home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.lisp
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!uwm.edu!linac!uchinews!uchinews.uchicago.edu!converse
- From: converse@cs.uchicago.edu (timoshenko)
- Subject: Re: macro question
- In-Reply-To: kardank@ERE.UMontreal.CA's message of 7 Jan 93 04:05:52 GMT
- Message-ID: <CONVERSE.93Jan5225205@sloth.uchicago.edu>
- Sender: news@uchinews.uchicago.edu (News System)
- Organization: University of Chicago Computer Science
- References: <1993Jan7.040552.27087@cc.umontreal.ca>
- Date: Wed, 6 Jan 1993 04:52:05 GMT
- Lines: 37
-
- In article <1993Jan7.040552.27087@cc.umontreal.ca> kardank@ERE.UMontreal.CA (Kardan Kaveh) writes:
-
- >I would like to define a macro which in turn defines several functions.
- >For example:
-
- >(defmacro a (x y)
- > `(defun ,x () (+ 2 2))
- > `(defun ,y () (* 2 3)))
-
- >As it stands, the macro only defines the second function, since that is the
- >returned value. How can I get both functions defined?
-
- I suppose you could do something like
-
- (defmacro a (x y)
- `(progn (defun ,x () (+ 2 2))
- (defun ,y () (* 2 3))))
-
- This is a macro that expands to an expression that, when evaluated,
- will cause both of the defun forms to be evaluated. You're right
- that the last form in the defmacro is returned as the expansion, and
- so the first defun in your version above has no effect.
-
- Why do you want to do this, though? It's likely to be confusing,
- both because it's unusual (though legal) to have defun forms that
- aren't top-level, and because this will cause functions to be defined
- without a corresponding explicit defun form in the code. I suspect
- that there is some better way to do whatever you're trying to do;
- in particular, if you are defining functions that are used only once,
- it would be better to use a lambda-expression than to automatically
- define a named function before calling it.
-
- --Tim Converse
-
- --
- -------------------------------------------------------------------------------
- Tim Converse U. of Chicago CS Dept. converse@cs.uchicago.edu (312) 702-8584
-