From: Michael Gass
Subject: eval question
Date: 
Message-ID: <392da49b@152.65.161.36>
Why the following behavior?

(list '+ 1 1)
   => (+ 1 1)

(eval (list '+ 1 1))
   => 2

That is, why doen't the top level evaluator work like eval here?

-- 
Michael Gass		

email: ·····@csbsju.edu                 

From: Barry Margolin
Subject: Re: eval question
Date: 
Message-ID: <XZhX4.31$ub1.1313@burlma1-snr2>
In article <········@152.65.161.36>,
Michael Gass  <·····@bach.math.csbsju.edu> wrote:
>Why the following behavior?
>
>(list '+ 1 1)
>   => (+ 1 1)
>
>(eval (list '+ 1 1))
>   => 2
>
>That is, why doen't the top level evaluator work like eval here?

When you were typing to the top-level evaluator, you told it to execute the
LIST function, and display the result of that.  It called LIST, which
returned a list, and that's what was displayed.  The normal top-level just
performs one level of evaluation.

In the second case, you told the top-level evaluator to call LIST (as in
the first case), and then pass the result of that to the function EVAL.
LIST returned a list (much like the one that was displayed in the first
case), passed that to EVAL, and then EVAL called the function +, which
performed the addition.  You got two levels of evaluation: one from the
top-level, and another from the explicit call to EVAL.

For further education, consider:

(list 'list ''+ 1 1)
(eval (list 'list ''+ 1 1))
(eval (eval (list 'list ''+ 1 1)))

Ponder: why are two quotes needed?

-- 
Barry Margolin, ······@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Frode Vatvedt Fjeld
Subject: Re: eval question
Date: 
Message-ID: <2hd7ma9snk.fsf@dslab7.cs.uit.no>
Michael Gass <·····@bach.math.csbsju.edu> writes:

> Why the following behavior?
> 
> (list '+ 1 1)
>    => (+ 1 1)

The function LIST creates a list. This is very different from
interpreting a list as a form and executing it...

> (eval (list '+ 1 1))
>    => 2

...which is precicely what EVAL does. Perhaps what you want to do is
(funcall #'+ 1 1) or (apply #'+ '(1 1)), which both means "apply the
function named + to the arguments (1 1)".

-- 
Frode Vatvedt Fjeld
From: Rainer Joswig
Subject: Re: eval question
Date: 
Message-ID: <rainer.joswig-DBFA20.00471626052000@news.is-europe.net>
In article <········@152.65.161.36>, Michael Gass 
<·····@bach.math.csbsju.edu> wrote:

> Why the following behavior?
> 
> (list '+ 1 1)
>    => (+ 1 1)
> 
> (eval (list '+ 1 1))
>    => 2
> 
> That is, why doen't the top level evaluator work like eval here?

You are not doing the same.

In the first example the top level does something like:
  (eval '(list + '1 1))   -->   (+ 1 1)

Note the additional quote.

-- 
Rainer Joswig, Technical Director, BU Partner,
ISION Internet AG, Steinh�ft 9, 20459 Hamburg, Germany
Tel: +49 40 3070 2950, Fax: +49 40 3070 2999
Email: ····················@ision.net WWW: http://www.ision.net/