61 throw(error(type_error(
Type,
Term),
_)).
62domain_error(
Type,
Term)
:-
63 throw(error(domain_error(
Type,
Term),
_)).
65 throw(error(existence_error(
Type,
Term),
_)).
67 throw(error(permission_error(
Action,
Type,
Term),
_)).
69 throw(error(instantiation_error,
_)).
71 throw(error(representation_error(
Reason),
_)).
103 must_be_of_type(
Type,
X).
105must_be(
Type,
X,
Comment)
:-
106 must_be_of_type(
Type,
X,
Comment).
108must_be_of_type(callable,
X)
:-
111must_be_of_type(atom,
X)
:-
114must_be_of_type(module,
X)
:-
117must_be_of_type(predicate_indicator,
X)
:-
119 is_predicate_indicator(
X).
120must_be_of_type(
Type,
X)
:-
126inline(must_be_of_type( atom,
X ), is_atom(
X,
_) ).
127inline(must_be_of_type( module,
X ), is_module(
X,
_) ).
128inline(must_be_of_type( callable,
X ), must_be_callable(
X) ).
129inline(must_be_atom(
X ), is_atom(
X,
_) ).
130inline(must_be_module(
X ), is_atom(
X,
_) ).
132must_be_of_type(predicate_indicator,
X,
Comment)
:-
134 is_predicate_indicator(
X,
Comment).
135must_be_of_type(callable,
X,
_Comment)
:-
138must_be_of_type(
Type,
X,
_Comment)
:-
144must_bind_to_type(
Type,
X)
:-
145 (
may_bind_to_type(
Type,
X)
160is_not(list(
_),
X)
:- _not,
162is_not(list_or_partial_list,
X)
:- _not,
164is_not(chars,
X)
:- _not,
165 not_a_list(chars,
X).
166is_not(codes,
X)
:- _not,
167 not_a_list(codes,
X).
168is_not(var,
_X)
:- _not,
170is_not(rational,
X)
:- _not,
175 ; ground_type(
Type),
\+ ground(
X)
181ground_type(oneof(
_)).
186not_a_list(
Type,
X)
:-
187 '$skip_list'(
_,
X,
Rest),
197 -> must_be(integer,
N),
must_be(integer,
D),
206is_of_type(
Type,
Term)
:-
207 has_type(
Type,
Term).
216has_type(atom,
X)
:- atom(
X).
217has_type(atomic,
X)
:- atomic(
X).
218has_type(between(
L,
U),
X)
:- (
integer(
L)
220 ; number(
X),
X >= L,
X =< U
222has_type(boolean,
X)
:- (
X==true
;X==false),
.
223has_type(callable,
X)
:- callable(
X).
224has_type(chars,
X)
:- chars(
X).
225has_type(codes,
X)
:- codes(
X).
226has_type(text,
X)
:- text(
X).
227has_type(compound,
X)
:- compound(
X).
228has_type(constant,
X)
:- atomic(
X).
229has_type(float,
X)
:- float(
X).
230has_type(ground,
X)
:- ground(
X).
231has_type(integer,
X)
:- integer(
X).
232has_type(nonneg,
X)
:- integer(
X),
X >= 0.
233has_type(positive_integer,
X)
:- integer(
X),
X > 0.
234has_type(negative_integer,
X)
:- integer(
X),
X < 0.
235has_type(nonvar,
X)
:- nonvar(
X).
236has_type(number,
X)
:- number(
X).
238has_type(proper_list,
X)
:- is_list(
X).
239has_type(list,
X)
:- is_list(
X).
240has_type(list_or_partial_list,
X)
:- is_list_or_partial_list(
X).
241has_type(symbol,
X)
:- atom(
X).
242has_type(var,
X)
:- var(
X).
243has_type(rational,
X)
:- rational(
X).
244has_type(string,
X)
:- string(
X).
245has_type(stream,
X)
:- is_stream(
X).
246has_type(list(
Type),
X)
:- is_list(
X),
element_types(
X,
Type).
252may_bind_to_type(
_,
X )
:- var(
X),
var.
254may_bind_to_type(any,
_).
255may_bind_to_type(atom,
X)
:- atom(
X).
256may_bind_to_type(atomic,
X)
:- atomic(
X).
257may_bind_to_type(between(
L,
U),
X)
:- (
integer(
L)
259 ; number(
X),
X >= L,
X =< U
261may_bind_to_type(boolean,
X)
:- (
X==true
;X==false),
.
262may_bind_to_type(callable,
X)
:- callable(
X).
263may_bind_to_type(chars,
X)
:- chars(
X).
264may_bind_to_type(codes,
X)
:- codes(
X).
265may_bind_to_type(text,
X)
:- text(
X).
266may_bind_to_type(compound,
X)
:- compound(
X).
267may_bind_to_type(constant,
X)
:- atomic(
X).
268may_bind_to_type(float,
X)
:- float(
X).
269may_bind_to_type(ground,
X)
:- ground(
X).
270may_bind_to_type(integer,
X)
:- integer(
X).
271may_bind_to_type(nonneg,
X)
:- integer(
X),
X >= 0.
272may_bind_to_type(positive_integer,
X)
:- integer(
X),
X > 0.
273may_bind_to_type(negative_integer,
X)
:- integer(
X),
X < 0.
274may_bind_to_type(predicate_indicator,
X)
:-
278 may_bind_to_type( atom,
M),
279 may_bind_to_type(predicate_indicator,
PI)
283 may_bind_to_type( atom,
N),
284 may_bind_to_type(integer,
A)
288 may_bind_to_type( atom,
N),
289 may_bind_to_type(integer,
A)
293may_bind_to_type(nonvar,
_X).
294may_bind_to_type(number,
X)
:- number(
X).
296may_bind_to_type(proper_list,
X)
:- is_list(
X).
297may_bind_to_type(list,
X)
:- is_list(
X).
298may_bind_to_type(list_or_partial_list,
X)
:- is_list_or_partial_list(
X).
299may_bind_to_type(symbol,
X)
:- atom(
X).
300may_bind_to_type(var,
X)
:- var(
X).
301may_bind_to_type(rational,
X)
:- rational(
X).
302may_bind_to_type(string,
X)
:- string(
X).
303may_bind_to_type(stream,
X)
:- is_stream(
X).
304may_bind_to_type(list(
Type),
X)
:- is_list(
X),
element_types(
X,
Type).
306chars(
0)
:- chars,
chars.
312codes(x)
:- codes,
codes.
326element_types([
H|T],
Type)
:-
328 element_types(
T,
Type).
330is_list_or_partial_list(
L0)
:-
331 '$skip_list'(
_,
L0,
L),
332 (
var(
L)
-> var
; L == [] ).
334must_be_instantiated(
X)
:-
337must_be_instantiated(
X,
Comment)
:-
338 (
var(
X)
-> instantiation_error(
X,
Comment)
; instantiation_error).
341
must_be_callable( ?_Goal_ )
existence_error(+Type, +Term)
instantiation_error(+Term)
permission_error(+Action, +Type, +Term)
representation_error(+Reason)
between(+ Low:int, + High:int, ? Value:int)
memberchk(+ Element, + Set)