up previous next
CheckArgTypes

Check types in a list

Syntax
CheckArgTypes(Ltype: LIST of TYPE, Larg: LIST)

Description
This function provides a basic type checking for user defined functions: it checks whether the types of the elements in the third argument, a list, correspond to the types in the second list. If so, it returns nothing, otherwise returns an error.

Example
/**/  -- the following returns an error for the 2nd argument (INT)
/**/  -- CheckArgTypes([RAT, RINGELEM, MAT], [2/3, 20, LexMat(3)]); --> ERROR
--> ERROR: Arg 2 is INT but must be RINGELEM

/**/  -- the following returns nothing
/**/  CheckArgTypes([RAT, [INT,RAT,RINGELEM], MAT], [2/3, 20, LexMat(3)]);

/**/  -- an example of use for type checking
/**/  Define Pow(F, N)
/**/    CheckArgTypes([[INT,RAT,RINGELEM,IDEAL,MAT], INT], [F, N]);
/**/    Return F^N;
/**/  EndDefine; -- Pow
/**/  Pow(x, 3);
x^3
/**/  -- Pow(2, x); --> !!! ERROR !!! as expected
--> ERROR: Arg 2 is RINGELEM but must be INT