]> Repositorios git - scryer-prolog.git/commitdiff
ENHANCED: more efficient chars_si/1, using specialized predicates of Scryer
authorMarkus Triska <[email protected]>
Fri, 4 Aug 2023 19:18:00 +0000 (21:18 +0200)
committerMarkus Triska <[email protected]>
Fri, 4 Aug 2023 19:18:37 +0000 (21:18 +0200)
Source:

    https://github.com/mthom/scryer-prolog/issues/1947#issuecomment-1665113488

src/lib/si.pl

index 910cad5b54013e7669d74e540a695bb82fdff661..bdebc956da6085db6beb45ce3e249357264bd222 100644 (file)
@@ -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,