Hello colleagues,

one of the USPs of julia is (should be) metaprogramming i.e. creating 
programs by running other programs.
I'm playing around with Expr to create functions, but this look more 
complicated than the actual job...

# three versions

function f1(x::Int64)
        x+31
end

function fe2a()
        e0 = Expr(:function,
                Expr(:call,:f2a,
                        Expr(symbol("::"),:x,:Int64)),
                Expr(:call,:+, :x, 31))
        e0
end

function fe2b()
        e1 = Expr(:call)
        e1.args = [:+, :x, 31]
        ef = Expr(symbol("::"))
        ef.args = [:x, :Int64]
        e2 = Expr(:call)
        e2.args = [:f2b,ef]
        e3 = Expr(:function)
        e3.args = [e2,e1]
        e3
end


afaics Expr needs constant arguments, but the expression created allows 
changing fields (like args). Could Expr be extended, so that it also 
accepts Arrays as arguments?

Reply via email to