home/ atoms/ sonicpi-tick-vs-look

In Sonic Pi, .tick mutates the ring counter while .look only reads it — calling .tick twice in one pass advances twice

.tick and .look are complementary accessors on Sonic Pi rings. .tick reads the current element and advances the counter by 1 (mutation). .look reads the current element without advancing the counter (non-destructive read). Calling .tick twice in a single pass reads two different elements, stepping through the ring twice. To read the same ring element in two different places in one pass, call .tick once and .look everywhere else. Ticks are keyed per live_loop and per named counter: notes.tick(:mel) and amps.tick(:amp) maintain independent counters even in the same loop.

Examples

notes = [:c4,:e4,:g4].ring\nlive_loop :mel do\n play notes.tick # advances counter\n play notes.look # reads same position\n sleep 1\nend

Assessment

Explain the bug in play notes.tick; with_fx :reverb do; play notes.tick; end; sleep 1 and rewrite it to play the same note with reverb without advancing the counter twice.

“*`.tick` mutates state; `.look` does not.**”
context/ · L1-instruments/sonicpi/gotchas.md · chunk 1
“**once** per counter per pass; read again with `.look`. Name independent ticks”
context/ · L5-debug/sonicpi.md · chunk 1