Next: lib-ugraphs, Previous: lib-trees, Up: The Prolog Library [Contents][Index]
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 | |
| boolean | |
| 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.
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.