Re: Source changes

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

Juergen Luethje wrote:
> 
> Robert Craig wrote:
> 
> > Juergen Luethje wrote:
> 
> >> CChris wrote:
> >> 
> >>> A few hours ago, I checked in the changes related to value() and get(), so
> >>> that
> >>> they both return 4 element sequences. I didn't test the generated docs.
> >> 
> >> <snip>
> >> 
> >> Rob,
> >> 
> >> please do not put these changes into the next Euphoria release.
> > 
> > I can understand your concerns about keeping things
> > simple, but I'm not going to veto this change. I doubt that
> > it will cause much, if any, code to break.
> 
> Backwards compatibility is not my main concern. However, for the sake of
> completeness: The proposed change will cause code to break such as
> }}}
<eucode>
> if equal(value(s), {GET_SUCCESS,a}) then
> </eucode>
{{{


I understand your concern. However, because of the very nature of Euphoria's
sequence paradigm, Euphoria coders must never assume that the length of a
returned sequence will be anything specific. A better (?) coding for this
construct might be

if begins(value(s), {GET_SUCCESS,a}) then


(That reminds me, I should submit my begins()/ends() functions to the standard
library too. )

global function begins(sequence s, object b)
    if length(s) = 0 then
        return 0
    end if
    if atom(b) then
       return (s[1] = b)
    end if
    if length(b) = 0 then
       return 0
    end if
    if length(b) > length(s) then
       return 0
    end if
    return equal(s[1..length(b)], b)
end function

global function ends(sequence s, object b)
    if length(s) = 0 then
        return 0
    end if
    if atom(b) then
       return (s[$] = b)
    end if
    if length(b) = 0 then
       return 0
    end if
    if length(b) > length(s) then
       return 0
    end if
    return equal(s[length(s) - length(b) + 1 .. $], b)
end function


-- 
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell

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

Search



Quick Links

User menu

Not signed in.

Misc Menu