From: Markus Triska Date: Fri, 26 Nov 2021 16:11:35 +0000 (+0100) Subject: ENHANCED: use '$skip_max_list'/4 for fast list tests in can_be/2 and must_be/2 X-Git-Tag: v0.9.0~22^2~1 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=6ba374c62baa43e56f8d56dbbf59d9952d502143;p=scryer-prolog.git ENHANCED: use '$skip_max_list'/4 for fast list tests in can_be/2 and must_be/2 This also (partially) addresses #1108. --- diff --git a/src/lib/error.pl b/src/lib/error.pl index d6bf8708..749ad04e 100644 --- a/src/lib/error.pl +++ b/src/lib/error.pl @@ -79,9 +79,12 @@ character(C) :- atom(C), atom_length(C, 1). -ilist(V) :- var(V), instantiation_error(must_be/2). -ilist([]). -ilist([_|Ls]) :- ilist(Ls). +ilist(Ls) :- + '$skip_max_list'(_, -1, Ls, Rs), + ( var(Rs) -> + instantiation_error(must_be/2) + ; Rs == [] + ). type(type). type(integer). @@ -120,10 +123,11 @@ can_(chars, Ls) :- '$is_partial_string'(Ls). can_(list, Term) :- list_or_partial_list(Term). can_(boolean, Term) :- boolean(Term). -list_or_partial_list(Var) :- var(Var). -list_or_partial_list([]). -list_or_partial_list([_|Ls]) :- - list_or_partial_list(Ls). +list_or_partial_list(Ls) :- + '$skip_max_list'(_, -1, Ls, Rs), + ( var(Rs) -> true + ; Rs == [] + ). /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Shorthands for throwing ISO errors.