object

# type

> Type checking predicates. User extensible. New types can be defined by adding clauses for the type/1 and check/2 multifile predicates.

author:
  `Paulo Moura`
version:
  `1.0`
date:
  `2016/8/21`

compilation flags:
  `static, context_switching_calls, complements(restrict)`

(no dependencies on other files)

## Public interface

### type/1

> Table of defined types. A new type can be registered by defining a clause for this predicate and adding a clause for the check/2 multifile predicate.

compilation flags:
  `static, multifile`
template:
  `type(Type)`
mode – number of proofs:
  `type(?callable) – zero_or_more`

### valid/2

> True if the given term is of the specified type. Fails otherwise.

compilation flags:
  `static`
template:
  `valid(Type,Term)`
mode – number of proofs:
  `valid(@callable,@term) – zero_or_one`

### check/3

> True if the given term is of the specified type. Throws an error otherwise using the format error(Error, Context). For the possible values of Error see the check/2 predicate.

compilation flags:
  `static`
template:
  `check(Type,Term,Context)`
mode – number of proofs:
  `check(@callable,@term,@term) – one_or_error`

### check/2

> True if the given term is of the specified type. Throws an error otherwise. A new type can be added by defining a clause for this predicate and registering it by adding a clause for the type/1 multifile predicate.

compilation flags:
  `static, multifile`
template:
  `check(Type,Term)`
mode – number of proofs:
  `check(@callable,@term) – one_or_error`
exceptions:
  Term is not bound as required: `instantiation_error`
  Term is not of the specified type: `type_error(Type, Term)`
  Term is the of the correct type but not in the specified domain: `domain_error(Domain, Term)`
  Term is the of the correct type and domain but the resource it represents does not exist: `existence_error(Type, Term)`

## Protected interface

(none)

## Private predicates

(none)

## Operators

### (none)

## Remarks

Logtalk specific types
  {entity, object, protocol, category, entity_identifier, object_identifier, protocol_identifier, category_identifier, event}

Prolog module related types (when the backend compiler supports modules)
  {module, module_identifier}

Base types from Prolog
  {term, var, nonvar, atomic, atom, number, integer, float, compound, callable, ground}

Atom derived types
  {boolean, character}

Number derived types
  {positive_integer, negative_integer, non_positive_integer, non_negative_integer, byte, character_code}

List types (compound derived types)
  {list, partial_list, list_or_partial_list, list(Type)}

Other compound derived types
  {predicate_indicator, non_terminal_indicator, predicate_or_non_terminal_indicator, clause, clause_or_partial_clause, pair, pair(KeyType,ValueType), cyclic, acyclic}

Other types
  {between(Type,Lower,Upper), property(Type, LambdaExpression), one_of(Type, Set), var_or(Type)}

between(Type, Lower, Upper) type notes
  The type argument allows distinguishing between numbers and other types. It also allows choosing between mixed integer/float comparisons and strict float or integer comparisons. The term is type-checked before testing for interval membership.

boolean type notes
  The two value of this type are the atoms true and false.

character_code type notes
  This type takes into account Unicode support by the backend compiler. When Unicode is supported, it distinguishes between BMP and full support. When Unicode is not supported, it assumes a byte representation for characters.

property(Type, Lambda) type notes
  Verifies that Term satisfies a property described using a lambda expression of the form [Parameter]>>Goal. The lambda expression is applied in the context of "user". The term is type-checked before calling the goal.

one_of(Type, Set) type notes
  For checking if a given term is an element of a set. The set is represented using a list. The term is type-checked before testing for set membership.

order type notes
  The three possible values of this type are the single character atoms <, =, and >.

types(Types)
  Allows checking if a term is a valid value for one of the types in a list of types.

Caveats
  The type argument to the predicates is never itself type-checked for performance reasons.

Design choices
  The main predicates are valid/2 and check/3. These are defined using the predicate check/2. Defining clauses for check/2 instead of valid/2 gives the user full control of exception terms without requiring an additional predicate.

## See also

### (none)