Next: , Previous: lib-trees, Up: The Prolog Library

10.41 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
| db_reference
| float
| float(rangeterm)
| ground
| integer
| integer(rangeterm)
| list
| list(Type)
| mutable
| nonvar
| number
| number(rangeterm)
| oneof(L)
| order
| pair
| pred_spec
| pred_spec_tree
| proper_list
| proper_list(Type)
| simple
| term
| var
| var_or(Type)

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

Culprit information:

These predicates takes arguments that are used when reporting the reason and location of errors. The arguments are:

must be a callable term, without (:)/2 module wrapping, with arity at least ArgNo.
must be a non-negative integer, where zero means no specific argument postition.
the term that has the offending value.

Exported predicates:

must_be(+Term, +Type, +Goal, +ArgNo)
checks whether the Term belongs to the indicated Type, which should be a typeterm. If it doesn't, several different error exceptions can be thrown: the Term may not be instantiated enough to tell yet (Instantiation Error); it may be instantiated when an unbound variable was expected (Uninstantiation Error); it may be definitely not of the right type (Type Error); it may be of the right type but not representable (Representation Error); or it may be of the right type but in the wrong domain (Domain Error). If an error exception is thrown, it will include Goal and ArgNo and, if possible, the line of code in the scope of which the error occurred. See ref-ere-err.
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.