Previous: , Up: Types And Values   [Index]


4.3 Implicit Convertions

The aime interpreter will convert between types of similar nature or use when there is a type mismatch between the present and expected value.

Implicit convertions are only performed for function arguments and returns. No convertions are performed for operator arguments, references function arguments, etc.

Convertions are done between the numerical intrinsic types (‘cardinal’, ‘integer’ and ‘real’) and between the ‘object’ type and any other type.

See The Object Type.

For the:

integer abs(integer);
real exp(real);
integer min(integer, integer);
real pow(real, real);

functions, all the:

    abs(7.5)
    abs(8z)
    abs(exp(0))
    exp(-2)
    exp(0z)
    min(2.5, -2.5)
    min(3, 3z)
    pow(0, 2)
    pow(8z, -2)
    pow(17, -.5)

calls are allowed.

Functions like:

void l_push(list, integer,);
void __object(object);

may be called with arguments of any type:

    __object(0);
    __object("all mine");
    __object(sin(3));
    __object(__object);
    l_push(l, 0, 1001);
    l_push(l, 0, "ich");
    l_push(l, 0, l);
    l_push(l, 0, exp);

All the:

real
convert_1(void)
{
    return 2;
}
integer
convert_2(cardinal c)
{
    return c;
}
object
convert_3(void)
{
    return 4;
}
integer
convert_4(object o)
{
    return o;
}

function definitions are allowed. The ‘object’ to ‘integer’ convertion in ‘convert_4’ will fail at run time if o holds no ‘integer’ convertible data.

Many of the functions exported by aime libraries accompanying the interpreter will also convert between related types.

See Byte Data Converters.