<-)
SPL uses a single two-character token <- (less-than and hyphen) for
assignment sugar and for an alternate function-definition header. It is not the same as writing
< and - as two operators.
name <- expr; means the same as
name.setVar(expr); — including scoping rules (update an existing binding
or create one in the innermost frame). The semicolon is optional, like other statements.
n <- 3;
n.setVar(math.multiply(n, 2));
<- code:)
After zero or more parameter names (space-separated identifiers), you may write
<- code: to open a function body. This is equivalent to
functionDefine.name(param1, param2, ...): for the same name and parameters.
The identifier code is reserved in
this position — it must appear immediately after <- and before
:.
addOne x <- code: return.number(math.add(x, 1));
noop <- code: return.number(0);
twice x <- code:
return.number(math.multiply(x, 2));
end;
The block after : follows the same rules as any
... : block — including optional
one-line bodies when the first
statement sits on the same line as the colon.
<- for assignments when you want concise, expression-like left-hand sides.... <- code: when you prefer parameter names listed before the arrow instead of inside parentheses after functionDefine.name.