<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br></div><div>Let's remove /load from this world so we can see the expansion and let's play: </div><div><br></div><div><div>#lang racket</div><div><br></div><div>;;provider</div><div>(module T racket</div><div> (provide a)</div><div> (define a 1))</div><div><br></div><div>;; requirer</div><div>(module R racket</div><div> (require (for-syntax syntax/parse))</div><div> (define-syntax (test-binding stx)</div><div> (syntax-parse stx</div><div> [(_ path)</div><div> #'(let () (local-require (only-in path a)) a)]))</div><div> ;; if you remove the next line, drracket shows an error. Why? </div><div> #; </div><div> (test-binding (submod ".." T))</div><div> ;; "expanded" by hand, and it works </div><div> (let () (local-require (only-in (submod ".." T) a)) a))</div><div><br></div><div>;; go</div><div>(require 'R)</div></div><div><br></div><div><br></div><div><br></div><div>The two comments show that a does not get bound thru the binding position in only-in. You can also run the macro expander now and see that the expansion "looks like" what I did but the binding information shows that the a is done correctly for the "expanded" version. </div><div><br></div><div>This tells you that local-require is doing some hygiene/binding manipulation that can't be done inside a let context. </div><div><br></div><div><br></div><div><br></div><div><br></div><br><div><div>On Nov 6, 2014, at 6:33 PM, Spencer Florence wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">I understand why the begin and [a a] work, but what I'm wondering is why the others didn't work. For example, why didn't `begin` work in my second example? Is the lexical information for the bindings just coming form somewhere really weird?<br><br><div class="gmail_quote">On Thu Nov 06 2014 at 5:18:59 PM Jay McCarthy <<a href="mailto:jay.mccarthy@gmail.com">jay.mccarthy@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The begin works because the macro use is at the top-level and the<br>
thing gets pulled up and spliced in, I believe.<br>
<br>
The [a a] works because the second a is detected as a binder so it<br>
gets matched up mark-wise with the second one rather than having them<br>
erased? Hygiene? Marks? Dye packets?<br>
<br>
Jay<br>
<br>
On Thu, Nov 6, 2014 at 4:36 PM, Spencer Florence <<a href="mailto:spencer@florence.io" target="_blank">spencer@florence.io</a>> wrote:<br>
> Thanks! That fixed it!<br>
><br>
> Although I'm still curious as to why the error happens in the first place.<br>
><br>
> On Thu Nov 06 2014 at 3:32:02 PM Alexander D. Knauth <<a href="mailto:alexander@knauth.org" target="_blank">alexander@knauth.org</a>><br>
> wrote:<br>
>><br>
>> I think I had a similar sort of problem about a year ago (I was at either<br>
>> RacketCon or a Hackathon that same weekend and Mathew Flatt figured it out),<br>
>> and the solution was changing (only-in path a) to (only-in path [a a]).<br>
>><br>
>> #lang racket/load<br>
>> ;;provider<br>
>> (module T racket<br>
>> (provide a)<br>
>> (define a 1))<br>
>> ;; requirer<br>
>> (module R racket<br>
>> (require (for-syntax syntax/parse))<br>
>> (define-syntax (test-binding stx)<br>
>> (syntax-parse stx<br>
>> [(_ path)<br>
>> #'(let () (local-require (only-in path [a a])) a)]))<br>
>> (test-binding 'T))<br>
>> ;; go<br>
>> (require ‘R)<br>
>><br>
>><br>
>> On Nov 6, 2014, at 4:09 PM, Spencer Florence <<a href="mailto:spencer@florence.io" target="_blank">spencer@florence.io</a>> wrote:<br>
>><br>
>> > Hi All,<br>
>> ><br>
>> > I've been struggling to have a macro be given a path then require<br>
>> > something from that path. The following code produces and "Unbound<br>
>> > Identifier" error, although I would expect it to evaluate to 1. Could<br>
>> > someone provide insight into what is going on?<br>
>> ><br>
>> > #lang racket/load<br>
>> > ;;provider<br>
>> > (module T racket<br>
>> > (provide a)<br>
>> > (define a 1))<br>
>> > ;; requirer<br>
>> > (module R racket<br>
>> > (require (for-syntax syntax/parse))<br>
>> > (define-syntax (test-binding stx)<br>
>> > (syntax-parse stx<br>
>> > [(_ path)<br>
>> > #'(let () (local-require (only-in path a)) a)]))<br>
>> > (test-binding 'T))<br>
>> > ;; go<br>
>> > (require 'R)<br>
>> ><br>
>> ><br>
>> > P.S. I attempted to do this with `dynamic-require,` but that failed<br>
>> > because in my actual program `path` is sometimes `(submod "..")`, which<br>
>> > caused an error about not having a base path.<br>
>> ><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>
> ____________________<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>
<br>
<br>
--<br>
Jay McCarthy<br>
<a href="http://jeapostrophe.github.io/" target="_blank">http://jeapostrophe.github.io</a><br>
<br>
"Wherefore, be not weary in well-doing,<br>
for ye are laying the foundation of a great work.<br>
And out of small things proceedeth that which is great."<br>
- D&C 64:33<br>
</blockquote></div>
____________________<br> Racket Users list:<br> <a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a><br></blockquote></div><br></body></html>