hy
hy copied to clipboard
Help understanding hy.macros.-hy-macros initialization.
First run will print hy.macros.-hy-macros
fine. Second and subsequent runs will print an empty dict.
Deleting the foo.pyc
will reset the -hy-macros
dict as expected.
Is this intended behavior? If intended - how do I test code referencing -hy-macros
?
pkg/foo.hy
(import hy.macros)
(defn foo []
(print hy.macros.-hy-macros))
pkg/test_foo.hy
(import [pkg.foo [foo]])
(defn test-foo []
(foo)
(doc ->)) ; Similarly, will print on first runthrough, error on second run
Maybe related to #1324.
It's easy to force a compile at runtime though, just use hy.eval
, e.g.
(hy.eval '(print hy.macros._hy-macros))
Ok thanks a simple (hy.eval '(import hy.macros))
in the module being tested does the trick.
I don't think hy.macros._hy_macros
is intended for public use.
Is there a better way to access all defined macros? doc
takes the same approach (and has the same error on a second run). It's for code introspection for Emacs, not sure if that qualifies as public use.
No, I don't think so. We've never worked on introspection of the macro system beyond Hy's own internal needs.
Better support for introspection of the macro system could replace hy.reserved
and perhaps also delmacro
.