[Fluxus] repeat

Kassen signal.automatique at gmail.com
Wed Feb 16 08:22:07 PST 2011


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pawfal.org/pipermail/fluxus-pawfal.org/attachments/20110216/de3bb19c/attachment-0001.htm>


More information about the Fluxus mailing list