-
-
Notifications
You must be signed in to change notification settings - Fork 5
assignment
In the shell, assignments declarations are treated symbolically!
z=y*y would be erroneous in a normal block, if y was not defined!
z=y*y with the same evaluation semantics is written z:=y*y in a normal block.
:= is identical to be assignment and charged method definition :
square x be x*x
square x := x*x
to square x: x*x
All three are identical.
Difference between symbolic assignment :=, lazy assignment := and direct assignment = :
If symbols in the body of := do not occur on the right hand side, they remain lazy symbols waiting for evaluation.
square := x*x
x = 3
square == 9
x = 4
square == 16
Lazy assignment should be discouraged because it facilitates unpure code!
Direct assignment = evaluates all symbols not occurring on the left hand side immediately:
square x = x*x # ok
square = x*x # todo: error, unknown symbol x, or treat as :=
x=3
square = x*x # ok, use symbol x from context
square == 9
x = 4
square == 9 # square was fully evaluated when x=3
Contrast the last behavior of
square = x*x with
square := x*x
square x := x*x
square x = x*x
square = x : x*x
Assignment and object creation
foo{bar:3} #object creation
foo:{bar:3} #property assignment (nested objects)
foo={bar:3} #variable assignment (of calling context)
todo ambiguous assignment concepts:
name, age, source = "Crystal, 123, GitHub".split(", ")
name age, source := "Crystal, 123, GitHub".split(", ")
The operator = and its equivalent keyboard is can act as