Re: A question about certain language features
- Posted by Derek Parnell <ddparnell at bigpond.com> Mar 21, 2002
- 591 views
Karl, I'm thinking that a distinct token be placed in the slice notation that indicates end-of-sequence rather than omitting the end slice value. Maybe a "$" symbol. foo = "abcdefghij" a = foo[2..$] -- everything except the first element. a==> "bcdefgihj" b = foo[1..$-6] -- everything except the last 6 elements. b==>"abcd" c = foo[$-4..$-1] -- only the elements 6 thru 9. c==>"fghi" The problem with omission is that it you are never certain that the omission was deliberate or not. A specific symbol inserted is more rarely a mistake. Of course we don't need a special symbol to represent the beginning of a sequence because the value 1 suffices. The other nice slice extention is to allow a list of subslices in the notation: d = foo[1..3, $-2..$] d==> "abchij" but that might be stretching the friendship ------------ Derek. ----- Original Message ----- From: <kbochert at ix.netcom.com> To: "EUforum" <EUforum at topica.com> Sent: Friday, March 22, 2002 6:36 AM Subject: RE: A question about certain language features You wrote on 3/21/02 10:54:37 AM: >Karl, > > Consider this syntax for shorthand slicing. Your current syntax sort >of defeats the sequence bounds checking. > >seq[1..0] -- seq[1..length(seq)] >seq[1..0-1] -- seq[1..length(seq)-1] > >seq[1..1-1] -- {} (reverse slice) >seq[1..-1] -- index [-1] out of bounds > >integer index index=0 >seq[1..index] -- {} (reverse slice) > >'O' is explicit, it cannot be implied. If it is, the original EU rules >apply. > >I haven't thouroughly looked. Does your shorthand work if it's implied >with a variable? > > >Chris I handle 'foo[2..]' by expanding it textually. I think of it as a macro. when I see the '..' followed by a ']' or '-', I insert the text 'length(foo)' directly into the input stream. (Having previously saved the 'foo'). 'foo[2..]' causes the interpreter to actually see 'foo[2..length(foo)]' and 'foo[2..-(a*b)]' is seen as 'foo[2..length(foo)-(a*b)]' As a result, all the normal Euphoria processing is left intact. Thanks for the link Karl Bochert