Block Recursion

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

Block Recursion

Bob Williams
I read that Blocks in Squeak and Pharo, since it was derived from Squeak did not implement true block closures and would not support block recursion. On one count the statement was correct, but not on the other. I tried:

    | a f |
    a := 0.
    f := [ Transcript show: a. (a < 5)ifTrue:[a := a + 1. f value ] ].
    f value.
    a inspect.

A Workspace DoIt did not work in Squeak, it failed complaning that the block was being evaluated. In Pharo, it works but with the annoying modal dialog asking to run since f was not assigned a value. If blocks are to be used recursively, a better way must be found to flag but not stop execution.

This example points out that porting from Squeak to Pharo is fine, but the reverse might be questionable.

bw
Reply | Threaded
Open this post in threaded view
|

Re: Block Recursion

Clément Béra
Hello,

Closures were implemented in Squeak/Pharo according to the blue book, so they were not real closures, up to 2008. Then the VM and the compiler were changed to support real closures.

The code you showed should work both on latest Squeak and on latest Pharo fine. Old version of Squeak and/or Pharo may not work. Last time I tried, it worked on Squeak 4.5 and it works at least since Pharo 1.4.

About compiler warnings you can disable them in the setting browser. Then you won't have the modal dialog that you find annoying.

Regards.


2014-05-26 18:42 GMT+02:00 Bob Williams <[hidden email]>:
I read that Blocks in Squeak and Pharo, since it was derived from Squeak did not implement true block closures and would not support block recursion. On one count the statement was correct, but not on the other. I tried:

    | a f |
    a := 0.
    f := [ Transcript show: a. (a < 5)ifTrue:[a := a + 1. f value ] ].
    f value.
    a inspect.

A Workspace DoIt did not work in Squeak, it failed complaning that the block was being evaluated. In Pharo, it works but with the annoying modal dialog asking to run since f was not assigned a value. If blocks are to be used recursively, a better way must be found to flag but not stop execution.

This example points out that porting from Squeak to Pharo is fine, but the reverse might be questionable.

bw