remove non-determinism in number_chars/2 and numbercodes/2 (#1473)
This commit is contained in:
@@ -1375,33 +1375,32 @@ must_be_number(N, PI) :-
|
|||||||
; throw(error(instantiation_error, PI))
|
; throw(error(instantiation_error, PI))
|
||||||
).
|
).
|
||||||
|
|
||||||
can_be_chars_or_vars(Cs, _) :- var(Cs), !.
|
chars_or_vars(Cs, _) :-
|
||||||
can_be_chars_or_vars(Cs, PI) :- chars_or_vars(Cs, PI).
|
( var(Cs) ->
|
||||||
|
!
|
||||||
chars_or_vars([], _).
|
; Cs == [] ->
|
||||||
|
!
|
||||||
|
).
|
||||||
chars_or_vars([C|Cs], PI) :-
|
chars_or_vars([C|Cs], PI) :-
|
||||||
( nonvar(C) ->
|
( nonvar(C) ->
|
||||||
( atom(C),
|
( atom(C),
|
||||||
atom_length(C, 1) ->
|
atom_length(C, 1) ->
|
||||||
( nonvar(Cs) ->
|
|
||||||
chars_or_vars(Cs, PI)
|
chars_or_vars(Cs, PI)
|
||||||
; false
|
|
||||||
)
|
|
||||||
; throw(error(type_error(character, C), PI))
|
; throw(error(type_error(character, C), PI))
|
||||||
)
|
)
|
||||||
; chars_or_vars(Cs, PI)
|
; chars_or_vars(Cs, PI)
|
||||||
).
|
).
|
||||||
|
|
||||||
can_be_codes_or_vars(Cs, _) :- var(Cs), !.
|
codes_or_vars(Cs, _) :-
|
||||||
can_be_codes_or_vars(Cs, PI) :- codes_or_vars(Cs, PI).
|
( var(Cs) ->
|
||||||
|
!
|
||||||
codes_or_vars([], _).
|
; Cs == [] ->
|
||||||
|
!
|
||||||
|
).
|
||||||
codes_or_vars([C|Cs], PI) :-
|
codes_or_vars([C|Cs], PI) :-
|
||||||
( nonvar(C) ->
|
( nonvar(C) ->
|
||||||
( catch(builtins:char_code(_, C), _, false) ->
|
( catch(builtins:char_code(_, C), _, false) ->
|
||||||
( nonvar(Cs) -> codes_or_vars(Cs, PI)
|
codes_or_vars(Cs, PI)
|
||||||
; false
|
|
||||||
)
|
|
||||||
; integer(C) ->
|
; integer(C) ->
|
||||||
throw(error(representation_error(character_code), PI))
|
throw(error(representation_error(character_code), PI))
|
||||||
; throw(error(type_error(integer, C), PI))
|
; throw(error(type_error(integer, C), PI))
|
||||||
@@ -1416,15 +1415,13 @@ number_chars(N, Chs) :-
|
|||||||
error(E, _),
|
error(E, _),
|
||||||
builtins:throw(error(E, number_chars/2))
|
builtins:throw(error(E, number_chars/2))
|
||||||
),
|
),
|
||||||
'$chars_to_number'(Chs, Nx),
|
'$chars_to_number'(Chs, N)
|
||||||
Nx = N
|
|
||||||
; must_be_number(N, number_chars/2),
|
; must_be_number(N, number_chars/2),
|
||||||
( var(Chs) -> true
|
( var(Chs) -> true
|
||||||
; can_be_list(Chs, number_chars/2),
|
; can_be_list(Chs, number_chars/2),
|
||||||
chars_or_vars(Chs, number_chars/2)
|
chars_or_vars(Chs, number_chars/2)
|
||||||
),
|
),
|
||||||
'$number_to_chars'(N, Chsx),
|
'$number_to_chars'(N, Chs)
|
||||||
Chsx = Chs
|
|
||||||
).
|
).
|
||||||
|
|
||||||
list_of_ints(Ns) :-
|
list_of_ints(Ns) :-
|
||||||
@@ -1438,15 +1435,13 @@ number_codes(N, Chs) :-
|
|||||||
error(E, _),
|
error(E, _),
|
||||||
builtins:throw(error(E, number_codes/2))
|
builtins:throw(error(E, number_codes/2))
|
||||||
),
|
),
|
||||||
'$codes_to_number'(Chs, Nx),
|
'$codes_to_number'(Chs, N)
|
||||||
Nx = N
|
|
||||||
; must_be_number(N, number_codes/2),
|
; must_be_number(N, number_codes/2),
|
||||||
( var(Chs) -> true
|
( var(Chs) -> true
|
||||||
; can_be_list(Chs, number_codes/2)
|
; can_be_list(Chs, number_codes/2),
|
||||||
, codes_or_vars(Chs, number_codes/2)
|
codes_or_vars(Chs, number_codes/2)
|
||||||
),
|
),
|
||||||
'$number_to_codes'(N, Chsx),
|
'$number_to_codes'(N, Chs)
|
||||||
Chsx = Chs
|
|
||||||
).
|
).
|
||||||
|
|
||||||
subsumes_term(General, Specific) :-
|
subsumes_term(General, Specific) :-
|
||||||
|
|||||||
@@ -1839,7 +1839,10 @@ impl Machine {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let chars_atom = self.machine_st.atom_tbl.build_with(&string.trim());
|
let chars_atom = self.machine_st.atom_tbl.build_with(&string.trim());
|
||||||
self.machine_st.unify_complete_string(chars_atom, self.machine_st.store(self.machine_st.deref(chs)));
|
self.machine_st.unify_complete_string(
|
||||||
|
chars_atom,
|
||||||
|
self.machine_st.store(self.machine_st.deref(chs)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
|||||||
Reference in New Issue
Block a user