### 25.2.5 Checking the type of the argument

The type command finds the type of its input.

- type takes one argument: arg, an object.
- type(arg) returns an integer indicating the type of arg.

  The integer is given as a constant symbol which is equal to the integer. The possible values are:

  - 1, equivalently real, double or DOM_FLOAT.
  - 2, equivalently integer or DOM_INT.
  - 4, equivalently complex or DOM_COMPLEX.
  - 6, equivalently identifier or DOM_IDENT.
  - 7, equivalently vector or DOM_LIST.
  - 8, equivalently expression or DOM_SYMBOLIC.
  - 10, equivalently rational or DOM_RAT.
  - 12, equivalently string or DOM_STRING.
  - 13, equivalently func or DOM_FUNC.

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.

- getType takes obj, an object.
- getType(obj) returns the type of obj, which in this case means one of: NUM, VAR, STR, EXPR, NONE, PIC, MAT or FUNC.

#### Examples

type(4)

integer |  |  |  |  |  |  |  |  |  |

type(3.1)==DOM_FLOAT

true |  |  |  |  |  |  |  |  |  |

getType(3.14)

NUM |  |  |  |  |  |  |  |  |  |

getType(x)

VAR |  |  |  |  |  |  |  |  |  |

#### Subtypes

Xcas has various types of lists; the subtype command can determine what kind of list it is.

- subtype takes L, a list (in DOM_LIST).
- subtype(L) returns an integer indicating what type of list L is.

  The possible values are:

  - 1 is L is a sequence.
  - 2 if L is a set.
  - 10 if L is a polynomial represented by a list (see Section 11.1).
  - 0 if L is not one of the above types of list.

#### Example

subtype(1,2,3)

1 |  |  |  |  |  |  |  |  |  |

#### Object comparison

The compare operator compares two objects taking their type into account.

- compare takes two arguments: a,b, two objects.
- compare(a,b) returns
  - 1 (true) if type(a)<type(b) or if type(a)=type(b) and a is less than b in the ordering of their type.
  - 0 (false) otherwise.

#### Examples

compare("a","b")

1 |  |  |  |  |  |  |  |  |  |

since "a" and "b" have the same type (string) and "a" is less than "b" in the string ordering.

If b is a formal variable:

compare("a",b)

0 |  |  |  |  |  |  |  |  |  |

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.