hy
hy copied to clipboard
Inconsistent number of executions of a file that requires itself
Consider the following code similar to Hy's tests/resources/bin/circular_macro_require.hy
, placed in mydir/t1.hy
:
(defmacro bar [expr]
`(print (.upper ~expr)))
(defmacro foo [expr]
`(do (require mydir.t1 [bar])
(bar ~expr)))
(foo "wowie")
If executed from outside the directory with PYTHONPATH=. hy mydir/t1.hy
, it prints "WOWIE" once. If, on the other hand, you run the same file but with its parent directory set to your current working directory, and with the require
form changed appropriately, you get two copies of "WOWIE".
This issue is probably related to how the require
macro only adds a call to hy.macros.require
in the generated Python AST if the compile-time call to hy.macros.require
returns true.