Immutable environments in blocks?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Immutable environments in blocks?

Jeff Gonis

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

I never get 44 returned from the current squeak trunk.  I only ever get 43, which suggests to me that the assignment to init in the inner block is not actually ever over writing the init value in the outer environment.  How would I go about altering the outer environment from inside a block if I desired to do so?

Thanks for all your help,
Jeff G.


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Immutable environments in blocks?

Bert Freudenberg

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 -


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Immutable environments in blocks?

Jeff Gonis

Thanks a ton Bert, I really appreciate your help.

On 2011-05-26 5:31 AM, "Bert Freudenberg" <[hidden email]> wrote:


On 25.05.2011, at 18:47, Jeff G wrote:

> Hi everyone,
>
> My question is about the semantics of b...

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 -


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners