|
> let x = 1; // declares a local variable
> // and binds it to an object
>
> x := 2; // binds local variable to
> // another object
The first form introduces 'x' into the local environment, and
associates it with an initial value. The second form changes the
association of the symbol x with an object, but does not
introduce any new bindings.
Dylan comes from a LISP heritage, where variables REFER to
values, not contain values (like in C, or Pascal).
> My question is, why do the two statements use a
> different operator?
> The assignment operator := vs. equality operator =
Actually, you're comparing the "let" binding form to assignment,
which is not correct. The "=" operator in "let" is pure syntactic
sugar, whereas the ":=" operator is the defining characteristic of
an assignment expression.
> Why didn't the designers of Dylan use the syntax:
> let x := 1;
> It would seem to be more consistent syntax if they
> used the same operator. Both statements are
> assignments, even though the first statement initializes x.
The two expressions are not assignment. The first is a binding
form, whereas the second is a destructive assignment. There
are significant differences between the two. The first's effect
(introducing x into the lexical scope) is a compile time concept,
whereas the second is a runtime mutation.
> The only other difference that I can think of
> is that the scope of x begins right after the end
> of the "let" declaration statement that declares x.
Actually, there is a significant difference in meaning. I'll use the
Lispish syntax to demonstrate:
(let ((x 3)) (+ x 1))
means
((lambda (x) (+ x 1)) 3)
That is, it is not assignment, whereas the second form
explicitely means assignment.
|