[ Comparing and Sorting | Reference Manual | Alphabetic Index ]

local domain(++Def)

export domain(++Def)

Define a domain (a set of symbols mapped to natural numbers)
Def
A structure with atomic arguments.

Description

This defines a domain. A domain definition is a ground structure with atomic arguments. The structure's functor name is taken as the name of the domain. The domain name is used e.g. for declaring domain variables in lib(ic_symbolic).

The structure's arguments are the domain values. A domain value can be any atomic term (atom, string, number), but will usually be an atom. Domains are ordered, and the argument order in the defining structure implies the order of the domain values. The domain values are mapped to natural numbers, with the first argument being mapped to 1, the second to 2 and so on.

After having been defined, the mapping can be looked up via the primitives domain_index/3 and current_domain/3. Certain libraries (e.g. lib(ic_symbolic)) use the defined mapping internally.

Domain definitions can be local or exported. The domain values of all visible domain definitions within a module must be mutually exclusive, i.e. there must not be any ambiguity as to which domain a particular value belongs to. The system checks this condition whenever new domains are defined or imported.

Modes and Determinism

Exceptions

(4) instantiation fault
Def is not ground
(5) type error
Def is neither variable nor structure
(5) type error
A domain value is not atomic
(6) out of range
A domain value is not unique in this module
(87) attempt to redefine an existing local item
The domain name is already used locally
(88) attempt to redefine an existing exported item
The domain name is already used and exported
(89) attempt to redefine an already imported item
The domain name is already used by an imported domain

Examples

    :- local domain(colour(red,green,blue)).

    :- export domain(vowel(a,e,i,o,u)).

    :- local domain(abc(a,b,c)).
    Domain value a not unique in module eclipse
    out of range in local domain(abc(a, b, c))
    Abort

    ?- current_domain(Name, DefModule, Def).
    Name = colour
    DefModule = eclipse
    Def = colour(red, green, blue)
    More (0.00s cpu) ? ;

    Name = vowel
    DefModule = eclipse
    Def = vowel(a, e, i, o, u)
    More (0.00s cpu) ? ;

    No (0.00s cpu)

    ?- domain_index(blue, Domain, Index).
    Domain = eclipse : colour
    Index = 3
    Yes (0.00s cpu)

    ?- domain_index(o, Domain, Index).
    Domain = eclipse : vowel
    Index = 4
    Yes (0.00s cpu)

    ?- domain_index(yellow, Domain, Index).
    No (0.00s cpu)

See Also

local / 1, export / 1, current_domain / 3, domain_index / 3, library(ic_symbolic)