Awesome! Thanks, that works for what I'm doing.<br><br><div class="gmail_quote">On Mon Jan 05 2015 at 2:47:43 PM Matthew Flatt <<a href="mailto:mflatt@cs.utah.edu">mflatt@cs.utah.edu</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">That turns out to be tricky. I've enclosed an implementation, but it<br>
works only for units that have no imports.<br>
<br>
At Mon, 05 Jan 2015 17:21:37 +0000, Spencer Florence wrote:<br>
> What I'm trying to do is capture all lifts inside a unit body, instead of<br>
> having them propagating to the top level.<br>
><br>
> If I understand what you mean by "add internal-definition context to the<br>
> bindings listed in `exports`", I can't do that because I need to capture<br>
> any lifts inside the unit body, but a `(local-expand/capture-lifts #'(unit<br>
> ...))` would put them outside. But maybe I miss understand you.<br>
> On Mon Jan 05 2015 at 12:10:53 PM Matthew Flatt <<a href="mailto:mflatt@cs.utah.edu" target="_blank">mflatt@cs.utah.edu</a>> wrote:<br>
><br>
> > I'm not really clear on what you're trying to do. One way to explain<br>
> > more might be to explain how `test` is meant to differ from `begin`. Or<br>
> > maybe you can say why it doesn't work to add the internal-definition<br>
> > context to the bindings listed in `exports` (i.e., to bring everything<br>
> > into the definition context).<br>
> ><br>
> > At Mon, 05 Jan 2015 16:44:10 +0000, Spencer Florence wrote:<br>
> > > Is there any way to have the `test` macro work more like `begin`?<br>
> > ><br>
> > > What I am trying to accomplish is something like:<br>
> > ><br>
> > > (define-syntax (make-my-unit stx)<br>
> > > (syntax-parse stx<br>
> > > [(e ...)<br>
> > > (with-syntax ([body (local-expand/capture-lifts stx <something>)])<br>
> > > #'(unit (imports ...) (exports ...) body))]))<br>
> > ><br>
> > > Where the defines in #'(e ...) are visible to `unit` so that they can be<br>
> > > used for exports.<br>
> > ><br>
> > > --spf<br>
> > > On Mon Jan 05 2015 at 11:32:46 AM Matthew Flatt <<a href="mailto:mflatt@cs.utah.edu" target="_blank">mflatt@cs.utah.edu</a>><br>
> > wrote:<br>
> > ><br>
> > > > I think it's more a question of what a definition context is supposed<br>
> > > > to be, rather than how `syntax-local-bind-syntaxes` works.<br>
> > > ><br>
> > > > When you create a new definition context, the context's bindings are<br>
> > > > visible only to expressions that are also in that context. The `test`<br>
> > > > form here creates a new definition context in much the same way as<br>
> > > > `(let () ...)`:<br>
> > > ><br>
> > > > (let ()<br>
> > > > (let () (define x 1))<br>
> > > > x)<br>
> > > ><br>
> > > > In other words, the final `x` really is out of the scope of the<br>
> > > > definition of `x`.<br>
> > > ><br>
> > > > At Mon, 05 Jan 2015 16:26:30 +0000, Spencer Florence wrote:<br>
> > > > > Progress is a new error! I don't think I understand how<br>
> > > > > syntax-local-bind-syntaxes is supposed to work. I extended the<br>
> > previous<br>
> > > > > program:<br>
> > > > ><br>
> > > > > #lang racket<br>
> > > > > (require (for-syntax syntax/parse))<br>
> > > > > (define-syntax (test stx)<br>
> > > > > (syntax-parse stx<br>
> > > > > [(_ e)<br>
> > > > > (define ctx<br>
> > > > > (if (list? (syntax-local-context))<br>
> > > > > (cons (gensym) (syntax-local-context))<br>
> > > > > (list (gensym))))<br>
> > > > > (define def-ctx (syntax-local-make-definition-<u></u>context))<br>
> > > > > (define expd (local-expand #'e ctx (list #'define-values)<br>
> > def-ctx))<br>
> > > > > (define ids (syntax-parse expd [(def (id) _) (list #'id)]))<br>
> > > > > (syntax-local-bind-syntaxes ids #f def-ctx)<br>
> > > > > (internal-definition-context-<u></u>seal def-ctx)<br>
> > > > > expd]))<br>
> > > > > (let ()<br>
> > > > > (test (define x 1))<br>
> > > > > x)<br>
> > > > ><br>
> > > > > And now I receive the error: `x: unbound identifier in module in: x`<br>
> > > > > Looking at the docs for `syntax-local-make-definition-<u></u>context` it<br>
> > seems<br>
> > > > > like I need to provide it with the parent definition-context, but<br>
> > I'm not<br>
> > > > > sure how to get a hold of that.<br>
> > > > ><br>
> > > > > --spf<br>
> > > > ><br>
> > > > > On Mon Jan 05 2015 at 10:00:53 AM Matthew Flatt <<a href="mailto:mflatt@cs.utah.edu" target="_blank">mflatt@cs.utah.edu</a>><br>
> > > > wrote:<br>
> > > > ><br>
> > > > > > The error message is intended for "end users" and turns out to be<br>
> > > > > > misleading for the implementor of an internal-definition context.<br>
> > The<br>
> > > > > > documentation for `define-values` has essentially the same<br>
> > problem: it<br>
> > > > > > describes how `define-values` should work in an internal-definition<br>
> > > > > > context, but it doesn't say how the form interacts with<br>
> > `local-expand`.<br>
> > > > > ><br>
> > > > > > A `define-values` form will only expand in a module or top-level<br>
> > > > > > context. To implement an internal-definition context, you must<br>
> > expand<br>
> > > > > > only far enough to see `define-values` form; in other words, supply<br>
> > > > > > `#'define-values` in the stop list. Then, a partially expanded<br>
> > > > > > `define-values` form must be recognized and handled explicitly,<br>
> > with<br>
> > > > > > tools like `syntax-local-bind-syntaxes` or re-writing to<br>
> > > > > > `letrec-values`, as appropriate for the definition context.<br>
> > > > > ><br>
> > > > > > At Mon, 05 Jan 2015 14:49:03 +0000, Spencer Florence wrote:<br>
> > > > > > > Hey all,<br>
> > > > > > ><br>
> > > > > > > I'm trying to use 'local-expand', however it seems to think its<br>
> > > > never in<br>
> > > > > > a<br>
> > > > > > > definition context. For example:<br>
> > > > > > ><br>
> > > > > > > (require (for-syntax syntax/parse))<br>
> > > > > > > (define-syntax (test stx)<br>
> > > > > > > (syntax-parse stx<br>
> > > > > > > [(_ e)<br>
> > > > > > > (define ctx<br>
> > > > > > > (if (list? (syntax-local-context))<br>
> > > > > > > (cons (gensym) (syntax-local-context))<br>
> > > > > > > (list (gensym))))<br>
> > > > > > > (local-expand<br>
> > > > > > > #'e ctx null<br>
> > > > > > > ;; result is the same with this uncommented<br>
> > > > > > > #;(syntax-local-make-<u></u>definition-context))]))<br>
> > > > > > > (let ()<br>
> > > > > > > (test (define x 1))<br>
> > > > > > > x)<br>
> > > > > > ><br>
> > > > > > > errors with a "define-values: not in a definition context in:<br>
> > > > > > > (define-values (x) 1)"<br>
> > > > > > ><br>
> > > > > > > Can anyone provide any insight into what is going on?<br>
> > > > > > ><br>
> > > > > > > --spf<br>
> > > > > > > ____________________<br>
> > > > > > > Racket Users list:<br>
> > > > > > > <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/<u></u>users</a><br>
> > > > > ><br>
> > > ><br>
> ></blockquote></div>