]> Repositorios git - scryer-prolog.git/commitdiff
use new predicates from library(error) to throw type and domain errors
authorMarkus Triska <[email protected]>
Tue, 28 Apr 2020 15:34:56 +0000 (17:34 +0200)
committerMarkus Triska <[email protected]>
Tue, 28 Apr 2020 15:59:49 +0000 (17:59 +0200)
src/prolog/lib/charsio.pl
src/prolog/lib/lists.pl
src/prolog/lib/random.pl

index ead86e236b04daf1a14bbfc96c1ee970e7145ea6..b0faf0ab71fabdb527439717e4a43f5fdff5cc3e 100644 (file)
@@ -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)),
index 8561ab2aa32230903822d8f9a069d2731dba99a2..cded47467d93422843b6030610f0d38e5f03b14e 100644 (file)
@@ -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) :-
index 7f7803e32d35d4b90d950ed1fbe770153a7c5053..2fb21279faf32f70a9ddcb72cbc86245631358f0 100644 (file)
@@ -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) ->