Skip to content
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

Support user introspection and modification of the currently defined macros #1467

Closed
ekaschalk opened this issue Dec 16, 2017 · 6 comments · Fixed by #2525
Closed

Support user introspection and modification of the currently defined macros #1467

ekaschalk opened this issue Dec 16, 2017 · 6 comments · Fixed by #2525
Labels

Comments

@ekaschalk
Copy link
Contributor

ekaschalk commented Dec 16, 2017

Help me understand 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
@gilch
Copy link
Member

gilch commented Dec 16, 2017

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))

@ekaschalk
Copy link
Contributor Author

Ok thanks a simple (hy.eval '(import hy.macros)) in the module being tested does the trick.

@Kodiologist
Copy link
Member

I don't think hy.macros._hy_macros is intended for public use.

@ekaschalk
Copy link
Contributor Author

ekaschalk commented Dec 17, 2017

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.

@Kodiologist
Copy link
Member

No, I don't think so. We've never worked on introspection of the macro system beyond Hy's own internal needs.

@Kodiologist Kodiologist changed the title Help understanding hy.macros.-hy-macros initialization. Support user introspection and modification of the currently defined macros Nov 12, 2022
@Kodiologist
Copy link
Member

Better support for introspection of the macro system could replace hy.reserved and perhaps also delmacro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants