[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: a little problem



>Hello everybody here,
>
>Happy new year !
>
>I have a question for you, lisp gurus. Perhaps you'll find it too simple,
>but it's driving me nuts.
>
>I have a macro that instanciate an object via a side effect:
>
>(defmacro defTree (theTree)
>  `(setq ,theTree (make-instance 'generic-tree-class))
>)
>
>Now, I want something like defTree* so that I just type:
>
>(defTree* toto titi tata ...)
>
>in order to instanciate toto, titi, tata, ...
>
>The first of you who answers correctly will be declared benefactor of our
>lab, and will receive a postcard (just put your surface mail address)
>
>Thanks in advance.
>
>---
>Lafourcade Mathieu
>GETA (Groupe d'Etude pour la Traduction Automatique)
>BP 53X, 38041 GRENOBLE CEDEX, FRANCE
>
>Lafourca@imag.fr

With some luck, this will be an easy way to get a nice postcard!
Here is the macro you want:

(defmacro defTree (&rest theTrees)
  `(progn
     ,@(mapcar (function
                 (lambda (theTree)
                   `(setq ,theTree (make-instance 'generic-tree-class))))
               theTrees)))

This pattern of macro definition is very common when
you want a macro to have multiple arguments that all have the same
expansion.

Hope this helps.

Guillaume Cartier
LACIM, Universite du Quebec a Montreal.
Bureau: (514) 987-4290
E-Mail: cartier@math.uqam.ca