Merge pull request #1111 from triska/fast_list_test

Use '$skip_max_list'/4 for fast list tests in can_be/2 and must_be/2
This commit is contained in:
Mark Thom
2021-11-27 20:29:17 -05:00
committed by GitHub

View File

@@ -47,13 +47,13 @@ must_be_(integer, Term) :- check_(integer, integer, Term).
must_be_(atom, Term) :- check_(atom, atom, Term). must_be_(atom, Term) :- check_(atom, atom, Term).
must_be_(character, T) :- check_(error:character, character, T). must_be_(character, T) :- check_(error:character, character, T).
must_be_(chars, Ls) :- must_be_(chars, Ls) :-
( ground(Ls), '$is_partial_string'(Ls) -> must_be(list, Ls),
( '$is_partial_string'(Ls) ->
% The expected case (success) uses a very fast test. % The expected case (success) uses a very fast test.
% We cannot use partial_string/1 from library(iso_ext), % We cannot use partial_string/1 from library(iso_ext),
% because that library itself imports library(error). % because that library itself imports library(error).
true true
; must_be(list, Ls), ; all_characters(Ls)
all_characters(Ls)
). ).
must_be_(list, Term) :- check_(error:ilist, list, Term). must_be_(list, Term) :- check_(error:ilist, list, Term).
must_be_(type, Term) :- check_(error:type, type, Term). must_be_(type, Term) :- check_(error:type, type, Term).
@@ -79,9 +79,12 @@ character(C) :-
atom(C), atom(C),
atom_length(C, 1). atom_length(C, 1).
ilist(V) :- var(V), instantiation_error(must_be/2). ilist(Ls) :-
ilist([]). '$skip_max_list'(_, -1, Ls, Rs),
ilist([_|Ls]) :- ilist(Ls). ( var(Rs) ->
instantiation_error(must_be/2)
; Rs == []
).
type(type). type(type).
type(integer). type(integer).
@@ -120,10 +123,11 @@ can_(chars, Ls) :- '$is_partial_string'(Ls).
can_(list, Term) :- list_or_partial_list(Term). can_(list, Term) :- list_or_partial_list(Term).
can_(boolean, Term) :- boolean(Term). can_(boolean, Term) :- boolean(Term).
list_or_partial_list(Var) :- var(Var). list_or_partial_list(Ls) :-
list_or_partial_list([]). '$skip_max_list'(_, -1, Ls, Rs),
list_or_partial_list([_|Ls]) :- ( var(Rs) -> true
list_or_partial_list(Ls). ; Rs == []
).
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Shorthands for throwing ISO errors. Shorthands for throwing ISO errors.