Hi
Let's say I have z defined as follows:
> (define z '(+ 1 2))
then z will point to the list (+ 1 2)
so when I type z at the prompt, I get
> z
(+ 1 2)
But now I want to evaluate this list. How do I do it?
"Hong Bae Kim" <········@sympatico.ca> writes:
> But now I want to evaluate this list. How do I do it?
Use EVAL:
http://www.lispworks.com/reference/HyperSpec/Body/f_eval.htm
hth
Henrik
Hong Cae Kim asks:
> (define z '(+ 1 2))
> z
(+ 1 2)
But now I want to evaluate this list. How do I do it?
Well, "define" suggests scheme and not (Common) lisp, but there are
two possible answers depending on what exactly you meant.
1. Don't quote the expression you want to evaluation. ' means "don't
evaluate what comes next."
> (define z (+ 1 2))
> z
3
2. If you are trying to programmatically construct code, and then want
to evaluated what you constructed, you can use the function "eval"
as in:
> (define z '(+ 1 2))
> (eval z)
3
But this is rarely what people new to lisp (or scheme) really want
to be doing.
Larry
--
Lawrence Hunter, Ph.D.
Director, Center for Computational Pharmacology
Associate Professor of Pharmacology, PMB & Computer Science
phone +1 303 315 1094 UCHSC, Campus Box C236
fax +1 303 315 1098 School of Medicine rm 2817b
cell +1 303 324 0355 4200 E. 9th Ave.
email: ············@uchsc.edu Denver, CO 80262
PGP key on public keyservers http://compbio.uchsc.edu/hunter
"Hong Bae Kim" <········@sympatico.ca> wrote in message news:<·····················@news20.bellglobal.com>...
> Hi
>
> Let's say I have z defined as follows:
>
> > (define z '(+ 1 2))
Then you are programming in Scheme, not Lisp. The comp.lang.scheme
newsgroup is down the hall, to your left.
> then z will point to the list (+ 1 2)
> so when I type z at the prompt, I get
>
> > z
> (+ 1 2)
>
> But now I want to evaluate this list. How do I do it?
In Lisp or Scheme, this will work:
(eval z)
In Lisp, you could also use this trick: make z a symbol-macro. Then
the symbol z is automatically replaced by the specified expansion,
which is evaluated in its place:
(define-symbol-macro z '(+ 1 2))
z
==> 3