[racket] set! racket behaviour

From: Neil Van Dyke (neil at neilvandyke.org)
Date: Mon Oct 31 13:06:16 EDT 2011

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/d7506964/attachment.html>

Posted on the users mailing list.