home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / lisp / 3384 < prev    next >
Encoding:
Internet Message Format  |  1993-01-28  |  1.1 KB

  1. Path: sparky!uunet!math.fu-berlin.de!ira.uka.de!Germany.EU.net!sbsvax!cs.uni-sb.de!nesmith
  2. From: nesmith@cs.uni-sb.de (Daniel Nesmith)
  3. Newsgroups: comp.lang.lisp
  4. Subject: Re: Need help with macro writing
  5. Message-ID: <24163@sbsvax.cs.uni-sb.de>
  6. Date: 27 Jan 93 01:52:25 GMT
  7. References: <1993Jan26.215013.12107@news.unige.ch>
  8. Sender: news@sbsvax.cs.uni-sb.de
  9. Organization: Computer Science, University of the Saarland, Germany
  10. Lines: 17
  11.  
  12. Here's a suggestion (using woap as an abbreviation):
  13.  
  14. ; first woap1 swaps the body and the keys but getting rid of the enclosing list around
  15. ; the keywords
  16. > (defmacro woap1 (keywordlist &body body) `(woap2 ,body ,@keywordlist))
  17. WOAP1
  18. ; now get values of the keyword arguments, swap them with the body, splice into body
  19. > (defmacro woap2 (bodylist &key stream type object) 
  20.     `(woap (,stream ,type ,object) ,@bodylist))
  21. WOAP2
  22. ;; now test
  23. > (macroexpand-1 '(woap1 (:stream t :type tt :object ttt) (print object) (bla bla)))
  24. (WOAP2 ((PRINT OBJECT) (BLA BLA)) :STREAM T :TYPE TT :OBJECT TTT)
  25. T
  26. > (macroexpand-1 *)
  27. (WOAP (T TT TTT) (PRINT OBJECT) (BLA BLA))
  28. T
  29.