Re: Last Element Notation
- Posted by Robert Craig <rds at RapidEuphoria.com> Sep 17, 2003
- 487 views
Derek Parnell wrote: > Please, please, reconsider some syntax notational assistance for > accessing the last element in a sequence! OK. I know it's awkward sometimes. > The current piece I'm working on often needs to reference the last > element of a sequence, and often that is a deeply nested sequence. This > causes the program code to become VERY VERY *&%$ at &!* at ^ unreadable. Sure, > > I can write some neat routines that do this but I'm trying to avoid the > overhead (however bloody slight) of a routine call. > > > So that this ... > > FB_Content[lBuffer][lLine] = FB_Content[lBuffer][lLine][1..lCol-1] & > pText & > > FB_Content[lBuffer][lLine][lCol..length(FB_Content[lBuffer][lLine])] > > can become something like ... > > FB_Content[lBuffer][lLine] = FB_Content[lBuffer][lLine][1..lCol-1] & > pText & > FB_Content[lBuffer][lLine][lCol..$] Unless someone has a better idea, I think I'll go ahead with this idea of $ meaning "the index of the last element". e.g. s[1..$] s[1..$-1] s[$-2] etc. I've wanted to do something like this for quite a while, but I always had the feeling there might be a better way. > or even better, a couple of built-in routines... > > FB_Content[lBuffer][lLine] = insert(FB_Content[lBuffer][lLine], lCol, > pText) > > and to simplify the extremely common idiom of removing the last element... > > if equal(pText[i][$], '\n') then > pText[i] = remove_right(pText[i], 1) > end if > > instead of the hard-to-read ... > > if equal(pText[i][length(pText[i])], '\n') then > pText[i] = pText[i][1..length(pText[i])-1] > end if > > Its little things like this that make Euphoria so frustrating, when the > solution, from the point of view of your customers, is so simple. Please > help us. I'll add some sequence operations like this as routines in misc.e. I can use your recent contribution file as a guide. Thanks, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com