I try to play 5 different proxys. Lets say they are: ~out1.play; ~out2.play; ~out3.play… and so on. Instead of writing all outs.play separately I want to do this faster:
5.do{arg i;
~((out++(i+1)).asSymbol).play} is not working. How can I do this?
Thanks in advance!
try
currentEnvironment.at( (“out”++ (i+1) ).asSymbol )
the ProxySpace is an instance of Environment - read the help on Environment for more
Also envirGet
and envirPut
.
hjh
Thanks a lot! I was finding another solution too:
5.do{arg i; “~out%.play;”.format(i+1).interpret};
FWIW – benchmarking the different approaches, I found that currentEnvironment[...]
and (...).envirGet
run at about the same speed, but interpret
is about three times slower. That isn’t surprising: the first two are simple method calls that go directly to primitives; the third calls into the parser, builds a function, and evaluates the function (much heavier operations).
~a1 = 1; ~a2 = 2; ~a3 = 3; ~a4 = 4; ~a5 = 5;
bench { 100000.do { |i| ("a" ++ (i%5 + 1)).asSymbol.envirGet } }
bench { 100000.do { |i| currentEnvironment[("a" ++ (i%5 + 1)).asSymbol] } }
bench { 100000.do { |i| ("~a" ++ (i%5 + 1)).interpret } }
hjh