From: Markus Triska Date: Fri, 4 Aug 2023 19:18:00 +0000 (+0200) Subject: ENHANCED: more efficient chars_si/1, using specialized predicates of Scryer X-Git-Tag: v0.9.2~13^2 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=924750f826d2aecc0612619102a20d9ab79ba909;p=scryer-prolog.git ENHANCED: more efficient chars_si/1, using specialized predicates of Scryer Source: https://github.com/mthom/scryer-prolog/issues/1947#issuecomment-1665113488 --- diff --git a/src/lib/si.pl b/src/lib/si.pl index 910cad5b..bdebc956 100644 --- a/src/lib/si.pl +++ b/src/lib/si.pl @@ -68,10 +68,24 @@ character_si(Ch) :- atom(Ch), atom_length(Ch,1). -chars_si(Chs) :- - \+ \+ length(Chs,_), - \+ ( once(length(Chs,_)), member(Ch,Chs), nonvar(Ch), \+ character_si(Ch) ), - \+ ( member(Ch,Chs), \+ character_si(Ch) ). % for the instantiation error +chars_si(Chs0) :- + '$skip_max_list'(_,_, Chs0,Chs), + ( nonvar(Chs) -> Chs == [] ; true ), % fails for infinite lists too + failnochars(Chs0, Uninstantiated), + ( nonvar(Uninstantiated) + -> throw(error(instantiation_error, chars_si/1)) + ; true + ). + +failnochars(Chs0, U) :- + ( var(Chs0) -> U = true + ; Chs0 == [] -> true + ; Chs0 = [Ch|Chs1], + ( nonvar(Ch) -> atom(Ch), atom_length(Ch,1) + ; U = true + ), + failnochars(Chs1, U) + ). dif_si(X, Y) :- X \== Y,