11.3.2. Deferring Expression Evaluation

A Gamma expression preceded by the quote operator (#) will be taken literally, i.e., it will be protected from the evaluator. When the symbol containing this literal is evaluated, its contents are then interpreted. For example:

Gamma> x = #5 + 6;
(+ 5 6)
Gamma> #x;
x
Gamma> x;
(+ 5 6)
Gamma> eval (x);
11
	  

In the first case, the quote operator (#) protects the entire expression from the evaluator. That is, it protects everything to its right, all the way to the end of the expression (usually a semicolon or closed parenthesis). In the second case it is used to "produce" the literal symbol x. Then x is evaluated, returning its literal contents. Finally, the eval function is used to force execution of the literal contents of x. The eval function forces the resolution of variable references, as in this example:

Gamma> a = 1;
1;
Gamma> x = a + 5;
6;
Gamma> x = #a + 5;
(+ a  5)
Gamma> a = 10;
10
Gamma> eval (x);
15
	  

The literal is often used to delay the evaluation of an expression until an event is triggered. A good example is the add_set_function. This function takes two arguments. The first argument must be a symbol, so the # operator is used to prevent the required symbol from being evaluated. The second argument is simply any expression, most commonly a function. The add_set_function function sets the second argument to be evaluated when the first argument is changed:

Gamma> add_set_function (#a, #princ("My value = " ));
(princ "My value =")
Gamma> a = 21 / 3;
My value = 7
	  

In the following variation of the above example, a symbol used as an argument has been assigned a literal symbol, so that its evaluation will result in the desired symbol:

Gamma> x = #b;
b
Gamma> add_set_function (x, #princ("My value = " ));
(princ "My value =")
Gamma> b = 21 / 3;
My value = 7