Skip to content

representation

tuprolog.solve.exception.error.representation

Representation errors: an implementation limit is exceeded, e.g. the maximum arity.

ISO Prolog's representation_error(Limit) error, thrown as error(representation_error(Limit), Extra), means that a value cannot be represented by the implementation, as it exceeds the limit Limit: e.g. functor(F, foo, N) with N greater than the max_arity flag throws representation_error(max_arity), and char_code(C, -1) throws representation_error(character_code).

The error is a RepresentationError, and the limits are the values of the Limit enumeration (also available as the LIMIT_* constants). Build errors with representation_error.

Examples:

>>> from tuprolog.solve.prolog import prolog_solver
>>> prolog_solver().solve_once("catch(char_code(C, -1), error(E, _), true)")["E"]
representation_error(character_code)
See Also

2P-Kt's documentation on errors and exceptions.

RepresentationError module-attribute

RepresentationError = _errors.RepresentationError

The representation error: a limit is exceeded, thrown as error(representation_error(Limit), _).

The JVM class (also a Python ValueError and a tuprolog.errors.PrologRepresentationError). Members (snake_case aliases as well): limit, the exceeded Limit; besides those of tuprolog.solve.exception.LogicError (e.g. type, error_struct, message).

Limit module-attribute

Limit = RepresentationError.Limit

The enumeration of the limits of representation errors (2P-Kt's RepresentationError.Limit).

Each value (also available as a LIMIT_* constant) is the Limit of a representation_error(Limit) term: to_term() gives it as an atom (e.g. max_arity), and limit as a string. Limit.of(name) and Limit.fromTerm(term) look a value up (see limit).

LIMIT_CHARACTER module-attribute

LIMIT_CHARACTER = Limit.CHARACTER

character: the exceeded limit is the set of characters.

LIMIT_CHARACTER_CODE module-attribute

LIMIT_CHARACTER_CODE = Limit.CHARACTER_CODE

character_code: the exceeded limit is the range of character codes (0 to 65535).

LIMIT_IN_CHARACTER_CODE module-attribute

LIMIT_IN_CHARACTER_CODE = Limit.IN_CHARACTER_CODE

in_character_code: the exceeded limit is the range of input character codes.

That is, character codes, or -1 for the end of file.

LIMIT_MAX_ARITY module-attribute

LIMIT_MAX_ARITY = Limit.MAX_ARITY

max_arity: the exceeded limit is the maximum arity of compound terms (the max_arity flag).

LIMIT_MAX_INTEGER module-attribute

LIMIT_MAX_INTEGER = Limit.MAX_INTEGER

max_integer: the exceeded limit is the greatest integer (the max_integer flag).

LIMIT_MIN_INTEGER module-attribute

LIMIT_MIN_INTEGER = Limit.MIN_INTEGER

min_integer: the exceeded limit is the least integer (the min_integer flag).

LIMIT_OOP_OBJECT module-attribute

LIMIT_OOP_OBJECT = Limit.OOP_OBJECT

oop_object: the exceeded limit is the objects a term can be converted into, through OOPLib.

See tuprolog.solve.libs.

LIMIT_TOO_MANY_VARIABLES module-attribute

LIMIT_TOO_MANY_VARIABLES = Limit.TOO_MANY_VARIABLES

too_many_variables: the exceeded limit is the number of variables a term may contain.

representation_error

representation_error(
    context: ExecutionContext,
    procedure: Signature,
    limit: Limit,
    cause: Any = None,
) -> RepresentationError

Creates a representation error.

Parameters:

Name Type Description Default
context ExecutionContext

the execution context in which the error occurs (e.g. a request's context).

required
procedure Signature

the signature of the predicate raising the error (e.g. a request's signature).

required
limit Limit

the exceeded limit (e.g. LIMIT_MAX_ARITY).

required
cause Any

the exception causing this one, if any.

None

Returns:

Type Description
RepresentationError

The error, thrown as error(representation_error(Limit), Message).

Examples:

>>> from tuprolog.solve import signature
>>> from tuprolog.solve.exception.error import *
>>> from tuprolog.solve.prolog import prolog_solver
>>> context = prolog_solver().current_context
>>> representation_error(context, signature("functor", 3), LIMIT_MAX_ARITY).type
representation_error(max_arity)

limit

limit(name: str | Term) -> Limit

The Limit named by a string or an atom.

Parameters:

Name Type Description Default
name str | Term

the name, as a string (case-insensitive) or a tuprolog.core.Term (as in the error terms, e.g. atom("max_arity")).

required

Returns:

Type Description
Limit

The matching Limit; None for terms other than atoms.

Raises:

Type Description
IllegalArgumentException

if no Limit has that name.

Examples:

>>> from tuprolog.solve.exception.error.representation import *
>>> limit("max_arity") == LIMIT_MAX_ARITY
True