[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
- To: info-mcl@cambridge.apple.com
- From: lafourca@imag.fr
- Date: Wed, 15 Jan 1992 08:42:32 +0100
The problem was :
>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, ...
>
>---
>Lafourcade Mathieu
*** The first answer was this one :
(from Guillaume Cartier ; BTW now u know the winner :-)
...
(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.
***
*** The second type of answer (Seth Tisue and Mike Engber)
(defmacro defTree* (&rest trees)
`(progn ,@(mapcar #'(lambda (x) (list 'defTree x)) trees)))
***
*** The third type (Matthew MacLaurin) :
(defmacro deftree* (&rest tree-names)
(let ((result-list))
(dolist (name tree-names)
(push `(setq ,name (make-instance 'generic-tree-class))
result-list))
`(progn ,@result-list)))
***
*** and the fourth and last type of answer (from Rich Lynch) :
WARNING!!!: THIS CODE USES EVAL AND WILL *NOT* BE SUITABLE FOR A
STAND-ALONE APPLICATION.
...
(defmacro defTree (theTree)
`(setq ,theTree (make-instance 'generic-tree-class))
)
(defmacro defTree* (&rest theTrees)
(let ((theTree (gensym)))
`(dolist (,theTree ',theTrees)
(eval `(defTree ,,theTree))
) ) )
***
That's all ! (sorry for those which I missed !)
I finally (after a long delay :-) choose the first one. I didn't need to
keep the original defTree with just one arg. It's why I didn't choose the
second one. The third one looked a bit complicated (for me, I know it is
*very subjective*). The last one cannot used in a single app.
Any comment ?
Is my choice right ?
Perhaps someone can evaluate these differents soln ?
Any other *different and interresting* soln ?
Mathieu
---
Lafourcade Mathieu
GETA (Groupe d'Etude pour la Traduction Automatique)
BP 53X, 38041 GRENOBLE CEDEX, FRANCE
Lafourca@imag.fr