Re: [julia-users] how to i get number of arguments of a function?

2016-01-28 Thread Mauro
> 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,

Re: [julia-users] how to i get number of arguments of a function?

2016-01-27 Thread Jon Norberg
Wow, thanks a lot, That one I would never had a chance to figure out.

Re: [julia-users] how to i get number of arguments of a function?

2016-01-22 Thread Jon Norberg
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

Re: [julia-users] how to i get number of arguments of a function?

2016-01-22 Thread Mauro
> 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

Re: [julia-users] how to i get number of arguments of a function?

2016-01-21 Thread amiksvi
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

Re: [julia-users] how to i get number of arguments of a function?

2016-01-21 Thread Yichao Yu
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

Re: [julia-users] how to i get number of arguments of a function?

2016-01-21 Thread amiksvi
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))

[julia-users] how to i get number of arguments of a function?

2014-10-16 Thread Evan Pu
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

Re: [julia-users] how to i get number of arguments of a function?

2014-10-16 Thread Tim Holy
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

Re: [julia-users] how to i get number of arguments of a function?

2014-10-16 Thread Evan Pu
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,

Re: [julia-users] how to i get number of arguments of a function?

2014-10-16 Thread Toivo Henningsson
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.

Re: [julia-users] how to i get number of arguments of a function?

2014-10-16 Thread Evan Pu
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