RE: Standard Euphoria Library Project

new topic     » goto parent     » topic index » view thread      » older message » newer message

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..

This brings up a Q i have.. what is faster.. storing the length of the 
seqeunce, or just using length()?

Chris

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu