Hi Ben,

Thanks for your comments. There's another aspect of the syntax changes I am
playing with. The intention is to make more evident the relationship
between objects and closures as they could be implemented in terms of each
other (see below article from Vassily on the subject).

http://live.exept.de/doc/online/english/programming/humor.html


> Your ideas below regarding method definition is interesting, but this
> class definition seems problematic.
>
> > [Point: Object |
> > | x y |


I've removed passing the superclass as an argument, that was a mistake.
Now a more complete example would be written as:

[Generator: initialValue |
| currentValue |
currentValue := initialValue.
[reset | currentValue := 0 ].
[next |
currentValue := currentValue + 1.
^currentValue].
reset category: 'accessing'.
next category: 'accesing'.
].
myGen := Generator: 5.
myGen next = 6.
myGen reset = 0.
myGen next = 1.


To highlight that the blocks defining the methods wouldn't be thrown away,
I've added a couple of categorization methods.

Notice how close is that from a valid implementation using plain blocks in
regular Smalltalk. Almost identical if you ignore the method lookup
resolution which is obviously missing from blocks.

generatorClass := [:initialValue |
| currentValue |
currentValue := initialValue.
Array
with: [ currentValue := 0 ]
with: [ currentValue := currentValue + 1 ].
].

myGen := generatorClass value: 5.
myGen last value = 6.
myGen first value = 0.
myGen last value = 1.

Reply via email to