> Wow, thanks a lot, That one I would never had a chance to figure out.
It's easy enough, you could figure it out yourself too, knowing just a
few tricks. The essentials are here:
http://docs.julialang.org/en/release-0.4/devdocs/reflection/ plus the
tools: xdump, @less, @edit, @which.
In fact,
Wow, thanks a lot, That one I would never had a chance to figure out.
Is it also possible to get a list of names of the variables used in a
function?
e.g. for
function f(x,y)
k=0.1
return x*y+k
end
I'd like to get a list ["k","x","y"]
My first thought was to make a method f() that returns this list, but if
its possible to do this otherwise and more
> Is it also possible to get a list of names of the variables used in a
> function?
>
> e.g. for
>
> function f(x,y)
> k=0.1
> return x*y+k
> end
>
> I'd like to get a list ["k","x","y"]
>
> My first thought was to make a method f() that returns this list, but if
> its possible to do this
I'm using Julia v0.4.2 and I can't compute the length of what m.sig returns:
julia> function f(x)
end
julia> for m in methods(f)
println(length(m.sig))
end
ERROR: MethodError: `length` has no method matching length(::Type{Tuple{
Int64,Int64}})
Since I'm trying to use the
On Thu, Jan 21, 2016 at 11:35 AM, wrote:
> I'm using Julia v0.4.2 and I can't compute the length of what m.sig returns:
>
> julia> function f(x)
>end
>
> julia> for m in methods(f)
> println(length(m.sig))
>end
> ERROR: MethodError: `length` has no
Great, thanks a lot.
In fact, I also need to evaluate the number of arguments of an anonymous
function:
julia> function factory(y)
return x -> x + y
end
factory (generic function with 1 method)
julia> type Foo
f::Function
end
julia> foo = Foo(factory(2))
How do I get the number of arguments of a function?
for instance, f(x, y) = x + y
I want something like num_args(f), which will give me back 2. If the
function has multiple methods then something more general would be nice,
but so far I only care about functions with just a single method.
Is
You might want to look into the various introspection functions, like
`methods`, `code_lowered`, etc. Leah Hanson had a nice blog post:
http://blog.leahhanson.us/julia-introspects.html
For your specific problem, once you have a specific method, then `m.sig`
returns
its signature, and you can
thanks!!
On Thursday, October 16, 2014 12:41:22 PM UTC-4, Tim Holy wrote:
You might want to look into the various introspection functions, like
`methods`, `code_lowered`, etc. Leah Hanson had a nice blog post:
http://blog.leahhanson.us/julia-introspects.html
For your specific problem,
Though you should probably look out for varargs methods too, the length of e.g.
(Int...) is one, but a method with that signature can take any number of
arguments.
yeah, the function I'm intending to inspect will be defined by me and they
shouldn't be varargs
On Thursday, October 16, 2014 2:10:34 PM UTC-4, Toivo Henningsson wrote:
Though you should probably look out for varargs methods too, the length of
e.g. (Int...) is one, but a method with that
12 matches
Mail list logo