home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / scheme / c / 99 < prev    next >
Encoding:
Internet Message Format  |  1993-01-22  |  2.2 KB

  1. Path: sparky!uunet!olivea!spool.mu.edu!yale.edu!yale!mintaka.lcs.mit.edu!ai-lab!zurich.ai.mit.edu!gjr
  2. From: gjr@zurich.ai.mit.edu (Guillermo J. Rozas)
  3. Newsgroups: comp.lang.scheme.c
  4. Subject: Re: macro problem
  5. Message-ID: <GJR.93Jan22085538@chamarti.ai.mit.edu>
  6. Date: 22 Jan 93 16:55:38 GMT
  7. References: <1993Jan22.082118.21781@cc.umontreal.ca>
  8. Reply-To: gjr@zurich.ai.mit.edu
  9. Distribution: inet
  10. Organization: M.I.T. Artificial Intelligence Lab.
  11. Lines: 50
  12. NNTP-Posting-Host: chamartin.ai.mit.edu
  13. In-reply-to: kardank@ERE.UMontreal.CA's message of 22 Jan 93 08:21:18 GMT
  14.  
  15. In article <1993Jan22.082118.21781@cc.umontreal.ca> kardank@ERE.UMontreal.CA (Kardan Kaveh) writes:
  16.  
  17. |
  18. |   From: kardank@ERE.UMontreal.CA (Kardan Kaveh)
  19. |   Newsgroups: comp.lang.scheme.c
  20. |   Date: 22 Jan 93 08:21:18 GMT
  21. |
  22. |   What's wrong with the following?  MIT Scheme 7.2 complains f1 is unbound.
  23. |
  24. |   (define (f1 x) (* x x))
  25. |
  26. |   (define-macro (m1 y) `(+ 2 ,(f1 y)))
  27. |
  28. |   (m1 3)
  29. |
  30. |   ;Unbound variable: f1
  31. |
  32.  
  33. The environment where the macro expander procedure 
  34.  (i.e. (lambda (y) `(+ ... )) ) is closed is _not_ the top level
  35. environment where F1 is bound.  It is a separate environment.
  36.  
  37. This may seem like a strange decision, but imagine that F1, M1, and a
  38. use of M1 are in some file that is to be compiled.  At the time of
  39. compilation, M1 needs to be expanded, but the expansion requires the
  40. binding for F1 that will not exist until run time.  Since clearly,
  41. when compiling, the macro expander cannot be closed in the runtime
  42. environment, we decided to make a special environment for macro
  43. expanders to be closed, and this is done consistently when compiling
  44. and simply interacting.
  45.  
  46. The environment where macro expanders is closed is the value of the
  47. global variable SYNTAXER/DEFAULT-ENVIRONMENT.
  48. In your init file, you can include
  49.  
  50.     (set! syntaxer/default-environment user-initial-environment)
  51.  
  52. or some such, and then it will have the behavior that you want when
  53. interacting.
  54.  
  55. |
  56. |   Also, I can't seem to find any documentation on macros in the info files.
  57. |
  58.  
  59. Correct.  There is a very short document giving an overview (and
  60. pointing out some gotchas) but it is not integrated into the info
  61. structure.
  62.  
  63. You can get it from altdorf.ai.mit.edu:archive/scheme-7.2/macros.txt
  64. by anonymous ftp.
  65.