On Oct 28, 2013, at 11:00 PM, Nick Coghlan wrote:
In this vein, I started wondering if it might be worth trying to come up with a syntax to control whether the ends of a slice were open or closed.
Since mismatched paren types would be too confusing, perhaps abusing some binary operators as Chris suggested could help:
"[<i:" closed start of slice (default) "[i<:" open start of slice ":>j]" open end of slice (default) ":j>]" closed end of slice ":>j:k]" open end of slice with step ":j>:k]" closed end of slice with step
Default slice: "[<0:-1>:1]" Reversed slice: "[<-1:0>:-1]"
This makes it possible to cleanly include the final element as a closed range, rather than needing to add or subtract 1 (and avoids the zero trap when indexing from the end).
Sorry, I'm -1 here. I think it's already difficult enough to teach, read, and comprehend what's going on with slice notation when there are strides (especially negative ones). I don't think this syntax will make it easier to understand at a glance (or even upon some deeper inspection). -Barry