It would be easy enough to write a macro @saved_info function foo(x::Int) x+2 end
body_of(foo, (Int,)) # -> :(x+2) What do you want to do? On Thursday, May 5, 2016 at 5:18:27 PM UTC-4, Curtis Vogt wrote: > > What does it mean to comvert a method to a expression. > > > What I was hoping for was to get the implementation of the method back as > an expression, something like: > > julia> expr = :(foo(n::Integer) = 2*n) > :(foo(n::Integer) = begin # REPL[2], line 1: > 2n > end) > > julia> eval(expr) > foo (generic function with 1 method) > > julia> method = first(methods(foo)) > foo(n::Integer) at REPL[2]:1 > > julia> Expr(method) == expr # Not reality > true > > More than likely it isn't possible. I just figured it was worth asking. A > far more likely scenario would be to get a LambdaInfo as an Expr: > > julia> foo(n::Integer) = 2*n > foo (generic function with 1 method) > > julia> method = first(methods(foo)) > foo(n::Integer) at REPL[1]:1 > > julia> method.lambda_template > LambdaInfo for foo > :(begin # REPL[1], line 1: > return 2 * n > end) > > > On Thursday, May 5, 2016 at 3:59:20 PM UTC-5, Yichao Yu wrote: >> >> On Thu, May 5, 2016 at 3:45 PM, Curtis Vogt <[email protected]> wrote: >> > I doubt this is possible but is there a way of creating an expression >> from a >> > Method or LambaInfo? Something like: >> > >> > julia> m = first(methods(open, (AbstractString,))) >> > open(fname::AbstractString) at iostream.jl:99 >> > >> > julia> Expr(m) >> > ERROR: TypeError: Expr: expected Symbol, got Method >> > in Expr(::Any) at ./boot.jl:270 >> > in eval(::Module, ::Any) at ./boot.jl:228 >> > >> > >> > I'm running Julia 0.5.0-dev+3898. >> >> What does it mean to comvert a method to a expression. >> >
