11.3.4. Partially Evaluated Literal

Gamma supports evaluation of sub-expressions, allowing you to write expressions whose elements may or may not be evaluated. In the following example, we want to create a literal expression which will calculate a to the power of b, where b is a specific power, evaluated at the time the literal is defined. The operator ` is used like # to prevent evaluation of the expression, but it allows for exceptions. These exceptions, which will be evaluated, are denoted using the @ operator.

Gamma> b = 3;
3
Gamma> my_cube = `(pow (a, @b));
(pow a 3)
Gamma> a = 10;
10
Gamma> eval(my_cube);
1000
	  

In the following example, the timer event is used to demonstrate how the current value of a variable can be evaluated into a literal:

Gamma> a = "hello";
"hello"
Gamma> every (15, #princ(a,"\n"));
1
Gamma> next_event();
hello
nil
Gamma> a = "goodbye";
"goodbye"
Gamma> next_event();
goodbye
Gamma> cancel (1);
[866239787 836823463 15 ((princ a,"\n")) 1]
Gamma> every (15, list (#princ, a, "\n"));
2
Gamma> next_event();
goodbye
nil
Gamma> a = "no more";
"no more"
Gamma> next_event();
goodbye
nil