[Grace-core] 0..(size-1) or 1..size

Andrew P. Black black at cs.pdx.edu
Tue Jul 5 00:37:46 PDT 2011


The answer (to me) is clearly 1 .. size.   That's how mathematicians index vectors and arrays, so it seems the natural default, and thus what one gets with a literal.

Naturally, the libraries will allow users to pick any specific lower and upper bounds that they want.

On 4 Jul 2011, at 4:21, James Noble wrote:

> So I needed to do this:
> 
> const l := ["ab","ac","ad","ae","af"] 
> 
> for (0..(l.size - 1)) do { i ->
>   print(i)
>   print (l.at(i))
> } 

Please don't do that.  Instead, do

l.withIndexDo{ i, elem -> 
	print i
	print elem
}

The array knows what it's bounds are; the programmer doesn't have to.
	
	Andrew


More information about the Grace-core mailing list