Node:Declarations, Next:Functions, Previous:Union objects, Up:Top
The form :var is used to declare a new variable var.
It is an expression which evaluates to the "value" of var.
That value may be unknown when we evaluate :var,
but at some point in the future it may get a value,
so what we get is a "potential" value.
Operationally, :var creates a new memory location,
binds name name var to that location, and returns that location.
Usually, the first thing we may want to do with a new variable is to
give it a value. This is easy using the = operator:
:x = 10 declares that the variable x has the
same value as 10. Operationally, the = operator
is implemented as unification, which causes the value 10
to be placed into the memory location for x.
(You can think of the expression x=y as a specification
that x and y are equal.)
Through the power of unification, we can do complex pattern-matching:
[:x :y]=[4 5] has the effect of setting x to 4,
and y is set to 5. Here, [4 5] is a list
containing the two elements (4 and 5), and [:x :y]
yields a list whose two elements are the locations for x and y.
Then the unification specifies that the two lists are equal,
which means that x must equal 4 and y must equal 5.