A.16 library(error): Error generating support
All Application Manual Name SummaryHelp

  • Documentation
    • Reference manual
      • The SWI-Prolog library
        • library(error): Error generating support
          • type_error/2
          • domain_error/2
          • existence_error/2
          • existence_error/3
          • permission_error/3
          • instantiation_error/1
          • uninstantiation_error/1
          • representation_error/1
          • syntax_error/1
          • resource_error/1
          • must_be/2
          • is_of_type/2
          • has_type/2
          • current_encoding/1
          • current_type/3
    • Packages
Availability::- use_module(library(error)).(can be autoloaded)
Source[det]must_be(+Type, @Term)
True if Term satisfies the type constraints for Type. Defined types are atom, atomic, between, boolean, callable, chars, codes, text, compound, constant, float, integer, nonneg, positive_integer, negative_integer, nonvar, number, oneof, list, list_or_partial_list, symbol, var, rational, encoding, dict and string.

Most of these types are defined by an arity-1 built-in predicate of the same name. Below is a brief definition of the other types.

acyclicAcyclic term (tree); see acyclic_term/1
anyany term
between(FloatL,FloatU) Number [FloatL..FloatU]
between(IntL,IntU) Integer [IntL..IntU]
booleanOne of true or false
callableAtom or compound term
charAtom of length 1
charsProper list of 1-character atoms
codeRepresentation Unicode code point (0..0x10ffff)
codesProper list of Unicode character codes
compoundcompound term
compound(Term) Compound with same name/arity as term; checks arguments
constantSame as atomic
cyclicCyclic term (rational tree); see cyclic_term/1
dictA dictionary term; see is_dict/1
encodingValid name for a character encoding; see current_encoding/1
listA (non-open) list; see is_list/1
list(Type) Proper list with elements of Type
list_or_partial_listA list or an open list (ending in a variable); see is_list_or_partial_list/1
negative_integerInteger < 0
nonnegInteger >= 0
oneof(L) Ground term that is member of L
pairKey-Value pair. Same as compound(any-any)
positive_integerInteger > 0
proper_listSame as list
streamA stream name or valid stream handle; see is_stream/1
symbolSame as atom
textOne of atom, string, chars or codes
typeTerm is a valid type specification

In addition, types may be composed using TypeA,TypeB, TypeA;TypeB and negated using \Type.

Errors
instantiation_error if Term is insufficiently instantiated and type_error(Type, Term) if Term is not of Type.