Re: Re: What's new in 2.5?

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

Christian Cuvier wrote:
> I regularly wind out writing:
> if equal(seq[i..j],sth) then...
> but j may fall off bounds, and the statement is obviously not true. Out of 
> frustration, I now peruse
> 
> }}}
<eucode>
> function Equal(sequence s,integer i,integer j,sequence x)
> integer l l=length(x)
> if i<1 or j<1 or j+l>length(s) then return 0
> else return equal(s[i..j],x)
> end if
> end function
> </eucode>
{{{

> 
> No crash now, but does double duty with the interpreter. And I have to never 
> forget to use it rather than simpler code that will likely fail.
> See how "ifx s[i..j]=x then..." would help?

This gives me an idea for a new feature for Euphoria 2.6 (adding it to 2.5 would
probably require too much time to implement and test right now):
a soft-slice operator: it works just like the normal slice operator, but doesn't
throw an error. Instead, it tries to return a slice that is as close as possible.
Example:
sequence s1, s2
s1 = "This is a very long string."
s2 = s1[11...1000] -- soft slice
-- s2 should now be: "very long string"


That would solve your Equal-problem.

--
tommy online: http://users.telenet.be/tommycarlier
Euphoria Message Board: http://uboard.proboards32.com

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

Search



Quick Links

User menu

Not signed in.

Misc Menu