assignment - pannous/warp GitHub Wiki

The three binding operators differ in when the right side is evaluated (vocabulary and specification: charged):

# three ways to bind x, one per line
x = y*y     # a value: evaluated now
x := y*y    # charged: evaluated at every use (`x be y*y` is the same)
x : y*y     # uncharged: the block y*y, evaluated by x!

: := =

Precedence: := binds lowest a b := c d is equivalent to (a b) := (c d) = binds lower than :' a = b c is still equivalent to a = (b c) : the key pair operator has the highest precedence : a : b c is equivalent to (a:b) c EXCEPT in block expressions: to square x: x*x

In a type, : declares a field: class Person { name:String age:i64 }.

Assignment and object creation

foo{bar:3}   # object creation
foo:{bar:3}  # property assignment OR creation if new (nested objects)
foo={bar:3} # variable assignment (of calling context)

variables vs functions

todo ambiguous assignment concepts:

name, age, source = "Crystal, 123, GitHub".split(", ")
name age, source := "Crystal, 123, GitHub".split(", ")

=

The operator = acts as variable assignment, function declaration (square x = x*x), and inside an if/while condition as equality comparison (Footguns). The keyword is is always a comparison; a definition is written x be value (be).