Foreach Range Statement

renoX renosky at free.fr
Mon Jul 23 15:05:13 PDT 2007


Bill Baxter a écrit :
>  I really like that 5..1:-1 syntax though!  Was 
> that mentioned before?  Something about all the colons in Pythons range 
> literals always makes me uneasy.  a:b:c -- is that a to c stepping by b? 
>  Or a to b stepping by c?  In Python it's the latter.  In Matlab I think 
> it's the former.  Which is probably why I always feel a little uneasy 
> when I see it.  But a..b:c is much clearer!  Obviously it's from a to b, 
> so c must be a step.  And the colon looking like the two dots stood on 
> end -- lovely.

Lovely, yes, that's the first time I see this syntax, it's nice, but I 
wonder if the 'step' part is so important that sugar syntax is needed 
for it.

In Ruby, they do the step part without sugar: 1..n.step(<step value>), 
the <step value> being optional with a default value of 1 (following a 
proposal of mine where they only took this part which was for me the 
least interesting point of the proposal *sigh*)

IMHO, it'd better to concentrate on the range syntax and to get a nice 
one for all the cases: closed range, open, half-open.

At one point I came with [<, [>, >], <] it's not very pretty but it's 
quite intuitive (at least for those who are used to math range, I bet 
that you guys can figure what means [<1, 5<] without I need to give 
explanations) it has a good visual effect I think and that contrary to 
just .. and ... it allows all the possibilities..


Regards,
renoX



More information about the Digitalmars-d mailing list