Subject: Re: understanding macros in lisp
From: rpw3@rpw3.org (Rob Warnock)
Date: Sun, 29 Jun 2003 04:16:45 -0500
Newsgroups: comp.lang.lisp
Message-ID: <GyednRyX9NzgM2OjXTWc-g@speakeasy.net>
Kent M Pitman  <pitman@world.std.com> wrote:
+---------------
| agent smith <worldneedsavillian@yahoo.com> writes:
| > 	(defmacro test (x)
| >            (format t "x = ~A ~%" x))
...
| What you want to do is:
|   (defmacro test (x)
|     `(format t "x = ~A ~%" ,x))
| if you want the expansion of the macro to be (format t "x = ~A" (f a)) and 
|   (defmacro test (x)
|     `(format t "x = ~A ~%" ',x))
| if you want the expansion to be (format t "x = ~A" '(f a)).
+---------------

Actually -- just guessing, of course, mindreading a confused question
is always an iffy thing at best ;-}  -- I suspect that maybe what he
*really* wants is something like this:

    > (defmacro test (x)
        `(format t "~S = ~S~%" ',x ,x))
    > (test (+ 17 (* 4 3)))
    (+ 17 (* 4 3)) = 29
    NIL
    > 


-Rob

p.s. I sometimes use a little macro DBGV (for "debug values") that
takes an optional place and a list of forms and does the above on them.
Useful for "printf"-style debugging, e.g.:

    > (let ((x 'this)
	    (y "that"))
        (dbgv (top-level)
	  x y (+ 17 (* 4 3)) *package*
	  (get-dispatch-macro-character #\# #\!)))
    DBGV: @TOP-LEVEL:
    X = THIS
    Y = "that"
    (+ 17 (* 4 3)) = 29
    *PACKAGE* = #<The COMMON-LISP-USER package, 91/95 internal, 0/9 external>
    (GET-DISPATCH-MACRO-CHARACTER # !) = #<Function ORG.RPW3.UTILS::SHARP-BANG
					   {480416C1}>
    NIL
    >

Rob Warnock, PP-ASEL-IA		<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607