home/ atoms/ chuck-dur-time-arithmetic

In ChucK `dur`/`time` are typed and cannot mix with bare numbers — units need the `::` operator

ChucK treats dur and time as first-class typed values, distinct from plain numbers. A duration is written with the :: unit operator: 120::ms, 1::second120 ms does not parse. You cannot add a bare number to a time: now + 1 is a type error, while now + 1::second is correct. This typing is what makes ChucK’s timing sample-accurate and explicit, but it means arithmetic on time must always carry units.

Examples

now + 1::second // correct — advance one second from now now + 1 // type error (dur/time won’t mix with a bare int) 120::ms // a duration 120 ms // parse error

Assessment

Explain why now + 1 fails to compile in ChucK and fix it to schedule an event one second in the future. Then write the duration ‘120 milliseconds’ correctly.

“`dur` and `time` don't mix with bare numbers.** `now + 1` is a type error; `now + 1::second` is right. `120::ms` needs the `::` — `120 ms` doesn't parse.”
context/ · L1-instruments/chuck/gotchas.md · chunk 1