Syntax: How to write a cleaner code for many composed computations

The comma-delimited assignments in the “head” of the let statement behave differently from assignments in its body.

The behavior of let statements is like function definitions, where the head is like the argument list for a function with default values:

a=1; d=0

let a=a, b=2, c=a+b
    d=a+b+c
    d^2
end     #-> 36

# is like
(  (a=a, b=2, c=a+b) -> begin
    d=a+b+c
    d^2
end)()  #-> 36

d == 0  #-> true

The variable scoping rules are the same.

The difference between assignments in the head and assignments in the body becomes starker for nested local scopes:

let a=1
    (let a=10; a end, a)
end   #-> (10, 1)
# versus
let a=1
    (let; a=10; a end, a)
end   #-> (10, 10)

note, again, that functions share these same behaviors; the key differences with let being the absence of a capture or boxing (and no extra compile time), and return behaves differently.

Interestingly, the example in the docs is erroneous (it’s probably showing an intended feature that’s not implemented yet).

1 Like