Lambda the Ultimate

inactiveTopic New Block Closures in Squeak
started 1/22/2002; 5:55:49 AM - last post 1/23/2002; 10:50:56 AM
Ehud Lamm - New Block Closures in Squeak  blueArrow
1/22/2002; 5:55:49 AM (reads: 1926, responses: 3)
New Block Closures in Squeak
Block closure is when blocks have their own state separate from their creating context and can be invoked more than once at the same time.

Over on the Squeak wiki. The page includes a brief explanation of some implementation details.

More on the semantics.


Posted to implementation by Ehud Lamm on 1/22/02; 5:56:40 AM

Chris Rathman - Re: New Block Closures in Squeak  blueArrow
1/23/2002; 7:22:55 AM (reads: 816, responses: 1)
Couple of years ago, I found a code snippet on the Squeak Mailing list that presented kind of worst case scenario for ST block closures.

| blockArray dataArray |
   blockArray := Array new: 5.
   dataArray := #( 'Apple' 'Orange' 'Grape' 'Lemon' 'Kiwi').
   1 to: blockArray size do: [ :index |
      blockArray
         at: index
         put: [ dataArray at: index ] ].
^ (blockArray at: 2) value

The results of the various ST VM's were given as:

   Dolphin : Subscript out of bounds error (Array>>at:) 
   Smalltalk Express : primitive fails in Arrat>>at:VSE 3.1 : anwers 'Orange' 
   VisualWorks 2.5.1 : answers 'Orange' 
   VisualWorks Non-Commercial 3.0 : answers 'Orange' 
   VisualWorks Beta 5i : raises a SubscriptOutOfBoundsSignal in Core::Array>>at: 
VisualAge for Smalltalk 4.5 : answers 'Kiwi'

I would think that the answer should be Orange, as the value of the index at each code block is latched at the time it is created. Guess I need to try it on this version of Squeak, as it errored out on the earlier versions of Squeak that didn't have closures. :-)

rev - Re: New Block Closures in Squeak  blueArrow
1/23/2002; 10:50:56 AM (reads: 795, responses: 0)
The big thing about this isn't only the properness of having real block closures, it's also quite a bit faster than the stock VM! On the Squeak-dev list, people have been reporting 33% faster using the "0 tinyBenchmarks" bytecode benchmarks. When I ran them, they were about the same as on the stock VM, but morphic *felt* quite a bit faster. This is quite a bit leap of speed for Squeak!

Mark Hulme-Jones - Re: New Block Closures in Squeak  blueArrow
1/25/2002; 11:07:51 AM (reads: 824, responses: 0)
I've given this a try. It causes an exception...