Proc argument names instead of arity

M

Macario Ortega

Hi, i am trying to make a SuperCollider(http://www.audiosynth.com/)
client for ruby and I want it to be as close as using SCLang.

Both languages are very similar, although i find ruby more concise but
SCLang function object (equivalent to ruby proc) can give you an array
of the function's argument names which is the basis of the synth
creation process, so in SCLang you can do:

var func = { |arg1, arg2| arg1 + arg2 }
=> a Function
var def = func.def
=> a FunctionDef - closed
def.argumentNames
=> [arg1, arg2]

Is there any way of doing this with ruby?
 
R

Roger Pack

var func = { |arg1, arg2| arg1 + arg2 }
=> a Function
var def = func.def
=> a FunctionDef - closed
def.argumentNames
=> [arg1, arg2]

Is there any way of doing this with ruby?


Appears that there is.
~ sudo gem install ParseTree
class A; def go(b); end; end
args = ParseTree.translate(A, :go)[2][1][1]
=> [:args, :b]

Only works with MRI.
Been using it recently for an auto named variable generator.
GL.
-R
 
M

Macario Ortega

Roger said:
Appears that there is.
~ sudo gem install ParseTree
class A; def go(b); end; end
args = ParseTree.translate(A, :go)[2][1][1]
=> [:args, :b]

Only works with MRI.
Been using it recently for an auto named variable generator.
GL.
-R

I will check it out

I want to get the arg names for a block passed as an argument, I will
check the API. Thanks!!
 
M

Macario Ortega

Roger said:
Another option is to pass args as an array
:abc => 123

Yeah, extracting the arg names is the sclang solution but is not the
only plausible one, thanks.
 
M

Macario Ortega

Macario said:
Yeah, extracting the arg names is the sclang solution but is not the
only plausible one, thanks.

Anyway I would like get the arg names for a proc. Is it doable with
parsetree. I am googling about it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top