RE: Standard Euphoria Library Project
- Posted by Kat <gertie at PELL.NET> Feb 07, 2001
- 403 views
On 7 Feb 2001, at 5:06, Chris Bensler wrote: > > David Cuny wrote: > > <SNIP> > > function remove( integer i, sequence s) > > -- remove ith element from s > > return s[1..i-1] & s[i+1..length(s)] > > end function > <SNIP> > > What if the user tries to remove the first or last item? > i would end up being 0 or greater than the length of the sequence.. > > Yeah you could say that it is up to the user to determine that, but if > it's going to be in a StdLib, it should be fool proof and robust.. > > I use this.. > > function splice(sequence s, integer i) > if i=1 then return s[2..length(s)] > elsif i=length(s) then return s[1..i-1] > else return s[1..i-1] & s[i+1..length(s)] > end function > > any value passed to i will be handled.. if i is out of bounds, than EU > will catch it.. What if the passed sequence is "" ? > This brings up a Q i have.. what is faster.. storing the length of the > seqeunce, or just using length()? I think Robert said getting the length of the seq is as fast as getting the first element of the seq. The seq attribute data is stored, such as the length is stored in a basic string as the [0] byte. Kat