10.28 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)
| nonvar
| number
| number(rangeterm)
| oneof(L)
| mutable
| pair
| pred_spec
| pred_spec_tree
| 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 doesn'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. If an error is raised, Goal and ArgNo will be used in the error exception.
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.
var
An Instantiation error is raised.
type(ErrorType)
Same as must_be(Culprit, ErrorType, Goal, ArgNo).
domain(ErrorType,ErrorDomain)
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.
force_type(ExpType)
A Type Error is raised.
context(ContextType,CommandType)
A Context Error is raised.
existence(ObjType,Culprit,Message)
An Existence Error is raised.
permission(Operation,ObjType,Message)
A Permission Error is raised.
representation(ErrorType)
A Representation Error is raised.
evaluation(ErrorType)
An Evaluation Error is raised.
consistency(Culprit1,Culprit2,Message)
A Consistency Error is raised.
syntax(Pos,Msg,Tokens,AfterError)
A Syntax Error is raised.
resource(Resource)
A Resource Error is raised.
system(Message)
A System Error is raised.

Send feedback on this subject.