jastrachan | 5 Apr 09:15 2004
Picon

Re: Some late thoughts on optionality...


On 4 Apr 2004, at 22:05, Rob Giardina wrote:
> Hi All,
>
> I feel a bit silly about this but a minor irritant in ruby is always 
> having to type the opening | in a {} param list. I was quite pleased 
> with groovy's single | before I saw it's conflict. In the end { |arg| 
> ... } isn't too bad but it strikes me that syntactic allegiance to 
> ruby/smalltalk isn't really necessary. I've thought of the following 
> that on first look, don't seem to have conflicts:

Though recently the {| item | ... } has come back as it was causing 
conflicts with the use of the | operator.

> today:
>   list.each_with_index { |item, i| println "${i}: ${item}" }
>
> some candidates:
>   list.each_with_index { item, i :: println "${i}: ${item}" }
>   list.each_with_index { item, i -> println "${i}: ${item}" }
>   list.each_with_index { item, i : println "${i}: ${item}" }
>   list.each_with_index { item, i  <at>  println "${i}: ${item}" }
>   list.each_with_index { item, i _ println "${i}: ${item}" }
>
> and of course:
>   list.each_with_index { item, i :) println "${i}: ${item}" }
>
> or, if you don't really like closures:
>   list.each_with_index { item, i :( println "${i}: ${item}" }

Actually I quite like the use of colon.

list.each { i : ... }

We're already using : as a separator for maps.

map = [ 1 : 2, 2 : 4, 3 : 6 ]

etc. So maybe using a single colon is more consistent? Chris - I wonder 
if it'd cause much parser ambiguity?

James
-------
http://radio.weblogs.com/0112098/

Gmane