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

MacroTools not defined #30

Closed
cstjean opened this issue Jan 9, 2017 · 3 comments · Fixed by #201
Closed

MacroTools not defined #30

cstjean opened this issue Jan 9, 2017 · 3 comments · Fixed by #201

Comments

@cstjean
Copy link
Collaborator

cstjean commented Jan 9, 2017

module MM
using MacroTools: @capture
@capture(:(x=2), _lhs = _rhs)
end
> UndefVarError: MacroTools not defined

It works if I import MacroTools. In my code, I usually fix this by writing function calls like $MacroTools.foo(...), but I don't use hygiene so I'm not sure if it's applicable in your case.

This is still definitely one of the most useful Julia packages for me, thank you!

@MikeInnes
Copy link
Member

Glad it's useful, thanks!

You can fix this easily enough by adding using MacroTools, but it's pretty surprising that the above syntax doesn't import the MacroTools name into scope itself (breaking the macro). I'd open an issue open Base Julia for this since it will affect all macros.

@fingolfin
Copy link
Contributor

The code expanded by the macro invokes MacroTools.trymatch, which indeed is not available in the current scope after just doing using MacroTools: @capture. And I think this makes sense given that the expression returned by the macro is evaluated in the context of the calling module, not in the context of MacroTools. So I don't think there is a bug in Julia to report here?

If one was willing to require Julia 1.6, one could perhaps use something like import MacroTools as some_generated_symbol and then some_generated_symbol.trymatch.

@cstjean
Copy link
Collaborator Author

cstjean commented Dec 28, 2021

My standard solution would be to macroexpand into $MacroTools.trymatch. Would that work here?

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

Successfully merging a pull request may close this issue.

3 participants