A counter! How? Aargh

I can’t believe I can’t figure this out :frowning: or even find the answer in the docs or on the forum…

All I want is a simple function (routine?) that counts from 0 to 7, incrementing each time it is called.

something like this?

~rout = Routine({


Thanks. Honestly, I’ve been reading the helpfile on Routine for about two hours now, it still makes no sense to me whatsoever! But, thanks, that’s it. Except mod(8) is what I meant.

And… hmm. Why does it always start from 3?

Two other similar approaches that don’t use routines.

~counter = (
   current_value: 0,
   get_next: { |self|
        self.current_value = self.current_value + 1;


~count_globally = {
	~count_globally_n = ~count_globally_n ? 0; 
	~count_globally_n = ~count_globally_n + 1;

1 Like
a = Pseq((0..7),inf).asStream; // could also be 1 repeat, of course

Thanks both. And… I can’t believe I didn’t think of the Pseq solution!


a = Pn(Pseries(0, 1, 8), inf).asStream;