There are four reasons for having = for variable introduction and := for mutation:
- From the math perspective
x = x + 1is just plain wrong, thoughx := x + 1is ok. - Mutation is a dangerous operation (a modern days
goto), and as such should be minimized. Grammar should make it easier to introduce a new variable rather than to reuse some existing one (usually for slightly skewed purpose). - Marking the mutation points with
:=makes them more visible. It's a similar concept as in LISP where we use "!" in function names to indicate mutations. For example, Scheme's "set!" - The
:=syntax is aligned with other mutations+=,...>>=.
a = 42; // declare `a`
a := 11; // modify `a` value