[plt-scheme] Inlined language from a language module

From: Sam TH (samth at ccs.neu.edu)
Date: Fri Mar 20 17:50:09 EDT 2009

On Fri, Mar 20, 2009 at 1:22 PM, Matthew Flatt <mflatt at cs.utah.edu> wrote:
> At Fri, 20 Mar 2009 13:18:52 -0400, Sam TH wrote:
>> On Fri, Mar 20, 2009 at 1:02 PM, Jay McCarthy <jay.mccarthy at gmail.com> wrote:
>> > On Fri, Mar 20, 2009 at 10:54 AM, Matthew Flatt <mflatt at cs.utah.edu> wrote:
>> >> (define-syntax (with-mini stx)
>> >>  (syntax-case stx ()
>> >>    [(_ expr)
>> >>     #`(begin
>> >>         (require "mini.ss")
>> >>         #,(strip-context #'expr))]))
>> >
>> > Am I right to assume this only works at the top-level because it
>> > relies on require?
>>
>> I think this definition of `with-mini' should work:
>>
>> (define-syntax (with-mini stx)
>>     (syntax-case stx ()
>>       [(_ expr)
>>        (syntax-local-lift-require "mini.ss"
>>                                   (strip-context #'expr))]))
>>
>> but it doesn't seem to:
>>
>> compile: unbound identifier (and no #%app syntax transformer is bound) in: 1+
>
> I tried that too....
>
> The problem is that `strip-context' removes the lexical context that
> includes `require's --- even the `require's introduced by
> `syntax-local-lift-require'.

At first I thought I understood what you meant here, but on further
reflection, I can't figure it out.  If `strip-context' removes the
context from the expr such that it can't find the `require', then why
does the original implementation work?  Ryan's hypothesis was that the
module top-level restores the relevant context, but then this should
work:


  (define-syntax (with-mini stx)
    (syntax-case stx ()
      [(_ expr)
       #`(with-mini2 #,(strip-context #'expr))]))

  (define-syntax (with-mini2 stx)
    (syntax-case stx ()
      [(_ expr)
       (syntax-local-lift-require ''mini
                                  #'expr)]))

when used at module-top-level.  But it doesn't - it fails with the same error.

Can you explain what's going on here in a little more detail?

Thanks,
-- 
sam th
samth at ccs.neu.edu


Posted on the users mailing list.