hughperman / pure-lang

Automatically exported from code.google.com/p/pure-lang
0 stars 0 forks source link

Allow negative slicing indices #55

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
(0..3)!-1;
I wanted 3, but it throws an out_of_bounds exception.

I was hoping for:
x!(#x+n) if n<0;

I changed it in my prelude, but I think others might find it useful.

Original issue reported on code.google.com by ivxlc...@gmail.com on 21 Mar 2011 at 12:33

GoogleCodeExporter commented 8 years ago
I see why this is useful with numeric indices, but it's also problematic since 
it changes the semantics of the indexing operation. To be consistent, the 
slicing operation (!!) would have to be changed accordingly, which isn't really 
possible with the way arithmetic sequences i..j are defined right now. Last but 
not least, indexing is also used with non-numeric indices in Pure (e.g., 
records and dictionaries), so using -k to denote the kth last element of an 
aggregate is not always meaningful. Therefore I'm not really convinced that 
this is the right thing to do.

I'm setting this to "won't fix" for now, but I invite you to post your patch to 
the Pure mailing list so that we can discuss it there.

Original comment by aggraef@gmail.com on 29 Mar 2011 at 3:14