[Newbies] Immutable environments in blocks?
bert at freudenbergs.de
Thu May 26 11:31:47 UTC 2011
On 25.05.2011, at 18:47, Jeff G wrote:
> Hi everyone,
> My question is about the semantics of block closures in squeak. I played around with scheme a bit in order to do some comparisons and one big question I have is how to alter the outer environment from a closure.
> An example of closure semantics given by Ian Piumarta on squeak-dev in 1999 is as follows.
> mkCounter := [:init ¦ [init := init + 1]].
> b1 := mkCounter value: 42.
> b1 value. 43
> b1 value. 44
You cannot assign into arguments anymore (in 1999, you could). So you need to make a temp:
mkCounter := [:init | | counter | counter := init. [counter := counter + 1]].
- Bert -
More information about the Beginners