[CM] scheme, s7
ralf at seid-online.de
Thu Apr 25 15:48:55 PDT 2013
On Thu, Apr 25, 2013 at 08:03:27PM +0000, James Hearon wrote:
> Having a devil of a time trying to figure out how to assign a variable and increment a counter in a loop or process. Easy enough in c, but really struggling to do this in scheme.
> (define counter 0)
> (define (bump-counter) (process repeat 5 do(set! counter (+ counter 1))))
> Something like that would be what I'm after. Tried using LET, also declaring LET or SET outside the process or a loop but still within the definition, and no joy there.
> Any help for the parenthetically challenged greatly appreciated.
> Regards,Jim Hearon
Sorry, I might not get what you are after.
(define counter 0)
Here, you create a binding (i.e. you create a "variable" and assign an initial value to it).
(process repeat 5 do(set! counter (+ counter 1))))
Here you create a function that, when called, will return whatever 'process' return, which is
most likely not what you want (since process will return an anonymous function). I guess you want
'bump-counter' to actually modify your counter.
(loop repeat 5 do (set! counter (+ counter 1))))
Should do the job. But maybe I don't understand your question.
HTH Ralf Mattes
> Cmdist mailing list
> Cmdist at ccrma.stanford.edu
More information about the Cmdist