print errors as goals (#1408)
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
:- module(builtins, [(=)/2, (\=)/2, (\+)/1, !/0, (',')/2, (->)/2, (;)/2,
|
:- module(builtins, [(=)/2, (\=)/2, (\+)/1, !/0, (',')/2, (->)/2,
|
||||||
(=..)/2, (:)/2, (:)/3, (:)/4, (:)/5, (:)/6,
|
(;)/2, (=..)/2, (:)/2, (:)/3, (:)/4, (:)/5,
|
||||||
(:)/7, (:)/8, (:)/9, (:)/10, (:)/11, (:)/12,
|
(:)/6, (:)/7, (:)/8, (:)/9, (:)/10, (:)/11,
|
||||||
abolish/1, asserta/1, assertz/1,
|
(:)/12, abolish/1, asserta/1, assertz/1,
|
||||||
at_end_of_stream/0, at_end_of_stream/1,
|
at_end_of_stream/0, at_end_of_stream/1,
|
||||||
atom_chars/2, atom_codes/2, atom_concat/3,
|
atom_chars/2, atom_codes/2, atom_concat/3,
|
||||||
atom_length/2, bagof/3, call/1, call/2, call/3,
|
atom_length/2, bagof/3, call/1, call/2, call/3,
|
||||||
@@ -10,12 +10,12 @@
|
|||||||
close/1, close/2, current_input/1,
|
close/1, close/2, current_input/1,
|
||||||
current_output/1, current_op/3,
|
current_output/1, current_op/3,
|
||||||
current_predicate/1, current_prolog_flag/2,
|
current_predicate/1, current_prolog_flag/2,
|
||||||
fail/0, false/0, findall/3, findall/4,
|
error/2, fail/0, false/0, findall/3, findall/4,
|
||||||
flush_output/0, flush_output/1, get_byte/1,
|
flush_output/0, flush_output/1, get_byte/1,
|
||||||
get_byte/2, get_char/1, get_char/2, get_code/1,
|
get_byte/2, get_char/1, get_char/2, get_code/1,
|
||||||
get_code/2, halt/0, halt/1, nl/0,
|
get_code/2, halt/0, halt/1, nl/0, nl/1,
|
||||||
nl/1, number_chars/2, number_codes/2, once/1,
|
number_chars/2, number_codes/2, once/1, op/3,
|
||||||
op/3, open/3, open/4, peek_byte/1, peek_byte/2,
|
open/3, open/4, peek_byte/1, peek_byte/2,
|
||||||
peek_char/1, peek_char/2, peek_code/1,
|
peek_char/1, peek_char/2, peek_code/1,
|
||||||
peek_code/2, put_byte/1, put_byte/2, put_code/1,
|
peek_code/2, put_byte/1, put_byte/2, put_code/1,
|
||||||
put_code/2, put_char/1, put_char/2, read/1,
|
put_code/2, put_char/1, put_char/2, read/1,
|
||||||
@@ -1700,3 +1700,6 @@ nl :-
|
|||||||
|
|
||||||
nl(Stream) :-
|
nl(Stream) :-
|
||||||
put_char(Stream, '\n').
|
put_char(Stream, '\n').
|
||||||
|
|
||||||
|
error(Error_term, Imp_def) :-
|
||||||
|
throw(error(Error_term, Imp_def)).
|
||||||
|
|||||||
@@ -17,6 +17,14 @@
|
|||||||
:- use_module(library(pairs)).
|
:- use_module(library(pairs)).
|
||||||
|
|
||||||
|
|
||||||
|
write_error(Error) :-
|
||||||
|
write(' '),
|
||||||
|
( nonvar(Error),
|
||||||
|
functor(Error, error, 2) ->
|
||||||
|
writeq(Error)
|
||||||
|
; writeq(throw(Error))
|
||||||
|
).
|
||||||
|
|
||||||
'$print_message_and_fail'(Error) :-
|
'$print_message_and_fail'(Error) :-
|
||||||
( ( Error = error(existence_error(procedure, Expansion), Expansion)
|
( ( Error = error(existence_error(procedure, Expansion), Expansion)
|
||||||
; Error = error(evaluation_error((_:_)/_),Expansion)
|
; Error = error(evaluation_error((_:_)/_),Expansion)
|
||||||
@@ -25,12 +33,10 @@
|
|||||||
; Expansion = term_expansion/2
|
; Expansion = term_expansion/2
|
||||||
) ->
|
) ->
|
||||||
true
|
true
|
||||||
; write('caught: '),
|
; write_error(Error),
|
||||||
writeq(Error),
|
|
||||||
nl
|
nl
|
||||||
)
|
)
|
||||||
; write('caught: '),
|
; write_error(Error),
|
||||||
writeq(Error),
|
|
||||||
nl
|
nl
|
||||||
),
|
),
|
||||||
'$fail'.
|
'$fail'.
|
||||||
|
|||||||
@@ -129,8 +129,8 @@ run_goals([g(Gs0)|Goals]) :-
|
|||||||
),
|
),
|
||||||
run_goals(Goals).
|
run_goals(Goals).
|
||||||
run_goals([Goal|_]) :-
|
run_goals([Goal|_]) :-
|
||||||
write('caught: '),
|
loader:write_error(error(domain_error(arg_type, Goal), run_goals/1)),
|
||||||
write(error(domain_error(arg_type, Goal), run_goals/1)), nl,
|
nl,
|
||||||
halt.
|
halt.
|
||||||
|
|
||||||
repl :-
|
repl :-
|
||||||
@@ -412,13 +412,12 @@ gather_equations([Var = Value | Pairs], OrigVarList, Goals) :-
|
|||||||
|
|
||||||
print_exception(E) :-
|
print_exception(E) :-
|
||||||
( E == error('$interrupt_thrown', repl) -> nl % print the
|
( E == error('$interrupt_thrown', repl) -> nl % print the
|
||||||
% exception on a
|
% exception on a
|
||||||
% newline to evade
|
% newline to evade
|
||||||
% "^C".
|
% "^C".
|
||||||
; true
|
; true
|
||||||
),
|
),
|
||||||
write_term('caught: ', [quoted(false), max_depth(20)]),
|
loader:write_error(E),
|
||||||
writeq(E),
|
|
||||||
nl.
|
nl.
|
||||||
|
|
||||||
print_exception_with_check(E) :-
|
print_exception_with_check(E) :-
|
||||||
|
|||||||
Reference in New Issue
Block a user