[racket] set! racket behaviour

From: Neil Van Dyke (neil at neilvandyke.org)
Date: Mon Oct 31 14:43:23 EDT 2011

Parameters are very useful.  See:
http://docs.racket-lang.org/reference/parameters.html


Neil Van Dyke wrote at 10/31/2011 01:06 PM:
> jkaczorek at aol.pl wrote at 10/31/2011 12:58 PM:
>> Of course, I realize, that redefinition of the variables is not good 
>> (functional) programming style but sometimes it's necessary. Is there 
>> a possibility of such modifications without changing language?
>
> You might wish to use a parameter, like in the example below.
>
>
> #lang racket
>
> (define current-counter (make-parameter 0))
>
> (current-counter)  ;==> 0
>
> (current-counter 42)
>
> (current-counter)  ;==> 42
>
> (current-counter (+ 1 (current-counter)))
>
> (current-counter)  ;==> 43
>
>
> In this example, I have named your variable to start with "current-", 
> just by convention to emphasize that a variable is a parameter, but 
> that's not actually necessary.
>

-- 
http://www.neilvandyke.org/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20111031/2665dc9d/attachment.html>

Posted on the users mailing list.