[plt-scheme] Inlined language from a language module

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Fri Mar 20 13:26:49 EDT 2009

That's awesome.

Jay

On Fri, Mar 20, 2009 at 11:21 AM, Matthew Flatt <mflatt at cs.utah.edu> wrote:
> At Fri, 20 Mar 2009 11:02:35 -0600, Jay McCarthy 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?
>
> Good point.
>
> The simplest way I can find to allow `with-mini' anywhere requires
>
>  1. An extra module.
>
>  2. A `replace-context' function instead of `strip-context'.
>
> The latter is a simple generalization of `strip-context', and I've
> added it to `syntax/strip-context' in SVN.
>
> ---- with-mini.ss ----------------------------------------
> #lang s-exp "with-mini-maker.ss"
> "mini.ss"
>
> ---- with-mini-maker.ss ----------------------------------
> #lang scheme
> (require (for-syntax syntax/strip-context))
>
> (provide (rename-out [module-begin #%module-begin]))
>
> (define-syntax (module-begin stx)
>  (syntax-case stx ()
>    [(_ req)
>     #'(#%plain-module-begin
>        (require req)
>        (provide with-mini)
>        (define-syntax (with-mini stx)
>          (syntax-case stx ()
>            [(_ expr)
>             (replace-context #'req (strip-context #'expr))])))]))
>
> ---- example use of with-mini.ss -------------------------
> #lang scheme
> (require "with-mini.ss")
>
> (list (with-mini (1+ 0))
>      (with-mini (1+ (1+ 0))))
>
>
>



-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://teammccarthy.org/jay

"The glory of God is Intelligence" - D&C 93


Posted on the users mailing list.