[Q] Is a vertical bar necessary in block?
Reinier van Loon
R.L.J.M.W.van.Loon at inter.nl.net
Mon May 17 07:50:24 UTC 1999
>>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]
>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:
Well, I didn't want to require it. It was meant for documentation purposes
only. And I would continue the value:value: messages. But in this way blocks
can easily by converted to methods and vice versa.
Come to think of it: The value: and value:value: messages are probably the
reason why only colons are permitted. Otherwise we had to code something
like aCollection do: [ value: each | ... ].
No, I just want to extend the block parameter syntax for documentation
purposes and drop the vertical bar, something like this :
aCollection [ <optional name>: arg1 <optional name>: arg2 <code> ].
Reinier.
More information about the Squeak-dev
mailing list
|