From a3f02904325d40bd64c5d4587b2a82fe5639bb90 Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Wed, 17 Mar 2021 20:23:58 -0600 Subject: [PATCH] restore deleted parts of number_chars/2 and number_codes/2 (#721) --- src/lib/builtins.pl | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/lib/builtins.pl b/src/lib/builtins.pl index 0bb64f33..983612c8 100644 --- a/src/lib/builtins.pl +++ b/src/lib/builtins.pl @@ -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), -- 2.54.0