Chapter 4

Program Control

Assignment

The operator := is used to set variables to new values and as an alternate syntax for calling setter functions and macros.

The assignment operator is described in detail on page 409.

The following examples show the use of := to change the value of a module binding.

define variable *foo* = 10;
*foo*
  10
*foo* := *foo* + 100;
  110
*foo*
  110

The following examples show the use of := as shorthand for calling a setter function. In general, using this syntax to call a function fun is equivalent to calling the function fun-setter.

define variable *foo* = vector (10, 6, 8, 5);
element(*foo*, 2)
  8
element(*foo*, 2) := "bar"
  "bar"
*foo*
  #[10, 6, "bar", 5]

The following examples show the use of := as shorthand for calling a setter function using slot access notation.

window.position := point(100, 100)
vector.size := 50

The following examples show the use of := as shorthand for calling element-setter or aref-setter.

my-vector[2] := #"two"
my-array[1,1] := #"top-left"