[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
- To: email@example.com
- From: firstname.lastname@example.org
- 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, ...
*** The first answer was this one :
(from Guillaume Cartier ; BTW now u know the winner :-)
(defmacro defTree (&rest theTrees)
`(setq ,theTree (make-instance 'generic-tree-class))))
This pattern of macro definition is very common when
you want a macro to have multiple arguments that all have the same
*** 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)
(dolist (name tree-names)
(push `(setq ,name (make-instance 'generic-tree-class))
*** and the fourth and last type of answer (from Rich Lynch) :
WARNING!!!: THIS CODE USES EVAL AND WILL *NOT* BE SUITABLE FOR A
(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 ?
GETA (Groupe d'Etude pour la Traduction Automatique)
BP 53X, 38041 GRENOBLE CEDEX, FRANCE