RE: Is subscripting a slice useful
- Posted by Chris Bensler <bensler at nt.net> Oct 14, 2004
- 430 views
Derek Parnell wrote: > > > posted by: Derek Parnell <ddparnell at bigpond.com> > > 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 Readability is more important than compactness of code. I agree that implementing vertical slicing in that manor would be significantly detrimental to the readability of euphoria source code. I would like to see a restricted form of vertical slicing though. The restriction would be that there can be no more than one slice in any given reference. s[1..$][x] , or s[x][1..$][y][z] would be ok but not s[1..$][1..3][x] Sure it might be convenient, but it becomes more trouble to decipher it, than it is to just write it out the hard way in the first place. Granted that former example is quite simple, but there would have to be a limit, and the most logical limit is 1. Eu's limit is already 1. Chris Bensler Code is Alchemy