Aha! How to get rid of Blocks in Smalltalk.
Alan Knight
knight at acm.org
Sat Apr 22 17:56:42 UTC 2000
At 11:12 AM 4/22/00 +0000, Lex Spoon wrote:
>Ranjan Bagchi <ranjan.bagchi at frotz.com> wrote:
> > > Actually, you only really have to say:
> > >
> > > aCollection.do(new BlockLike() {
> > > int value(int each) {
> > > return each.doSomething();
> > > }
> > > });
> > >
> >
> > Maybe I'm missing something, but why is
> > aCollection do: [:each | each doSomething]
> > better?
> >
>
>It's one line instead of four, which means blocks are much more
>convenient to use in Smalltakl. They are also much simpler in
>Smalltalk, because you don't have to put all the surrounding static type
>information.
To make this "real" the Java example actually has to get longer and be
duplicated. To apply to multiple types we really need
aCollection.do(new BlockLikeForIntToInt() {
int value(int each) {
and a corresponding one for each pair of types
aCollection.do(new BlockLikeForARealClassToSomethingElse() {
RealClass value(SomethingElse each) {
If we really only need do: functionality then value can be uniformly void
and we only need an interface for each class (or a cast inside the
"block"), but that just brings us to #collect: functionality.
--
Alan Knight [|] knight at acm.org
WebGain, Inc. (613) 569-8855 (v) (613) 569-9418 (f)
"Never give up; and never, under any circumstances, no matter what -- never
face the facts"
- Ruth Gordon
More information about the Squeak-dev
mailing list
|