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> #'<span style="line-height:19.7999992370605px">(unit (imports ...) (exports ...) body))]))<br><br>Where the defines in #'(e ...) are visible to `unit` so that they can be used for exports.<br><br>--spf</span><br><div class="gmail_quote">On Mon Jan 05 2015 at 11:32:46 AM 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">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 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) 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 seems<br>
> like I need to provide it with the parent definition-context, but 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>> 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. The<br>
> > documentation for `define-values` has essentially the same 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 `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 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, 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 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>
</blockquote></div>