Checking the type of the argument: type subtype compare getType

### 12.2.5 Checking the type of the argument: type subtype compare getType

The type command finds the type of its input.

- type takes one argument: arg.
- 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.

#### Examples.

- Input:
  type(4)
  Output:
  integer
- Input:
  type(3.1) == DOM_FLOAT
  Output:
  true

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

- subtype takes one argument:
  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 5.27).
  - 0 if L isn’t one of the above types of list.

#### Example.

Input:

subtype(1,2,3)

Output:

1

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.

- Input:
  compare("a","b")
  Output:

  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:
  Input:
  compare("a",b)
  Output:

  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.

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 one argument:
  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.

- Input:
  getType(3.14)
  Output:
  NUM
- Input:
  getType(x)
  Output:
  VAR