syntax-local-context, I think. Robby
On Fri, Oct 2, 2009 at 6:17 AM, Casey Klein <clkl...@eecs.northwestern.edu> wrote: > On Thu, Oct 1, 2009 at 3:35 PM, Matthew Flatt <mfl...@cs.utah.edu> wrote: >> At Thu, 1 Oct 2009 15:01:56 -0500, Casey Klein wrote: >>> Can someone explain why this macro expands without error in a module >>> but not in the REPL? >>> >>> (define-syntax (m stx) >>> (syntax-case stx () >>> [(_ x) >>> (with-syntax ([(y) (generate-temporaries (syntax (x)))]) >>> (syntax (define (y) y)))])) >>> >>> > (m q) >>> compile: unbound identifier (and no #%top syntax transformer is bound) in: >>> q1 >> >> Yes, it's a hopeless-top-level sort of problem. At the point where the >> expander is trying to figure out where `y' comes from, there is no >> suitable `y', yet, and there won't be until the `define' is actually >> evaluated. >> >> There's a special hack to solve this problem: when a top-level >> `define-syntaxes' gets zero results from the RHS expression, it just >> makes the identifiers exist (in a suitable way) without defining >> anything. So, this works: >> >> (define-syntax (m stx) >> (syntax-case stx () >> [(_ x) >> (with-syntax ([(y) (generate-temporaries (syntax (x)))]) >> (syntax >> (begin >> (define-syntaxes (y) (values)) >> (define (y) y))))])) >> > > I see that this works only at the top-level. Is there a way to check > whether this application of m is at the top-level, so that I can > conditionally include the define-syntaxes trick? > _________________________________________________ > For list-related administrative tasks: > http://list.cs.brown.edu/mailman/listinfo/plt-dev > _________________________________________________ For list-related administrative tasks: http://list.cs.brown.edu/mailman/listinfo/plt-dev