[racket] set! racket behaviour

From: Erich Rast (erich at snafu.de)
Date: Mon Oct 31 13:24:07 EDT 2011

Doesn't really answer your question, but why not use something like this
instead:

(define inc
  (let ((counter 0))
    (lambda ()
      (set! counter (add1 counter))
      counter)))

Best,

Erich

On Mon, 2011-10-31 at 12:58 -0400, jkaczorek at aol.pl wrote:
> Hi,
> 
> I’m using DrRacket. 
> In an edit window I have written:
> 
> #lang racket
> (define counter 0)
> 
> I’m pressing “Run” button and next, in a command line, after running a
> command:
> 
> (set! counter (add1 counter))
> 
> I receive a message “set!: cannot modify a constant: counter”
> 
> The problem can be resolved by changing the language (Language/Choose
> language/R5RS and unchecking “Disallow redefinition of initial
> binding”) but I suppose that in this way I can lose an access to the
> racket libraries.
> 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?
> 
> Jerzy
> 
> _________________________________________________
>   For list-related administrative tasks:
>   http://lists.racket-lang.org/listinfo/users




Posted on the users mailing list.