[chuck-users] Any way to call an arbitrary function with some value

Kassen signal.automatique at gmail.com
Wed Feb 25 12:19:54 EST 2015

Hey, Rich!

I’m pretty sure I know the answer to this already – its not a dynamic
> language...

Indeed, and not a functional one either... but let's go over it anyway :-)

> However, I can put a UGen method into a variable, but I cannot apply it:
> ...
> SndBuf2 input;
> input.gain @=> Object f;
> ...
> This compiles, but can I apply it to an argument?

IMHO you have found a bug. I don't feel this should compile or parse;
input.gain is a function and functions are not objects, in ChucK, and hence
I feel the assignment should fail with some error message. I can see your
reasoning; that if it compiles you'll want to do Useful Stuff with it, but
IMHO this situation is the sad result of differences between "ChucK" as a
language and the actual chuck compiler/VM.

> Am trying to find a way of modifying arbitrary parameters via osc that
> doesn’t include writing unmaintainable code:
> ...
> if (parameterName == “gain”) myUgen.gain (value);
> ... etc ...
Ok, I can see how the above would look better if we had variables of type
function. We don't have those... but your illustration here looks far from
"unmaintainable" to me. Indeed it is a bit longer than the alternative in
-say- Scheme, but on the bright side; if you make a typo in this kind of
situation the parser will likely catch it for you before it compiles at
all. That has serious benefits too in how maintainable code is.

Hope that helps a bit?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20150225/a9374d35/attachment.html>

More information about the chuck-users mailing list