up previous next
CheckArgTypes

Check types in a list

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

Description
***** NOT YET IMPLEMENTED *****

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 nothing
  CheckArgTypes("MyFunc", [INT, POLY, IDEAL], [10, 20, ideal(x)]);
  -- the following returns an error for the 3rd argument
  CheckArgTypes("MyFunc", [INT, POLY, IDEAL], [10, 20, 30]);
ERROR: MyFunc: arg 3 is INT but must be IDEAL
CONTEXT: Return(S)
-------------------------------

  -- an example of use for type checking
  Define Power(F, N)
    CheckArgTypes("Power", [POLY, INT], [F, N]);
    Return F^N;
  EndDefine; -- Power
  Power(x, 3);
x^3
-------------------------------
  Power(2, 3);
8
-------------------------------
  Power(2, x);
ERROR: Power: arg 2 is POLY but must be INT
CONTEXT: Return(S)
-------------------------------