Dear list,
I was a bit tired of writing "for" loops for a single variable when I didn't
need the variable just to do something a few times. In that case Scheme's
"for" seems needlessly verbose. I'm also not that into recursion in that
case. So; I was missing ChucK's "repeat(n) { body }", which simply executes
"body" n times. Few people seem to use that in ChucK, but I blame that on it
being under-documented and non-traditional, not on a lack of usefulness.
So; I did this and added it to my .fluxus.scm;
(define-syntax-rule (repeat n f ...)
(for ((x (in-range 0 n))) f ... ))
While I was at it I also did this, which may or may not be good for
anything;
(define-syntax-rule (repeat/list n f ...)
(for/list ((x (in-range 0 n))) f ... ))
usage example;
;build 20 cubes
(repeat 20
(translate (vector 2 0 0))
(colour (rndvec))
(build-cube))
Hope that's useful to some.
Yours,
Kas.