-
-
Notifications
You must be signed in to change notification settings - Fork 4
:=
is identical to [[be
]] assignment and charged method definition :
:=
is also used for constant assignments of variables
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
This would be different from function definition to
or be
where all symbols need to be defined at the time of definition.
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
Todo: Ambiguity questions ? Functions are constant too, so both semantics could be reconcilable? Rule: if the right hand side contains a constant than it's a variable. But what if we want to assign some calculated value to a constant? Just assign the value
𝛕=2*calculate_pi() // calculated on assignment
𝛕:=2*calculate_pi() // calculated every time