Re: [racket] set! racket behaviour

2011-11-02 Thread jkaczorek
-Original Message- From: Dan Grossman To: David Vanderson CC: jkaczorek ; users Sent: Mon, 31 Oct 2011 21:25 Subject: Re: [racket] set! racket behaviour I also found it counterintuitive that #lang racket (define x 0) (set! x 1) works, but moving the set! out of the module and

Re: [racket] set! racket behaviour

2011-11-02 Thread jkaczorek
-Original Message- From: Dan Grossman To: David Vanderson CC: jkaczorek ; users Sent: Mon, 31 Oct 2011 21:25 Subject: Re: [racket] set! racket behaviour I also found it counterintuitive that #lang racket (define x 0) (set! x 1) works, but moving the set! out of the module

Re: [racket] set! racket behaviour

2011-10-31 Thread Dan Grossman
I also found it counterintuitive that #lang racket (define x 0) (set! x 1) works, but moving the set! out of the module and into the REPL does not. But Dave has pointed to the exact line in the Guide that makes this clear: A module-level definition is mutable only if there is a set! for it in th

Re: [racket] set! racket behaviour

2011-10-31 Thread Neil Van Dyke
Parameters are very useful. See: http://docs.racket-lang.org/reference/parameters.html Neil Van Dyke wrote at 10/31/2011 01:06 PM: jkaczo...@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 i

Re: [racket] set! racket behaviour

2011-10-31 Thread Neil Toronto
You could also make your intentions more explicit using #lang racket (define counter (box 0)) In the REPL, you would then do (set-box! counter (add1 (unbox counter))) Neil T On 10/31/2011 11:20 AM, David Vanderson wrote: I think you are running into the issue described here: http

Re: [racket] set! racket behaviour

2011-10-31 Thread Erich Rast
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, jkaczo...@aol.pl wrote: > Hi, > > I’m using DrRacket. > In an e

Re: [racket] set! racket behaviour

2011-10-31 Thread David Vanderson
I think you are running into the issue described here: http://docs.racket-lang.org/guide/module-set.html "Along the same lines, when a module contains no set! of a particular identifier tha

Re: [racket] set! racket behaviour

2011-10-31 Thread Neil Van Dyke
jkaczo...@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 th

[racket] set! racket behaviour

2011-10-31 Thread jkaczorek
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