-
Notifications
You must be signed in to change notification settings - Fork 372
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
require
and macro dependencies
#1650
Comments
Automatically determining which macros a piece of code depends upon is, I suspect, undecidable. But there's no reason in principle that we couldn't make Generally, macro subroutines are better written as functions than macros. Unfortunately, that's not an option when you're using a preexisting macro like |
The idea of My first response to this situation involved things like Given that Hy seems partly inspired by Clojure, how does it handle these things? (Unfortunately, I'm not familiar enough with Clojure to readily find that answer in its source.) |
Not scalable? Do you mean you expect there to be some kind of performance problem with allowing |
I doubt it'd really be any slower than Python's imports already are TBH. |
@Kodiologist, sure, but for no reason other than generic pessimism. Well, I would also include "complexity" (of code changes, comprehensibility, maintenance, etc.) into that scaling. Regardless, if there's negligible performance and/or complexity hits, then I'm all for it! I'm walking through the |
I don't anticipate a performance issue, no, and the resulting Hy programs will obviously not be more complex. I don't think the implementation will be complex, either, but figuring out how to do it could take some work. |
Clojure namespaces ("qualifies") symbols. So if you do a syntax quote, it automatically prepends the symbol's namespace to prevent conflicts. (Special forms are immune). If we had Clojure's system, then given your example, (defmacro test-module-macro [a]
`(let [b 1] (+ b ~a))) If invoked like (macroexpand-1 '(test-module-macro q)) Would expand to something like (hy.contrib.walk/let [test-module/b 1] (+ test-module/b q)) Let's try it in Clojure. First change namespace. Clojure 1.6.0
user=> (ns walk)
nil Clojure already has walk=> (defmacro LET [& body] `(let ~@body))
#'walk/LET
walk=> (ns test)
nil
test=> (refer 'walk :only '[LET])
nil
test=> (defmacro test-macro [a]
`(LET [b 1] (+ b ~a)))
#'test/test-macro
test=> (macroexpand-1 '(test-macro q))
(walk/LET [test/b 1] (clojure.core/+ test/b q)) Of course, this doesn't actually work in Clojure. test=> (test-macro q)
CompilerException java.lang.RuntimeException: Can't let qualified name: test/b, compiling:(NO_SOURCE_PATH:8:1) That's because it was almost certainly a mistake. The test=> (defmacro test-macro [a]
`(LET [b# 1] (+ b# ~a)))
#'test/test-macro
test=> (macroexpand-1 '(test-macro q))
(walk/LET [b__36__auto__ 1] (clojure.core/+ b__36__auto__ q))
test=> (test-macro 41)
42 Hy uses If you actually want to capture (like for an anaphoric macro), you can do that too. test=> (defmacro test-macro [a]
`(LET [~'b 1] (+ ~'b ~a)))
#'test/test-macro
test=> (macroexpand-1 '(test-macro q))
(walk/LET [b 1] (clojure.core/+ b q))
test=> (test-macro 41)
42 Of course, all this is currently Hypothetical in Hy. Heh. But you can see how a proper namespacing implementation would be easier to use than my current recommendation, (defmacro/g! test-module-macro [a]
`(do
(require [hy.contrib.walk [let :as ~g!let]])
(~g!let [~g!b 1]
(+ ~g!b ~a)))) |
This commit adds just enough namespacing to resolve a macro first in the Hy compilation namespace (i.e. the module assigned to the `HyASTCompiler`), then in the namespace it was defined. Namespacing is accomplished by adding a `module` attribute to `HySymbol`, so that `HyExpression`s can be checked for this definition namespace attribute and their car symbol resolved per the above. As well, a test is included that covers module-level macros (i.e. via `__macros` and `__tags__`), AST generated for `require`, and the non-local macro namespace resolution described above. Closes hylang#1268, closes hylang#1650, closes hylang#1416.
This commit adds just enough namespacing to resolve a macro first in the macro's defining module's namespace (i.e. the module assigned to the `HyASTCompiler`), then in the namespace/module it's evaluated in. Namespacing is accomplished by adding a `module` attribute to `HySymbol`, so that `HyExpression`s can be checked for this definition namespace attribute and their car symbol resolved per the above. As well, a comprehensive test has been added that covers - the loading of module-level macros - e.g. that only macros defined in the `require`d module are added - the AST generated for `require` - using macros loaded from modules imported via bytecode - the non-local macro namespace resolution described above - a `require`d macro that uses a macro `require` exclusively in its module-level namespace - and that (second-degree `require`d) macros can reference variables within their module-level namespaces. Closes hylang#1268, closes hylang#1650, closes hylang#1416.
This commit adds just enough namespacing to resolve a macro first in the macro's defining module's namespace (i.e. the module assigned to the `HyASTCompiler`), then in the namespace/module it's evaluated in. Namespacing is accomplished by adding a `module` attribute to `HySymbol`, so that `HyExpression`s can be checked for this definition namespace attribute and their car symbol resolved per the above. As well, a couple tests have been added that cover - the loading of module-level macros - e.g. that only macros defined in the `require`d module are added - the AST generated for `require` - using macros loaded from modules imported via bytecode - the non-local macro namespace resolution described above - a `require`d macro that uses a macro `require` exclusively in its module-level namespace - and that (second-degree `require`d) macros can reference variables within their module-level namespaces. There's also a test--expected to fail--for hylang#1414. Closes hylang#1268, closes hylang#1650, closes hylang#1416.
This commit adds just enough namespacing to resolve a macro first in the macro's defining module's namespace (i.e. the module assigned to the `HyASTCompiler`), then in the namespace/module it's evaluated in. Namespacing is accomplished by adding a `module` attribute to `HySymbol`, so that `HyExpression`s can be checked for this definition namespace attribute and their car symbol resolved per the above. As well, a couple tests have been added that cover - the loading of module-level macros - e.g. that only macros defined in the `require`d module are added - the AST generated for `require` - using macros loaded from modules imported via bytecode - the non-local macro namespace resolution described above - a `require`d macro that uses a macro `require` exclusively in its module-level namespace - and that (second-degree `require`d) macros can reference variables within their module-level namespaces. There's also a test--expected to fail--for hylang#1414. Closes hylang#1268, closes hylang#1650, closes hylang#1416.
This commit adds just enough namespacing to resolve a macro first in the macro's defining module's namespace (i.e. the module assigned to the `HyASTCompiler`), then in the namespace/module it's evaluated in. Namespacing is accomplished by adding a `module` attribute to `HySymbol`, so that `HyExpression`s can be checked for this definition namespace attribute and their car symbol resolved per the above. As well, a couple tests have been added that cover - the loading of module-level macros - e.g. that only macros defined in the `require`d module are added - the AST generated for `require` - using macros loaded from modules imported via bytecode - the non-local macro namespace resolution described above - a `require`d macro that uses a macro `require` exclusively in its module-level namespace - and that (second-degree `require`d) macros can reference variables within their module-level namespaces. There's also a test--expected to fail--for hylang#1414. Closes hylang#1268, closes hylang#1650, closes hylang#1416.
This commit adds just enough namespacing to resolve a macro first in the macro's defining module's namespace (i.e. the module assigned to the `HyASTCompiler`), then in the namespace/module it's evaluated in. Namespacing is accomplished by adding a `module` attribute to `HySymbol`, so that `HyExpression`s can be checked for this definition namespace attribute and their car symbol resolved per the above. As well, a couple tests have been added that cover - the loading of module-level macros - e.g. that only macros defined in the `require`d module are added - the AST generated for `require` - using macros loaded from modules imported via bytecode - the non-local macro namespace resolution described above - a `require`d macro that uses a macro `require` exclusively in its module-level namespace - and that (second-degree `require`d) macros can reference variables within their module-level namespaces. There's also a test--expected to fail--for hylang#1414. Closes hylang#1268, closes hylang#1650, closes hylang#1416.
This commit adds just enough namespacing to resolve a macro first in the macro's defining module's namespace (i.e. the module assigned to the `HyASTCompiler`), then in the namespace/module it's evaluated in. Namespacing is accomplished by adding a `module` attribute to `HySymbol`, so that `HyExpression`s can be checked for this definition namespace attribute and their car symbol resolved per the above. As well, a couple tests have been added that cover - the loading of module-level macros - e.g. that only macros defined in the `require`d module are added - the AST generated for `require` - using macros loaded from modules imported via bytecode - the non-local macro namespace resolution described above - a `require`d macro that uses a macro `require` exclusively in its module-level namespace - and that (second-degree `require`d) macros can reference variables within their module-level namespaces. There's also a test--expected to fail--for hylang#1414. Closes hylang#1268, closes hylang#1650, closes hylang#1416.
This commit adds just enough namespacing to resolve a macro first in the macro's defining module's namespace (i.e. the module assigned to the `HyASTCompiler`), then in the namespace/module it's evaluated in. Namespacing is accomplished by adding a `module` attribute to `HySymbol`, so that `HyExpression`s can be checked for this definition namespace attribute and their car symbol resolved per the above. As well, a couple tests have been added that cover - the loading of module-level macros - e.g. that only macros defined in the `require`d module are added - the AST generated for `require` - using macros loaded from modules imported via bytecode - the non-local macro namespace resolution described above - a `require`d macro that uses a macro `require` exclusively in its module-level namespace - and that (second-degree `require`d) macros can reference variables within their module-level namespaces. There's also a test--expected to fail--for hylang#1414. Closes hylang#1268, closes hylang#1650, closes hylang#1416.
This commit adds just enough namespacing to resolve a macro first in the macro's defining module's namespace (i.e. the module assigned to the `HyASTCompiler`), then in the namespace/module it's evaluated in. Namespacing is accomplished by adding a `module` attribute to `HySymbol`, so that `HyExpression`s can be checked for this definition namespace attribute and their car symbol resolved per the above. As well, a couple tests have been added that cover - the loading of module-level macros - e.g. that only macros defined in the `require`d module are added - the AST generated for `require` - using macros loaded from modules imported via bytecode - the non-local macro namespace resolution described above - a `require`d macro that uses a macro `require` exclusively in its module-level namespace - and that (second-degree `require`d) macros can reference variables within their module-level namespaces. There's also a test--expected to fail--for hylang#1414. Closes hylang#1268, closes hylang#1650, closes hylang#1416.
This commit adds just enough namespacing to resolve a macro first in the macro's defining module's namespace (i.e. the module assigned to the `HyASTCompiler`), then in the namespace/module it's evaluated in. Namespacing is accomplished by adding a `module` attribute to `HySymbol`, so that `HyExpression`s can be checked for this definition namespace attribute and their car symbol resolved per the above. As well, a couple tests have been added that cover - the loading of module-level macros - e.g. that only macros defined in the `require`d module are added - the AST generated for `require` - using macros loaded from modules imported via bytecode - the non-local macro namespace resolution described above - a `require`d macro that uses a macro `require` exclusively in its module-level namespace - and that (second-degree `require`d) macros can reference variables within their module-level namespaces. Closes hylang#1268, closes hylang#1650, closes hylang#1416.
This commit adds just enough namespacing to resolve a macro first in the macro's defining module's namespace (i.e. the module assigned to the `HyASTCompiler`), then in the namespace/module it's evaluated in. Namespacing is accomplished by adding a `module` attribute to `HySymbol`, so that `HyExpression`s can be checked for this definition namespace attribute and their car symbol resolved per the above. As well, a couple tests have been added that cover - the loading of module-level macros - e.g. that only macros defined in the `require`d module are added - the AST generated for `require` - using macros loaded from modules imported via bytecode - the non-local macro namespace resolution described above - a `require`d macro that uses a macro `require` exclusively in its module-level namespace - and that (second-degree `require`d) macros can reference variables within their module-level namespaces. Closes hylang#1268, closes hylang#1650, closes hylang#1416.
This commit adds just enough namespacing to resolve a macro first in the macro's defining module's namespace (i.e. the module assigned to the `HyASTCompiler`), then in the namespace/module it's evaluated in. Namespacing is accomplished by adding a `module` attribute to `HySymbol`, so that `HyExpression`s can be checked for this definition namespace attribute and their car symbol resolved per the above. As well, a couple tests have been added that cover - the loading of module-level macros - e.g. that only macros defined in the `require`d module are added - the AST generated for `require` - using macros loaded from modules imported via bytecode - the non-local macro namespace resolution described above - a `require`d macro that uses a macro `require` exclusively in its module-level namespace - and that (second-degree `require`d) macros can reference variables within their module-level namespaces. Closes hylang#1268, closes hylang#1650, closes hylang#1416.
This commit adds just enough namespacing to resolve a macro first in the macro's defining module's namespace (i.e. the module assigned to the `HyASTCompiler`), then in the namespace/module it's evaluated in. Namespacing is accomplished by adding a `module` attribute to `HySymbol`, so that `HyExpression`s can be checked for this definition namespace attribute and their car symbol resolved per the above. As well, a couple tests have been added that cover - the loading of module-level macros - e.g. that only macros defined in the `require`d module are added - the AST generated for `require` - using macros loaded from modules imported via bytecode - the non-local macro namespace resolution described above - a `require`d macro that uses a macro `require` exclusively in its module-level namespace - and that (second-degree `require`d) macros can reference variables within their module-level namespaces. Closes hylang#1268, closes hylang#1650, closes hylang#1416.
This commit adds just enough namespacing to resolve a macro first in the macro's defining module's namespace (i.e. the module assigned to the `HyASTCompiler`), then in the namespace/module it's evaluated in. Namespacing is accomplished by adding a `module` attribute to `HySymbol`, so that `HyExpression`s can be checked for this definition namespace attribute and their car symbol resolved per the above. As well, a couple tests have been added that cover - the loading of module-level macros - e.g. that only macros defined in the `require`d module are added - the AST generated for `require` - using macros loaded from modules imported via bytecode - the non-local macro namespace resolution described above - a `require`d macro that uses a macro `require` exclusively in its module-level namespace - and that (second-degree `require`d) macros can reference variables within their module-level namespaces. Closes hylang#1268, closes hylang#1650, closes hylang#1416.
This commit adds just enough namespacing to resolve a macro first in the macro's defining module's namespace (i.e. the module assigned to the `HyASTCompiler`), then in the namespace/module it's evaluated in. Namespacing is accomplished by adding a `module` attribute to `HySymbol`, so that `HyExpression`s can be checked for this definition namespace attribute and their car symbol resolved per the above. As well, a couple tests have been added that cover - the loading of module-level macros - e.g. that only macros defined in the `require`d module are added - the AST generated for `require` - using macros loaded from modules imported via bytecode - the non-local macro namespace resolution described above - a `require`d macro that uses a macro `require` exclusively in its module-level namespace - and that (second-degree `require`d) macros can reference variables within their module-level namespaces. Closes hylang#1268, closes hylang#1650, closes hylang#1416.
This commit adds just enough namespacing to resolve a macro first in the macro's defining module's namespace (i.e. the module assigned to the `HyASTCompiler`), then in the namespace/module it's evaluated in. Namespacing is accomplished by adding a `module` attribute to `HySymbol`, so that `HyExpression`s can be checked for this definition namespace attribute and their car symbol resolved per the above. As well, a couple tests have been added that cover - the loading of module-level macros - e.g. that only macros defined in the `require`d module are added - the AST generated for `require` - using macros loaded from modules imported via bytecode - the non-local macro namespace resolution described above - a `require`d macro that uses a macro `require` exclusively in its module-level namespace - and that (second-degree `require`d) macros can reference variables within their module-level namespaces. Closes hylang#1268, closes hylang#1650, closes hylang#1416.
This commit adds just enough namespacing to resolve a macro first in the macro's defining module's namespace (i.e. the module assigned to the `HyASTCompiler`), then in the namespace/module it's evaluated in. Namespacing is accomplished by adding a `module` attribute to `HySymbol`, so that `HyExpression`s can be checked for this definition namespace attribute and their car symbol resolved per the above. As well, a couple tests have been added that cover - the loading of module-level macros - e.g. that only macros defined in the `require`d module are added - the AST generated for `require` - using macros loaded from modules imported via bytecode - the non-local macro namespace resolution described above - a `require`d macro that uses a macro `require` exclusively in its module-level namespace - and that (second-degree `require`d) macros can reference variables within their module-level namespaces. Closes hylang#1268, closes hylang#1650, closes hylang#1416.
This commit adds just enough namespacing to resolve a macro first in the macro's defining module's namespace (i.e. the module assigned to the `HyASTCompiler`), then in the namespace/module it's evaluated in. Namespacing is accomplished by adding a `module` attribute to `HySymbol`, so that `HyExpression`s can be checked for this definition namespace attribute and their car symbol resolved per the above. As well, a couple tests have been added that cover - the loading of module-level macros - e.g. that only macros defined in the `require`d module are added - the AST generated for `require` - using macros loaded from modules imported via bytecode - the non-local macro namespace resolution described above - a `require`d macro that uses a macro `require` exclusively in its module-level namespace - and that (second-degree `require`d) macros can reference variables within their module-level namespaces. Closes hylang#1268, closes hylang#1650, closes hylang#1416.
What are the expectations and conventions surrounding
require
-ed macros and their dependencies?For example, consider the following:
In
test-module.hy
In
some-file.hy
In its current state, running
some-file.hy
will produceThis result implies that
(require [test-module [*]])
does not account for the required module's requirements (i.e.let
inhy.contrib.walk
).How should dependencies like this be handled? More importantly, what would it take to automatically include macro dependencies?
FYI: This question started here, where @gilch provided a lot of important considerations and an approach.
The text was updated successfully, but these errors were encountered: