Re: Is subscripting a slice useful
- Posted by Derek Parnell <ddparnell at bigpond.com> Oct 14, 2004
- 552 views
Pete Lomax wrote: [snip] > This is all possible, but you should at least by now understand why > *I* don't consider it an improvement to the lovely, elegant language > we all know and love. > > If the majority want this, so be it, I've had my say. I must agree with Pete (a rare thing I suspect). The concept of 'vertical' slicing needs a new syntax altogether, if we need to have it at all in the language. Currently the "[n..m]" notation in an expression is saying ... "create a new sequence, and build it from elements 'n' to 'm' inclusively" But vertical slicing implies that we don't want to use all of each element but just a subset of each element. So the difference in semantics (sub-element verses full element) needs to be reflected in the syntax. Something like "[n..m : x..y]" maybe. This is saying - build a new sequence from elements 'n' to 'm', but for each element just use sub-elements 'x' to 'y'. In other words, the syntax "[n..m]" could be thought of as shorthand for "[n..m:1..$]" A = { {1,2,3}, {4,5,6}, {7,8,9}, {10,11,12} } Thus A[2..3 : 2] would give {5,8} and A[2..3 : 2..3] would give {{5,6}, {8,9}} -- Derek Parnell Melbourne, Australia