-
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
Scope of functions resulting from a macro expansion #1703
Comments
I think the root of this problem might be more closely aligned with the idea of macros returning function objects. If a macro could return a function object, then the macro designer could simply create a function in whatever namespace they wanted. Currently, function objects can't be wrapped by a Hy object. Any ideas on how a function object could be represented in the Hy language model? |
I don't think we can do that, because Python AST can't. |
Maybe related to #919. You could sort of emulate having arbitrary Python objects in the AST using pickle. See also https://stackoverflow.com/questions/51675355/how-to-eval-a-cond-case-and-return-function-object The easiest way for a macro to resolve to a function object defined in another namespace is probably to expand to something like |
I'm reasonably confident that the way macro scoping works now is what we're going with for 1.0. It's what I've documented in detail in #2531. |
Would we ever want functions resulting from the expansion of an imported macro to share the macro's namespace and/or
require
s? Of course a macro can be made toimport
/require
its expansion's dependencies, but let's say one wanted to explicitly limit such dependencies to the resulting function's namespace/closure and not the namespace in which the macro is evaluated.This is related to the "auto-
require
s"-like functionality recently introduced in #1682, but it's not the same.To illustrate, consider the following:
In this example, or a similar one, would we ever want/expect
((fn-create))
to print"hi"
?The text was updated successfully, but these errors were encountered: