-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
@macroexpand macro #18240
Comments
I think the extra complications to the above are the handling of |
A naive implementation would be as follows:
It would be good to have a concrete example that breaks this. |
macro foo(ex)
isa(ex,Expr) && ex.head == :$ ? 7 : ex
end gives julia> @macroexpand @foo $bar
ERROR: UndefVarError: bar not defined
julia> @foo $bar
7 |
the |
Okay, if I run the function version of simonbyrne's example I get the same error:
The problem is julia trying to interpolate bar into the expression, before the function gets even called. So this means getting the correct expansion of simonbyrne's example using a function is impossible. Do I see this correctly? |
Well, it is possible, just a bit more complicated: see the MacroTools link above. |
I just meant it is impossible by using a function e.g. one has to write a macro which does not rely on a function, like the current |
The error has nothing to do with the function it's from the expression object. What you need is to properly convert the expression object before returning it from the macro. |
Thanks for the help and sorry for the confusion. It seems that
|
Passes the simonbyrne example. In this case the code gets passed directly to |
No need to use |
Yes I know that the function call is not the problem, but $ interpolation that takes place before function is even called. |
Only after the macro returns
Yes
It won't happen.
No
There's a function for it already. |
Thanks, finally I can see clear. I will put together a PR using
|
Writing
macroexpand(:(@foo x y z))
is a bit of a mouthful, but the expression passed to themacroexpand
function needs to be quoted, of course. With a@macroexpand
macro, this could be less annoying:@macroexpand @foo x y z
The text was updated successfully, but these errors were encountered: