On Jun 11, 2004, at 1:06 PM, Jacques B. Siboni wrote:

>
> Hi all,
>
> Could someone give me a suggestion to avoid evaluation in parameters 
> in a
> defun?
>
>
> (defun foo (bbb)
>   ...
> )
>
> (foo bar)
> with this defun and this call bar is evaluated
>
> to avoid evaluation i need to call with (foo 'bar)
>
> What modification to the  (defun foo ...) do I have to make to have 
> bar not
> evaluated in
> (foo bar) ?
>
>

The parameters are evaluated before the function is called.  There is 
nothing
you can do in foo to avoid evaluation of bar.

The solution is to make foo a macro instead.  Something like this:

* (defun %foo (bar)
     (format t "bar is \"~s\"~%" bar))

%FOO
* (defmacro foo (bar)
     `(%foo (quote ,bar)))

FOO
* (foo (format t "hello~%"))
bar is "(FORMAT T "hello~%")"
NIL
*

Macros are covered very well in Paul Graham's On Lisp,
http://www.paulgraham.com/onlisp.html
and they're a fairly advanced topic in Lisp programming.




Regards,

Craig Ludington

--
Craig Ludington                       __o
2446 N. Albany Avenue            ---_ \<,_
Chicago, IL 60647-2602        ---- (_)/ (_)
<[EMAIL PROTECTED]>  (773) 252-6911
GPG public key: http://gnunotunix.org/public-key.txt


Reply via email to