[CM] scheme, s7

Ralf Mattes 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:
> Hi,
> 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))))
> (bump-counter)
> 
> 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).

  (define (bump-counter)  
    (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.

  (define (bump-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
> http://ccrma-mail.stanford.edu/mailman/listinfo/cmdist



More information about the Cmdist mailing list