]> Repositorios git - scryer-prolog.git/commitdiff
restore deleted parts of number_chars/2 and number_codes/2 (#721)
authorMark Thom <[email protected]>
Thu, 18 Mar 2021 02:23:58 +0000 (20:23 -0600)
committerMark Thom <[email protected]>
Thu, 18 Mar 2021 02:23:58 +0000 (20:23 -0600)
src/lib/builtins.pl

index 0bb64f33414dc4b631dc3973d29b4c7118e07d54..983612c88888d5017c8b94d8804b0633b7ceddc1 100644 (file)
@@ -1336,6 +1336,39 @@ must_be_number(N, PI) :-
     ;  throw(error(instantiation_error, PI))
     ).
 
+can_be_chars_or_vars(Cs, _) :- var(Cs), !.
+can_be_chars_or_vars(Cs, PI) :- chars_or_vars(Cs, PI).
+
+chars_or_vars([], _).
+chars_or_vars([C|Cs], PI) :-
+    (  nonvar(C) ->
+       (  catch(builtins:atom_length(C, 1), _, false) ->
+             (  nonvar(Cs) ->
+             chars_or_vars(Cs, PI)
+             ;  false
+             )
+       ;  throw(error(type_error(character, C), PI))
+       )
+    ;  chars_or_vars(Cs, PI)
+    ).
+
+can_be_codes_or_vars(Cs, _) :- var(Cs), !.
+can_be_codes_or_vars(Cs, PI) :- codes_or_vars(Cs, PI).
+
+codes_or_vars([], _).
+codes_or_vars([C|Cs], PI) :-
+    (  nonvar(C) ->
+       (  catch(builtins:char_code(_, C), _, false) ->
+             (  nonvar(Cs) -> codes_or_vars(Cs, PI)
+             ;  false
+             )
+       ;  integer(C) ->
+          throw(error(representation_error(character_code), PI))
+       ;  throw(error(type_error(integer, C), PI))
+       )
+    ;  codes_or_vars(Cs, PI)
+    ).
+
 number_chars(N, Chs) :-
    (  ground(Chs)
    -> can_be_number(N, number_chars/2),