home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / lisp / 2383 < prev    next >
Encoding:
Text File  |  1992-09-08  |  1.5 KB  |  48 lines

  1. Path: sparky!uunet!usc!sdd.hp.com!think.com!barmar
  2. From: barmar@think.com (Barry Margolin)
  3. Newsgroups: comp.lang.lisp
  4. Subject: Re: Selective compilation of reader macro forms...
  5. Date: 8 Sep 1992 03:10:42 GMT
  6. Organization: Thinking Machines Corporation, Cambridge MA, USA
  7. Lines: 36
  8. Message-ID: <18h5jiINNj27@early-bird.think.com>
  9. References: <60132@mimsy.umd.edu>
  10. NNTP-Posting-Host: gandalf.think.com
  11.  
  12. In article <60132@mimsy.umd.edu> waander@cs.umd.edu (Bill Andersen) writes:
  13. >  I have a reader macro which I want to do two different things depending on
  14. >whether the form following the macro is being compiled, or is being
  15. >entered interactively.
  16.  
  17. If the reader macro is being defined in the same file as the uses that
  18. should get this special treatment, the following should work:
  19.  
  20. (eval-when (compile)
  21.   (defun read-macro-compile ...)
  22.   (set-macro-character #\<char> #'read-macro-compile ...))
  23.  
  24. (defun read-macro-runtime ...)
  25.  
  26. (set-macro-character #\<char> #'read-macro-runtime ...)
  27.  
  28. If the above restriction doesn't apply, you could use a special variable:
  29.  
  30. (defvar *read-macro-being-compiled* nil)
  31.  
  32. (defun read-macro (...)
  33.   (if *read-macro-being-compiled*
  34.       ...))
  35.  
  36. (defun my-compile-file (&rest args)
  37.   (let ((*read-macro-being-compiled* t))
  38.     (apply #'compile-file args)))
  39.  
  40. (defun my-compile (*rest args)
  41.   (let ((*read-macro-being-compiled* t))
  42.     (apply #'compile args)))
  43. -- 
  44. Barry Margolin
  45. System Manager, Thinking Machines Corp.
  46.  
  47. barmar@think.com          {uunet,harvard}!think!barmar
  48.