Re: Type-check behavior

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

> Maybe this is just me, but I think it's silly for Euphoria to do this...

Its not you. I have pointed this out several times in the past.
Unfortunately Robert never really responded with any arguments (other than: "I
believe you mentioned that before"), and Im still
lost as the reason why this works this way. (yeah, internally it makes sense, a
type check is just a function, but by declaring
it as a type you are able to declare variables with its name and have the
associated function as the check-value function)
Someday I'll just write a preproccesor to handle that stuff, or at least, I keep
telling myself.

type bug (sequence s)
    return length(s) = 3 and equal(bug[3],'G')
end type


? bug ("BUG")
-- prints 1

? bug ("BU")
-- crashes: short-circuiting, of all places, is not implemented here

? bug (1)
-- crashes: type check error ... (arrg.. I was *checking* the type)

type nobug (object s)
    if sequence (s) then
        if length(s) = 3 then
            return equal (s[3], 'G')
        else
            return 0
        end if
    else
        return 0
    end if
end type

Ralf N.
nieuwen at xs4all.nl
ralf_n at email.com

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

Search



Quick Links

User menu

Not signed in.

Misc Menu