[plt-scheme] Inlined language from a language module

From: Neil Toronto (ntoronto at cs.byu.edu)
Date: Wed Mar 25 14:20:13 EDT 2009

Matthew Flatt wrote:
> 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))))

I've attached my inline-language maker language module, stripped of 
everything but essentials for my latest question.

It turns out that replace-context as it is doesn't play well with 
unquoting. (I need to parameterize RevBayes code on Scheme values, and 
unquoting is a nice way to do it.) My replacement, 
replace-revbayes-context, works identically except it replaces 
#'(unquote expr) with #'(unrevbayes expr) and doesn't recurse into #'expr.

I'm posting this because with the whole macro system at my disposal, it 
seems weird that I'd need to do what is essentially a macro expansion 
inside of replace-context. But I can't think of a simpler way to do it 
that allows me to use comma syntax.

Neil

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: revbayes-inline-maker-essential.ss
URL: <http://lists.racket-lang.org/users/archive/attachments/20090325/2192fdca/attachment.ksh>

Posted on the users mailing list.