eval

eval — evaluates an argument.

Syntax

eval (s_exp)

		

Arguments

s_exp

Any Gamma or Lisp expression.

Returns

The result of evaluating the argument. Note that the argument is also evaluated as part of the function calling mechanism.

Description

The eval function forms the basis for running a Gamma program. Every data type has a defined behavior to the eval call. These are:

    symbol Look up the symbol in the current scope and return the value bound to the symbol. If the symbol is not bound, generate an "Undefined symbol" error.

    list Evaluate the first element of the list. If the result is a function, call that function with the rest of the list as arguments. If the first element evaluates to an instance of a class, look up the second element as the method name and resolve that method name in the class or its ancestors. Call the method with the instance bound to self and all other list elements as arguments.

    all others All other data types evaluate to themselves.

The eval function can be useful when constructing code which must be conditionally executed at a later date, and passed about as data until that time. It may be useful to provide a piece of code as an argument to a generic function so that the function can evaluate it as part of its operation.

Example

[Note]

Note: The # operator is used to protect an expression from evaluation. See Quote Operators for more information.

Gamma> a = 5;
5
Gamma> b = #a;
a
Gamma> b;
a
Gamma> eval(b);
5
Gamma> 
		

See Also

eval_list