On Mon, Mar 18, 2019 at 9:14 AM Matthew Flatt <mfl...@cs.utah.edu> wrote:

> I wonder whether the solution is an extension of `scribble/lp2` to
> support a `require-for-chunk` form where `chunk` records any such
> imports in its context and adds then to the stitched-together program.
>
>  (require-for-chunk (only-in racket/string string-join))
>
>  (define-syntax-parser cross-phase-macro
>    [(_ <>:id)
>     @#`begin{@(func-not-exported)
>
>      @chunk[<>
>             (string-join ....
>
> would work because `chunk` would pick up the `(only-in racket/string
> string-join)` from its context and attach it to the chunk, so that
> `(only-in racket/string string-join)` would be added to the
> stitched-together context.
>
> Maybe this would work by having `require-for-chunk` expand to something
> like `(begin-for-syntax (register-require #'chunk ....))` to register
> in a compile-time free-id table mapping from the #'chunk identifier to
> a list of imports. Then, the `chunk` macro would consult the table
> using the identifier that invoked the macro. (I have not tried this to
> be sure that it would work.)
>

While thinking about this idea, I came up with a simpler example that
exposes a hygiene issue in `scribble/lp2` without using `require`:

#lang scribble/lp2
@(define-syntax-rule (chunk/define <> lhs rhs ...)
   (chunk <>
          (define hygiene "this shouldn't cause capture")
          (define lhs rhs ...)))
@(chunk <*> <a> <b>)
@(chunk/define <a> a 1)
@(chunk/define <b> b 2)

fails with the error "module: identifier already defined in: hygiene".

I would have liked it to work analogously to this:

#lang racket
(define-syntax-rule (module+/define mod lhs rhs ...)
  (module+ mod
    (define hygiene "this shouldn't cause capture")
    (define lhs rhs ...)))
(module+/define main a 1)
(module+/define main b 2)

-Philip

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to