RE: Standard Euphoria Library Project
FYI: this is straight out of our friendly refman doc:
You can delete element i of any sequence s by concatenating the parts of
the sequence before and after i:
s = s[1..i-1] & s[i+1..length(s)]
This works even when i is 1 or length(s), since s[1..0] is a legal empty
slice, and so is s[length(s)+1..length(s)].
(see sections 2.2.6 and 2.2.7)
-- Brian
Chris Bensler wrote:
> DOH!!
> Don't think I actually ever TRIED to see if it works or not before!!
>
> To me it just seems irrational that it WOULD work.. it's an invalid
> subscript..
>
> But to my amazement it does!!
>
> Foolish me..
>
> Chris {;oP DUH!
>
> Chris Bensler wrote:
> > You shouldn't be allowed to try and access an out of bounds subscript..
> > It may not crash, but why would you want it to do that? IMHO, it should
> > crash.. that's what error checking is for..
> >
> > Chris
> >
> > Fam. Nieuwenhuijsen 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..
> > >
> > > Yes, *but* Euphoria won't crash. When you slice from one above the
> > > length of
> > > the sequence or when you slice to zero it will return an empty seq
> > > rather
> > > than crash.
> > >
> > > Come on people. This is trivial beginners stuff.
> > >
> > > Ralf N.
> > > nieuwen at xs4all.nl
|
Not Categorized, Please Help
|
|