-
Notifications
You must be signed in to change notification settings - Fork 2
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
Apply esc
to returned node of @json
to allow referring local variables
#1
Comments
Also, you should use Evaluation in a loaded module should avoided for it's purely dynamic. |
I have been highly confused by module mod
macro ee(x)
x
end
end seems to
|
I do understand you, for it might be quite annoying at the very beginning(even if you have exprience with macro processing in other languages).
function() __module__
end # wrong
macro f()
mod = __module__
:(1 + $(mod.a))
end
a = 1
@f
# => 2
macro g1()
:(1 + x)
end
function f(x)
@g1
end
f(2) # `x` is not defined!
macro g2()
:(1 + x) |> esc
end
function f(x)
@g2
end
f(2) # => 3 |
Thanks, I will study this a few times over. The funny thing is that by just half understanding, I can already accomplish quite a lot myself, but I keep getting surprises. Right now I can process the dubious
and the same problem crashes |
Hello again @thautwarm, I've read the metaprogramming docs about 5 times now, and despite the complicated examples and your explanations I still can't make a trivial macro that returns the input, untouched, from within a module. I understand that I need to modify an AST expression, and return an Expr, but if I can't even not modify the incoming expression I don't see how I can even begin thinking about modifying the AST. The best I can come up with for an identity macro is module Identity
macro identity(e)
ret = id(__module__, e)
dump(ret)
ret
end
id(m, e::Expr) = e
id(m, s::Symbol) = :($m.$s)
id(m, x) = x
end but this stops working when So I don't really understand why my code mostly works, I call functions from within the macro that happily create dicts and stuff. Generally, I don't understand why the macro expansion per se wants to implicity evaluate the (manipulated) expression in its own module environment just before returning the expression to the calling code. |
Okay, I've found more docs and I think I've found a more concise solution to the identity macro: module Identity
macro identity(e)
return :($(esc(e)))
end
end Perhaps this macro still evaluates the expression
Perhaps there is a macro for that. |
I think I have a reasonably working version committed with now. See runtest.jl |
Hi, David, it seems that you've undertood them all. The expression generated inside an However, module Identity
macro identity(e)
return esc(e)
end
end |
Wow, that it could be that simple! Perhaps this could be mentioned somewhere near the docs of |
Okay, I think this package could be pretty useful in the future, but currently Julia is not that popular, which I think to be the reason why you didn't earn a lot of stars. |
I think there are already great JSON packages, like LazyJSON (haven't tried it, but needed it often in the past). This package was partly inspired by an old discussion and my recent job activities involving typescript and mongo, where everything really seems to be about almost ad-hoc constructing and deeply digging into complex JSON-like objects. I didn't know graphQL, but I see that there is a Julia package as well. Do you mean that the route AST -> graphQL query could also be covered by macros, such that you could write: @schema
type Query {
hello: String
} and produce a Julia-representation of the query in DIana? |
No description provided.
The text was updated successfully, but these errors were encountered: