[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: define-macro bug?




  > Date: Tue, 23 Apr 2002 15:27:28 +0200 (CEST)
  > From: Zbyszek Jurkiewicz <zbyszek@duch.mimuw.edu.pl>
  > Cc: ittai@mrl.nyu.edu, <plt-scheme@fast.cs.utah.edu>
  > Content-Type: TEXT/PLAIN; charset=US-ASCII
  > X-Virus-Scanned: by AMaViS perl-11
  > 
  > 
  > 
  > On Mon, 22 Apr 2002, Matthias Felleisen wrote:
  > 
  > > 
  > > MzScheme now respects the phase separation between macros and values that
  > > should have existed a long time ago. Try this
  > > 
  > >  (define-macro egg (let ([foo (lambda x x)]) (lambda (x) foo)))
  > > 
  > > and you will see that foo is reachable from within a macro. 
  > 
  > Oh, I like this construction very much.  However, problem was having
  > GLOBALLY defined foo to be accessible inside macro body.
  > 
  > Zbyszek

No problem: 

  Welcome to DrScheme, version 200alpha17-cvs23apr2002.
  Language: Full.
  > (module a mzscheme 
      (require (lib "defmacro.ss"))
      (provide egg)
      (define foo 'in-a)
      (define-macro egg (lambda (x) 'foo)))
  > (module b mzscheme
      (require a)
      (define foo 'in-b-because-these-macros-are-neither-hygienic-nor-scope)
      (display (egg 5))
      (newline))
  > (require b)
  in-b-because-these-macros-are-neither-hygienic-nor-scope

or 
 
  Welcome to DrScheme, version 200alpha17-cvs23apr2002.
  Language: Full.
  > (define foo 'in-b-because-these-macros-are-neither-hygienic-nor-scope)
  > (define-macro egg (lambda (x) 'foo))
  > (display (egg 5))
  in-b-because-these-macros-are-neither-hygienic-nor-scope

Again the key is that macros and values are phase separated. If you want
foo, think S-expression macros from the alchemists days of macro usage. 

-- Matthias