It seems “->” could be one head of Expr, but I always got tuple head when trying
:(:->, :a, :a)
I was trying to know a little more about “->” and searched the document & google with no luck.
I also searched source code and found :lambda
lam = Expr(:lambda, g.argnames, …
Still, not much helpful. So where is the Symbol “->” defined?
You can construct an expression using Expr, but that relies on internals which may (1) change, (2) be complicated, or in some cases (3) irrelevant. Do what @mauro3 suggested, and construct expressions using interpolation, eg :($(aexpr) -> $(bexpr))
If you are interested in internals, just use something like
julia> dump(:(a -> b))
Expr
head: Symbol ->
args: Array{Any}((2,))
1: Symbol a
2: Expr
head: Symbol block
args: Array{Any}((2,))
1: LineNumberNode
line: Int64 1
file: Symbol REPL[39]
2: Symbol b
Note that the contents of Expr nodes are not “internals”, they are part of the exported Julia API; it is often necessary to use them when writing macros, for example. Breaking changes to Expr nodes should not be made in the Julia 1.x timeline.
That section is about the lowered form of the AST. The surface-syntax Expr nodes are documented in the metaprogramming section of the manual, though the documentation could be more complete. Because macros directly access the surface-syntax Expr type, it is part of the API that cannot be changed without breaking valid user code.