-
Notifications
You must be signed in to change notification settings - Fork 371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix macro require #273
Comments
Well yeah, that's because your function is actually defined at runtime, that is, not in the context where the macro is defined. Tried wrapping the defn in an |
(after a quick test, that doesn't work either... ??) |
What you need to add to bang.hy is Explanation: So far for how Hy works right now. The example shows a common Lisp idiom consisting of a macro expanding into an expression involving a call to a function defined in the same module. Hy should have some nice way to express this. This is less straightforward than in other Lisps due to the way symbols and namespaces work in Python. Problem #1 is deciding how symbols used in macro expansions should be taken from by default. For now, they are taken from the namespace in which the macro is used, not the one in which the macro is defined. Worse, there isn't any way to specify that they should be taken from the macro-defining namespace. There should be one, and probably it should be the default. But doing this is not trivial. The fundamental issue is that Python provides no way to refer to a symbol inside a given namespace directly. What a symbol means is always defined by the import statements of the module it appears in. We could make macro expansions include some imports, of course, but then we risk a name clash with explicit imports made in the module that uses the macro. One possible but ugly solution is to use gensyms to refer to such automatically imported names. |
That's precisely the work around I've used to skirt the issue. Don't really have a constructive solution yet. Not sure we can implicitly import * when using REQUIRE Sent from my mobile
|
There is one solution I thought of but I don't like it. After the And there's of course the gensym approach which is also ugly, but at least not slow. |
gensym would be interesting to add, even if we have a better solution for this bug |
I thought we already had gensym, but didn't check. It's pretty much compulsory for non-trivial macros (once you start caring about hygiene), so I'll create an issue for that immediately. |
Aye, thank you! |
I think the way macros and modules play together is now firmly established enough that we can say this isn't a bug. If you want the expansion of |
Require'd macros cannot reference global namespace of their module
Which is not terribly useful.
The text was updated successfully, but these errors were encountered: