Subject: Re: Manipulating macro parameters
From: rpw3@rpw3.org (Rob Warnock)
Date: Tue, 23 May 2006 04:32:49 -0500
Newsgroups: comp.lang.lisp
Message-ID: <evOdnfIt_vxcS-_Z4p2dnA@speakeasy.net>
Pedro Kr�ger <pedrokroeger@gmail.com> wrote:
+---------------
| Rob Warnock wrote:
| > Why READ-FROM-STRING and not simply INTERN?
...
| so you suggest doing this?:
|  (defmacro test (x)
|     `(defun ,(intern (concatenate 'string (symbol-name x) "BAR")) ()
|        (+ 2 2)))
+---------------

Basically, yes. [...with possibly also a package arg
to INTERN, if that makes sense in your application.]

+---------------
| ("BAR" has to be upper case, otherwise the symbol will be |FOObar|)
+---------------

True[1], but you could always do it this way[2]:

   (defmacro test (x)
      `(defun ,(intern (concatenate 'string (symbol-name x)
					    (symbol-name :bar)))
              ()
         (+ 2 2)))

or even this way[3]:

   (defmacro test (x)
     (let ((suffix (load-time-value (symbol-name :bar))))
       `(defun ,(intern (concatenate 'string (symbol-name x) ,suffix))
               ()
          (+ 2 2)))


-Rob

[1] Assuming the default READTABLE-CASE when FOO was read.

[2] Which still needs (READTABLE-CASE *READTABLE*) to be the same
    when the macro definition is read as when the macro call is read.

[3] Which still works when (EQL *READ-EVAL* NIL).

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