Re: evaluating binded symbols

From: Thomas A. Russ (tar_at_sevak.isi.edu)
Date: 03/29/05


Date: 28 Mar 2005 16:23:42 -0800


"Eli Bendersky" <eliben@gmail.com> writes:

>
> Hi all,
>
> I'm now going through PAIP (chapter 6, match-if function) and there is
> something the author uses but my CLISP v2.28 just doesn't grok. Simply
> put, it boils down to:
>
> [132]> (setq op '+ x 7 y 25)
> 25
> [133]> (eval '(op x y))
>
> *** - EVAL: the function OP is undefined
>
> Why does EVAL evaluate x and y but doesn't evaluate op ?
> Is this a problem with clisp or with the code from PAIP ?

Others have addressed the issue of PAIP.

To answer your direct question:

EVAL doesn't evaluate x and y. Since EVAL is a function, its argument
'(op x y) is evaluated to (OP X Y). Eval now tries to evaluate this
form. It does so by looking for a FUNCTION DEFINITION associated with
the symbol OP. It will also look for the VALUE of X and Y.

The evaluation rules for the function position and the argument position
are different in Common Lisp. So you would really need to use

    (funcall op x y)

to get the effect that you want. This is actually better, in that it
avoids the use of EVAL. But if the form of what you are trying to
evaluate is more irregular, you might need to resort to something like
the following:

   (eval `(,op ,x ,y))

where you explicitly do the substitution in the form passed to EVAL.

-- 
Thomas A. Russ,  USC/Information Sciences Institute


Relevant Pages

  • Re: evaluating binded symbols
    ... | something the author uses but my CLISP v2.28 just doesn't grok. ... | Is this a problem with clisp or with the code from PAIP? ... call that function with funcall, ... which implicitly declare the variable special. ...
    (comp.lang.lisp)
  • evaluating binded symbols
    ... something the author uses but my CLISP v2.28 just doesn't grok. ... put, it boils down to: ... Is this a problem with clisp or with the code from PAIP? ...
    (comp.lang.lisp)