Anonymous functions are a bit incomplete / not-fully-integrated in 0.4, and
I think this falls out as a consequence.
You can simulate the result you want with:
julia> function returnMacro()
eval(parse("""
macro myMacro(anexpr)
parse(anexpr)
end
"""))
eval(symbol("@myMacro"))
end
julia> mymacro = returnMacro()
(anonymous function)
julia> mymacro("1+1")
:(1 + 1)
However, there have been significant improvements to anonymous functions in
the nightly (0.5-dev), and the result is what you expect:
julia> function returnMacro()
eval(parse("""
macro myMacro(anexpr)
parse(anexpr)
end
"""))
end
returnMacro (generic function with 1 method)
julia> mymacro = returnMacro()
@myMacro (macro with 1 method)
julia> typeof(mymacro)
#@myMacro
julia> mymacro("1+1")
:(1 + 1)
That said, `mymacro` here is purely a function handle -- totally identical
to writing `mymacro(expr) = parse(expr)`. There is no special behavior.
(are you trying to do something specific?)
On Tue, Jul 5, 2016 at 11:04 AM, Rangarajan Krishnamoorthy <
[email protected]> wrote:
> Consider this function:
>
> function returnMacro()
> eval(parse("""
> macro myMacro(anexpr)
> parse(anexpr)
> end
> """))
> end
>
> I assign the function's result to a variable:
> mymacro = returnMacro()
>
> Then, typeof(mymacro) returns "Void". Is this correct? Because macros are
> parse time entities, wouldn't it be better for "eval" to raise some sort of
> exception?
>
> -Rangarajan
>