home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / lisp / 3181 < prev    next >
Encoding:
Text File  |  1993-01-06  |  2.0 KB  |  50 lines

  1. Newsgroups: comp.lang.lisp
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!uwm.edu!linac!uchinews!uchinews.uchicago.edu!converse
  3. From: converse@cs.uchicago.edu (timoshenko)
  4. Subject: Re: macro question
  5. In-Reply-To: kardank@ERE.UMontreal.CA's message of 7 Jan 93 04:05:52 GMT
  6. Message-ID: <CONVERSE.93Jan5225205@sloth.uchicago.edu>
  7. Sender: news@uchinews.uchicago.edu (News System)
  8. Organization: University of Chicago Computer Science
  9. References: <1993Jan7.040552.27087@cc.umontreal.ca>
  10. Date: Wed, 6 Jan 1993 04:52:05 GMT
  11. Lines: 37
  12.  
  13. In article <1993Jan7.040552.27087@cc.umontreal.ca> kardank@ERE.UMontreal.CA (Kardan Kaveh) writes:
  14.  
  15. >I would like to define a macro which in turn defines several functions.
  16. >For example:
  17.  
  18. >(defmacro a (x y)
  19. >  `(defun ,x () (+ 2 2))
  20. >  `(defun ,y () (* 2 3)))
  21.  
  22. >As it stands, the macro only defines the second function, since that is the
  23. >returned value.  How can I get both functions defined?
  24.  
  25. I suppose you could do something like
  26.  
  27. (defmacro a (x y)
  28.    `(progn (defun ,x () (+ 2 2))
  29.            (defun ,y () (* 2 3))))
  30.  
  31. This is a macro that expands to an expression that, when evaluated,
  32. will cause both of the defun forms to be evaluated.  You're right
  33. that the last form in the defmacro is returned as the expansion, and
  34. so the first defun in your version above has no effect.
  35.  
  36. Why do you want to do this, though?  It's likely to be confusing, 
  37. both because it's unusual (though legal) to have defun forms that
  38. aren't top-level, and because this will cause functions to be defined
  39. without a corresponding explicit defun form in the code.  I suspect
  40. that there is some better way to do whatever you're trying to do;
  41. in particular, if you are defining functions that are used only once,
  42. it would be better to use a lambda-expression than to automatically
  43. define a named function before calling it.
  44.  
  45.     --Tim Converse
  46.  
  47. --
  48. -------------------------------------------------------------------------------
  49. Tim Converse  U. of Chicago CS Dept.  converse@cs.uchicago.edu  (312) 702-8584
  50.