Getting parameter names from Method

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Getting parameter names from Method

David Anthoff

Is there a way to get the names of the parameters of a method from a Method type instance on julia 0.5?

 

Thanks,

David

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting parameter names from Method

Yichao Yu
On Fri, Nov 4, 2016 at 6:31 PM, David Anthoff <[hidden email]> wrote:
> Is there a way to get the names of the parameters of a method from a Method
> type instance on julia 0.5?

Roughly:

nargs tell you how many arguments the method accepts, the first one
being the object (function) being called.
The local variables names are available in the CodeInfo.slotnames and
the first nargs ones are the parameter names.
The CodeInfo can be found in the source field of the method for
non-generated functions and unspecialized.inferred for generated
function.

>
>
>
> Thanks,
>
> David
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Getting parameter names from Method

David Anthoff
How do I get at this nargs field? On julia 0.5 Method doesn't seem to have a field with that name?

> -----Original Message-----
> From: [hidden email] [mailto:julia-
> [hidden email]] On Behalf Of Yichao Yu
> Sent: Friday, November 4, 2016 3:54 PM
> To: Julia Users <[hidden email]>
> Subject: Re: [julia-users] Getting parameter names from Method
>
> On Fri, Nov 4, 2016 at 6:31 PM, David Anthoff <[hidden email]>
> wrote:
> > Is there a way to get the names of the parameters of a method from a
> > Method type instance on julia 0.5?
>
> Roughly:
>
> nargs tell you how many arguments the method accepts, the first one being
> the object (function) being called.
> The local variables names are available in the CodeInfo.slotnames and the
> first nargs ones are the parameter names.
> The CodeInfo can be found in the source field of the method for non-
> generated functions and unspecialized.inferred for generated function.
>
> >
> >
> >
> > Thanks,
> >
> > David

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting parameter names from Method

Ralph Smith
julia> mt=methods(randjump)
# 2 methods for generic function "randjump":
randjump(r::MersenneTwister, jumps::Integer) at random.jl:145
randjump(mt::MersenneTwister, jumps::Integer, jumppoly::AbstractString) at random.jl:137

julia> mt.ms[2].lambda_template.slotnames
8-element Array{Any,1}:
 Symbol("#self#")
 :mt             
 :jumps          
 :jumppoly       
 :mts            
 Symbol("#temp#")
 :i              
 :cmt            

julia> mt.ms[2].lambda_template.nargs
4




On Friday, November 4, 2016 at 7:00:56 PM UTC-4, David Anthoff wrote:
How do I get at this nargs field? On julia 0.5 Method doesn't seem to have a field with that name?

> -----Original Message-----
> From: <a href="javascript:" target="_blank" gdf-obfuscated-mailto="xmtBeceeAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">julia...@... [mailto:<a href="javascript:" target="_blank" gdf-obfuscated-mailto="xmtBeceeAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">julia-
> <a href="javascript:" target="_blank" gdf-obfuscated-mailto="xmtBeceeAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">us...@...] On Behalf Of Yichao Yu
> Sent: Friday, November 4, 2016 3:54 PM
> To: Julia Users <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="xmtBeceeAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">julia...@...>
> Subject: Re: [julia-users] Getting parameter names from Method
>
> On Fri, Nov 4, 2016 at 6:31 PM, David Anthoff <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="xmtBeceeAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">ant...@...>
> wrote:
> > Is there a way to get the names of the parameters of a method from a
> > Method type instance on julia 0.5?
>
> Roughly:
>
> nargs tell you how many arguments the method accepts, the first one being
> the object (function) being called.
> The local variables names are available in the CodeInfo.slotnames and the
> first nargs ones are the parameter names.
> The CodeInfo can be found in the source field of the method for non-
> generated functions and unspecialized.inferred for generated function.
>
> >
> >
> >
> > Thanks,
> >
> > David

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Getting parameter names from Method

David Anthoff

Thanks!

 

I’ve now been using Base.arg_decl_parts, which also seems to work. Any word of wisdom which of these two approaches is “better”?

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Ralph Smith
Sent: Friday, November 4, 2016 8:23 PM
To: julia-users <[hidden email]>
Subject: Re: [julia-users] Getting parameter names from Method

 

julia> mt=methods(randjump)

# 2 methods for generic function "randjump":

randjump(r::MersenneTwister, jumps::Integer) at random.jl:145

randjump(mt::MersenneTwister, jumps::Integer, jumppoly::AbstractString) at random.jl:137

 

julia> mt.ms[2].lambda_template.slotnames

8-element Array{Any,1}:

 Symbol("#self#")

 :mt             

 :jumps          

 :jumppoly       

 :mts            

 Symbol("#temp#")

 :i              

 :cmt            

 

julia> mt.ms[2].lambda_template.nargs

4

 




On Friday, November 4, 2016 at 7:00:56 PM UTC-4, David Anthoff wrote:

How do I get at this nargs field? On julia 0.5 Method doesn't seem to have a field with that name?


> -----Original Message-----
> From: <a href="javascript:" target="_blank">julia...@... [mailto:<a href="javascript:" target="_blank">julia-
> <a href="javascript:" target="_blank">us...@...] On Behalf Of Yichao Yu
> Sent: Friday, November 4, 2016 3:54 PM
> To: Julia Users <<a href="javascript:" target="_blank">julia...@...>
> Subject: Re: [julia-users] Getting parameter names from Method
>
> On Fri, Nov 4, 2016 at 6:31 PM, David Anthoff <<a href="javascript:" target="_blank">ant...@...>
> wrote:
> > Is there a way to get the names of the parameters of a method from a
> > Method type instance on julia 0.5?
>
> Roughly:
>
> nargs tell you how many arguments the method accepts, the first one being
> the object (function) being called.
> The local variables names are available in the CodeInfo.slotnames and the
> first nargs ones are the parameter names.
> The CodeInfo can be found in the source field of the method for non-
> generated functions and unspecialized.inferred for generated function.
>
> >
> >
> >
> > Thanks,
> >
> > David

Loading...