Types

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

Some questions about types and type-checking:

The Euphoria manual says:

    "Even when you turn off type checking, Euphoria reserves the right
    to make checks at strategic places, since this can actually allow
    it to run your program faster in many cases. So you may still get
    a type check failure even when you have turned off type checking."

I would like some more specific information about this: I might need
to do some half-forbidden stuff.

Example 1:

    integer i

    without type_check
    i = 3.45       -- this will crash
    with type_check



Example 2:

    integer i

    without type_check
    i = {}        -- this won't work either
    with type_check



Example 3:

    sequence s

    without type_check
    s = 8        -- neither will this
    with type_check



Example 4:

    atom a

    without type_check
    a = {}        -- this works!!!!
    with type_check



Example 5:

    type my_integer(object x)
        return integer(x)
    end type

    type my_sequence(object x)
        return sequence(x)
    end type

    type my_constant(object x)
        return 0
    end type


    my_integer i
    my_sequence s
    my_constant c


    without type_check
    i = {}            -- works
    s = 8             -- works
    c = "qwertyuiop"  -- works
    with type_check


Question: Will the above examples always turn out the same way?
    (i e: when type-checking is turned off, variables declared as
     integers or sequences are always type-checked, while atoms and
      user-defined types are never checked)



-------
Another issue:

    "types

    These are special functions that may be used in declaring the
    allowed values for a variable. A type must have exactly one parameter
    and should return an atom that is either true (non-zero) or false
    (zero). Types can also be called just like other functions."


Question: Are these the ONLY differences?   (logically as well as
performanceically)
     i e: Could I, if I by some perverted reason wanted to do so, declare
     all my functions that take one argument and return integers, as types?
     As far as I understand, types have routine-id:s, and can have side-
     effects.

Just want to be really sure.
Thanks in advance

Martin Nilsson

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

Search



Quick Links

User menu

Not signed in.

Misc Menu