RE: Standard Euphoria Library Project

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

On 7 Feb 2001, at 10:54, Brian Broker wrote:

> 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)]

But this would crash for me, with that error about nothing being assigned to s
to get
the length of. I am using v2.2, the complete edition, according to Exw.

Kat




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

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

Search



Quick Links

User menu

Not signed in.

Misc Menu