home/ atoms/ chuck-arrow-operator-overloading

ChucK's `=>` operator means patch, control, or assign depending on the operand types

ChucK uses the same => operator for three distinct operations, disambiguated entirely by operand types: audio patching (SinOsc s => dac), calling a setter/control (440 => s.freq), and variable declaration-and-assignment (2 => int x). Value flows left-into-right as written, which surprises programmers from C/Python/JavaScript who reach for s.freq = 440. Reading a value back out is also =>: s.freq => float f. For object references and arrays the special @=> operator is required — plain => on a fresh array literal will not declare it correctly.

Examples

SinOsc s => dac; // patch audio 440 => s.freq; // control (setter) 2 => int x; // declare+assign [0,2,4] @=> int a[]; // reference-assign array

Assessment

Given [1,3,5] => int notes[];, explain what is wrong and write the correct form. Then distinguish the three uses of plain => with one example each.

“`SinOsc s => dac` **patches** (audio). `440 => s.freq` **controls** (calls the setter). `2 => int x` **declares+assigns**. Same operator, different meaning by operand types”
context/ · L1-instruments/chuck/gotchas.md · chunk 1