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

Re: [plt-scheme] Macros and scope

There are actually two tricks that you need to solve this problem.
First, since mzscheme doesn't allow redefinition of imports, you need
to come up with a module that provides all of the mzscheme language,
but without letrec:

(module mzscheme-wo-letrec mzscheme
  (provide (all-from-except mzscheme letrec)))

Once you have that, you can use prefixing to give a funny name to the
original letrec and define your new letrec in terms of the old one:

(module m mzscheme-wo-letrec
  (require (prefix orig: mzscheme))
  (define-syntax (letrec stx)
    (syntax-case stx ()
      [(_ ((var val) ...) body ...)
       (syntax (list (orig:letrec ((var val) ...) body ...)))]))
  (display (letrec ((x x)) x)))

(require m)

The new version of letrec always wraps a list around its value.

Hope that helps,

At Tue, 14 May 2002 10:41:13 -0500 (EST), Matt Jadud wrote:
> Hello,
> 	I've encountered a Chezism that I'm not sure how to circumnavigate.
> 	(define-syntax letrec
> 	  (lambda (x)
>             (import scheme)  ;;Right here.
> 	    (syntax-case x ()
> 	      [(_ ((var val) ...) body)
> 	      .... (syntax (foo (letrec ((var val) ...) body))) .... ])))
>    In the Chez module system, you can "(import scheme)" when it becomes
> convenient to lexically refresh the namespace with clean, top-level bindings.
> In this case, this allows 'letrec' to be redefined to the outside world, but
> within the scope of the binding lambda, 'letrec' takes on the default Chez
> semantics.
> 	In short, I need to redefine 'letrec', but not within the scope of the
> macro.
> 	Hints or suggestions appreciated. I'll keep at the manual re Mz's
> modules, macro expansion, and namespaces.
> 	Thanks,
> 	Matt
> ________________________________________________________________________
> Matt Jadud                            http://www.cs.indiana.edu/~mjadud/
> Current Temperature Outside Lindley Hall                 55.6 F / 13.1 C
> Canterbury Weather: High 57 F / 14 C, Low 46 F / 8 C, Sunny intervals