<div dir="ltr"> Awesome. Thanks for the answers everyone. I'm probably going to end up doing a namespace-require on the arbitrary code within a new namespace and then use eval to test any macros within it.<br><br>Cody<br>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Feb 1, 2013 at 7:29 AM, Ryan Culpepper <span dir="ltr"><<a href="mailto:ryanc@ccs.neu.edu" target="_blank">ryanc@ccs.neu.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The answer is roughly "that is not possible". In general, the meaning of a macro cannot be represented by a run-time value (but see below), so if you want to do something reflection-based with macros, you probably need to change your design to deal with terms (represented by syntax objects) instead of values.<br>
<br>
Actually, it does make sense to talk about the run-time value that corresponds to a macro in the case of identifier macros---macros that can be used like variables. For example, if you use 'contract-out' to provide a variable 'f' with a contract, it actually creates an auxiliary identifier macro and provides that as 'f'. The expansion of the provided 'f' macro fills in the negative blame part of the contract with the module where the expansion occurred and applies the contract to the original 'f' variable.<br>
<br>
That's the situation handled by the extension of 'dynamic-require' to macros. So doing<br>
<br>
(dynamic-require mod macro-name)<br>
<br>
is approximately the same as<br>
<br>
(parameterize ((current-namespace (make-empty-base-namespace)))<br>
(namespace-require mod)<br>
(eval macro-name))<br>
<br>
(except that it uses 'namespace-attach-module' instead of just 'namespace-require'). If 'macro-name' happens to be a macro that acts like a variable, then 'eval' produces a value. Otherwise, if it's something like 'define' or 'match' or 'for/list', you get an error, and it's exactly the same error you would get if you wrote something like<br>
<br>
#lang racket<br>
for/list<br>
<br>
What to do next depends on what you want to do with the macros.<br>
<br>
Ryan<div class="im"><br>
<br>
<br>
On 02/01/2013 02:57 AM, Dan Grossman wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
<br>
Cody and I would love an answer to this question from 1.5 months ago if<br>
anybody can point us in the right direction and/or ask us to clarify the<br>
question. Or if the answer is "that is not possible" then we'll do<br>
something else.<br>
<br>
Much thanks!<br>
<br>
--Dan<br>
<br>
On Mon, Dec 17, 2012 at 9:20 PM, Cody Schroeder <<a href="mailto:codeblack08@gmail.com" target="_blank">codeblack08@gmail.com</a><br></div><div class="im">
<mailto:<a href="mailto:codeblack08@gmail.com" target="_blank">codeblack08@gmail.com</a>><u></u>> wrote:<br>
<br>
I'm in a position that I would like to use dynamic-require<br></div>
<<a href="http://docs.racket-lang.org/reference/Module_Names_and_Loading.html#(def._((quote._~23~25kernel)._dynamic-require))" target="_blank">http://docs.racket-lang.org/<u></u>reference/Module_Names_and_<u></u>Loading.html#(def._((quote._~<u></u>23~25kernel)._dynamic-require)<u></u>)</a>> to<div class="im">
<br>
gain access to all of the provides in a module. This is quite<br>
straightforward for normal procedures, but I also want this to<br>
include syntax. However, I get this error when trying to<br>
dynamically require the blah macro from my test module:<br>
<br>
(dynamic-require "test.rkt" 'blah)<br>
blah: use does not match pattern: (blah body) in: blah<br>
<br>
From the spec, it says that "If the module exports provided as<br>
syntax, then a use of the binding is expanded and evaluated in a<br>
fresh namespace to which the module is attached" when using<br>
dynamic-require. I don't understand how it's being used, though.<br>
<br>
Is there a way to use dynamic-require how I want? Is there a<br>
better way?<br></div><div class="im">
Cody<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>
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>
</div></blockquote>
<br>
</blockquote></div><br></div>