[Q] Is a vertical bar necessary in block?

Bob Arning arning at charm.net
Sat May 15 22:02:07 UTC 1999


On Sat, 15 May 1999 14:12:45 +0200 "Reinier van Loon" <R.L.J.M.W.van.Loon at inter.nl.net> wrote: 
>My second question is: Why not name the arguments in a block?
>Okay, might be a bit of overkill, but why not? It's much closer to the
>method syntax and there's one less rule to learn.
>E.g.
>
>( 1 to: 10 ) inject: 0 into:
>
>    previous: total current: each        "named block arguments"
>        total := total + each.
>].

I'm not sure if it is really possible to reduce the number of rules here. One of the strengths of the current standard is that blocks with the same number of arguments are equivalent in a polymorphic sense. Thus to write

	aCollection do: [ :person | person saySomething]

I do not need to know by what name aCollection is planning on referring to the single argument to my block. And I certainly don't need to worry whether aCollection could be of some class (possibly unknown when I write my method) that uses an argument name different from all other implementations. 

So, if names were required, we might find ourselves in an impossibly complex web of dependencies between the producers and consumers of blocks that might, ultimately, be resolved only by adding another rule:

"The first argument in any block shall be named argument1. The second shall be named argument2. Etc..."

If, on the other hand, names were optional, we would have added a rule (2nd legal style for blocks) rather than removing one. We would also have enabled the not so pretty picture of a named block being sent the value:value:-style message and the even nastier case of a block without names being sent messages of the named variety.

I guess I remain unconvinced on this one.

Cheers,
Bob





More information about the Squeak-dev mailing list