Invoking Evaluation Explicitly

In addition to the usual ability to call a named function, Lisp makes it possible to compute the name of a function and explicitly cause that function to be called. There are several ways to do this. All do essentially the same thing; they differ in the form in which the arguments are presented.

(eval x) causes the expression x to be evaluated twice: once to find the value to be evaluated, and then to do the evaluation. That is, x is a computation that produces Lisp code as its output, and eval causes that Lisp code to be executed (evaluated).

(eval (subst 5 'x '(* x x)))

      =  (eval '(* 5 5))

      =  25
The ability to compute new pieces of program at runtime and execute them is a unique and powerful feature of Lisp; it makes Lisp an ideal substrate for implementing embedded languages such as Expert System tools.

Contents    Page-10    Prev    Next    Page+10    Index