10.27 Type Checking—library(types)

This library module provides more and better type tests. For the purposes of this library, we first define an abstract type typeterm, as follows:

typeterm ::= atom
| atomic
| callable
| character
| character_code
| compound
| float
| float(rangeterm)
| ground
| integer
| integer(rangeterm)
| list
| list(Type)
| nonvar
| number
| number(rangeterm)
| oneof(L)
| pair
| proper_list
| proper_list(Type)
| simple
| term
| var

rangeterm ::= between(L,U)
| >=(L)
| >(L)
| =\=(L)

Exported predicates:

must_be(+Term, +Type, +Goal, +ArgNo)
checks whether the Term belongs to the indicated Type, which should be a typeterm. If it isn't, there are two cases: the Term may not be instantiated enough to tell yet, in which case an Instantiation Error will be raised, or the Term may be definitely not of the type, in which case a Type Error is raised. You should use this in commands with side effects, and should arrange that if this predicate does not succeed the side effect(s) will not take place. If an exception is raised, it will pinpoint the line of code in the scope of which the error occurs, if possible.
illarg(+ErrorTerm, +Goal, +ArgNo)
illarg(+ErrorTerm, +Goal, +ArgNo, +Culprit)
is the way to raise an error exception, if you would like the exception to pinpoint the line of code in the scope of which the error occurs. This is especially useful in the context of source-linked debugging. Culprit defaults to argument number ArgNo of Goal. These three arguments are passed to the exception being raised, if appropriate. ErrorTerm should be one of the following. See ref-ere-err.
An Instantiation error is raised.
Same as must_be(Culprit, ErrorType, Goal, ArgNo).
First, the type is checked by must_be(Culprit, ErrorType, Goal, ArgNo). If the type is valid, a Domain Error is raised with the expected domain being ErrorDomain.
A Type Error is raised.
A Context Error is raised.
An Existence Error is raised.
A Permission Error is raised.
A Representation Error is raised.
An Evaluation Error is raised.
A Consistency Error is raised.
A Syntax Error is raised.
A Resource Error is raised.
A System Error is raised.

Send feedback on this subject.