From: Markus Triska Date: Tue, 28 Apr 2020 15:34:56 +0000 (+0200) Subject: use new predicates from library(error) to throw type and domain errors X-Git-Tag: v0.8.123~100^2^2~6 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=b139620fbac947321aa883e87c2cdf3174a2b071;p=scryer-prolog.git use new predicates from library(error) to throw type and domain errors --- diff --git a/src/prolog/lib/charsio.pl b/src/prolog/lib/charsio.pl index ead86e23..b0faf0ab 100644 --- a/src/prolog/lib/charsio.pl +++ b/src/prolog/lib/charsio.pl @@ -3,7 +3,7 @@ write_term_to_chars/3]). :- use_module(library(iso_ext)). - +:- use_module(library(error)). fabricate_var_name(VarType, VarName, N) :- char_code('A', AC), @@ -58,17 +58,17 @@ extend_var_list_([V|Vs], N, VarList, NewVarList, VarType) :- char_type(Char, Type) :- - ( var(Char) -> throw(error(instantiation_error, char_type/2)) + ( var(Char) -> instantiation_error(char_type/2) ; atom_length(Char, 1) -> ( ground(Type) -> ( ctype(Type) -> '$char_type'(Char, Type) - ; throw(error(domain_error(char_type, Type), char_type/2)) + ; domain_error(char_type, Type, char_type/2) ) ; ctype(Type), '$char_type'(Char, Type) ) - ; throw(error(type_error(in_character, Char), char_type/2)) + ; type_error(in_character, Char, char_type/2) ). @@ -101,13 +101,13 @@ ctype(whitespace). get_single_char(C) :- ( var(C) -> '$get_single_char'(C) ; atom_length(C, 1) -> '$get_single_char'(C) - ; throw(error(type_error(in_character, C), get_single_char/1)) + ; type_error(in_character, C, get_single_char/1) ). read_term_from_chars(Chars, Term) :- ( var(Chars) -> - throw(error(instantiation_error, read_term_from_chars/2)) + instantiation_error(read_term_from_chars/2) ; nonvar(Term) -> throw(error(uninstantiation_error(Term), read_term_from_chars/2)) ; '$skip_max_list'(_, -1, Chars, Chars0), @@ -115,23 +115,23 @@ read_term_from_chars(Chars, Term) :- partial_string(Chars) -> true ; - throw(error(type_error(complete_string, Chars), read_term_from_chars/2)) + type_error(complete_string, Chars, read_term_from_chars/2) ), '$read_term_from_chars'(Chars, Term). write_term_to_chars(_, Options, _) :- - var(Options), throw(error(instantiation_error, write_term_to_chars/3)). + var(Options), instantiation_error(write_term_to_chars/3). write_term_to_chars(Term, Options, Chars) :- '$skip_max_list'(_, -1, Options, Options0), ( var(Options0) -> - throw(error(instantiation_error, write_term_to_chars/3)) + instantiation_error(write_term_to_chars/3) ; nonvar(Chars) -> throw(error(uninstantiation_error(Chars), write_term_to_chars/3)) ; Options0 == [] -> true ; - throw(error(type_error(list, Options), write_term_to_chars/3)) + type_error(list, Options, write_term_to_chars/3) ), builtins:inst_member_or(Options, ignore_ops(IgnoreOps), ignore_ops(false)), builtins:inst_member_or(Options, numbervars(NumberVars), numbervars(false)), diff --git a/src/prolog/lib/lists.pl b/src/prolog/lib/lists.pl index 8561ab2a..cded4746 100644 --- a/src/prolog/lib/lists.pl +++ b/src/prolog/lib/lists.pl @@ -21,9 +21,9 @@ length(Xs, N) :- ; var(Xs0) -> R is N-M, length_rundown(Xs0, R)). length(_, N) :- integer(N), !, - throw(error(domain_error(not_less_than_zero, N), length/2)). + domain_error(not_less_than_zero, N, length/2). length(_, N) :- - throw(error(type_error(integer, N), length/2)). + type_error(integer, N, length/2). length_addendum([], N, N). length_addendum([_|Xs], N, M) :- diff --git a/src/prolog/lib/random.pl b/src/prolog/lib/random.pl index 7f7803e3..2fb21279 100644 --- a/src/prolog/lib/random.pl +++ b/src/prolog/lib/random.pl @@ -22,7 +22,7 @@ random(R) :- random_integer(Lower, Upper, R) :- var(R), ( (var(Lower) ; var(Upper)) -> - throw(error(instantiation_error, random_integer/3)) + instantiation_error(random_integer/3) ; \+ integer(Lower) -> domain_error(integer, Lower, random_integer/3) ; \+ integer(Upper) ->