You can check the type of the argument of a function (or anything else, for that matter) with the type command. For example, entering
will return
The output of a type command is actually an integer from 1 to 12. The output of type(4) is integer, which is a constant with the value 1. Another way to represent this type is with DOM_INT; entering
will return
Possible types (followed by the integer they represent) include:
If the item being tested is a list (in DOM_LIST), then the subtype command can determine what type of list it is. If the object is a sequence, then subtype returns 1;
returns
If the object is a set, then subtype returns 2. If the object is a polynomial represented as a list (see section 5.27), then subtype will return 10. If the object isn’t one of these types of list, then subtype returns 0.
The compare function will compare two objects taking their type into account; in other words, compare(a,b) returns 1 (true) if a and b have the same type with a less than b, or if a and b have different types and the integer type(a) is less than type(b). For example,
returns
since "a" and "b" have the same type (string) and "a" is less than "b" in the string ordering. Also, if b is a formal variable, then
returns
since the type of "a" is string (the integer 12) while the type of b is identifier (the integer 6) and 12 is not less than 6.
The getType command is similar to type in that it takes an object and returns the type, but it has different possible return values. It is included for compatibility reasons. For example,
returns
and
returns
Other possible return values include STR, EXPR, NONE, PIC, MAT and FUNC.