[squeak-dev] Block argument syntax

Levente Uzonyi leves at elte.hu
Sat Mar 2 00:38:10 UTC 2013


On Fri, 1 Mar 2013, Yoshiki Ohshima wrote:

> On Fri, Mar 1, 2013 at 3:16 PM, Levente Uzonyi <leves at elte.hu> wrote:
>> On Fri, 1 Mar 2013, Yoshiki Ohshima wrote:
>>
>>> I believe I have seen Dan Ingalls posted about the syntax here
>>> before...  The essence of the message was that a block is still like a
>>> method, and they kind of have keyword message pattern, except that the
>>> keyword part is null (0-length) string.  In this regard, allowing
>>> spaces after a colon follows the principle.
>>
>>
>> That's pretty cool and exactly what I always thought about it, but I still
>> couldn't find a good reason for the | at the end of the block signature.
>> Without it blocks could be parsed just like methods, (probably) making the
>> parser simpler:
>>
>> array collect: [ :each
>>         each * each ]
>
> But a pair of vertical bars may follow the last argument name, so the
> parser would have to check it, no?

Of course, but it has to do that for methods too:

square: each

 	^each * each

vs

[ :each

 	each * each ]

and

square: each

 	| result |
 	result := each * each
 	^result

vs

[ :each

 	| result |
 	result := each * each.
 	result ]


Levente

>
> -- 
> -- Yoshiki
>
>


More information about the Squeak-dev mailing list