r - Julia: show body of function (to find lost code) -
in r-language able declare function , see body of function so:
> megafoobar = function(x){ return(x + 10000 )} > body(megafoobar) { return(x + 10000) } is possible in julia? wrote function useful , still in memory/callable forgot how wrote it. hoping such method exists in julia can find out how wrote it.
for functions defined in package, can utilize less or @less. former, takes function name (and returns first definition, need not 1 want), latter, function call.
less(less) # first definition of less, # signature (string,integer) @less less(less) # definition of less(f::callable) but not work functions defined in repl. those, can utilize code_typed, returns ast (abstract syntax tree) of code, less readable. need provide type of arguments, because there can several functions same name: can them methods.
f(x::number) = x + 1 f(x::abstractarray) = length(x) methods(f) # 2 methods generic function "f": # f(x::number) @ none:1 # f(x::abstractarray{t,n}) @ none:1 code_typed(f,(number,)) # give argument types tuple # 1-element array{any,1}: # :($(expr(:lambda, {:x}, {{},{{:x,number,0}},{}}, :(begin # none, line 1: # homecoming x::number + 1 # end)))) r function julia-lang
No comments:
Post a Comment