print errors as goals (#1408)

This commit is contained in:
Mark Thom
2022-04-09 14:01:48 -06:00
parent 0876d46880
commit 00eab4d415
3 changed files with 27 additions and 19 deletions

View File

@@ -1,7 +1,7 @@
:- module(builtins, [(=)/2, (\=)/2, (\+)/1, !/0, (',')/2, (->)/2, (;)/2,
(=..)/2, (:)/2, (:)/3, (:)/4, (:)/5, (:)/6,
(:)/7, (:)/8, (:)/9, (:)/10, (:)/11, (:)/12,
abolish/1, asserta/1, assertz/1,
:- module(builtins, [(=)/2, (\=)/2, (\+)/1, !/0, (',')/2, (->)/2,
(;)/2, (=..)/2, (:)/2, (:)/3, (:)/4, (:)/5,
(:)/6, (:)/7, (:)/8, (:)/9, (:)/10, (:)/11,
(:)/12, abolish/1, asserta/1, assertz/1,
at_end_of_stream/0, at_end_of_stream/1,
atom_chars/2, atom_codes/2, atom_concat/3,
atom_length/2, bagof/3, call/1, call/2, call/3,
@@ -10,12 +10,12 @@
close/1, close/2, current_input/1,
current_output/1, current_op/3,
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,
get_byte/2, get_char/1, get_char/2, get_code/1,
get_code/2, halt/0, halt/1, nl/0,
nl/1, number_chars/2, number_codes/2, once/1,
op/3, open/3, open/4, peek_byte/1, peek_byte/2,
get_code/2, halt/0, halt/1, nl/0, nl/1,
number_chars/2, number_codes/2, once/1, op/3,
open/3, open/4, peek_byte/1, peek_byte/2,
peek_char/1, peek_char/2, peek_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,
@@ -1700,3 +1700,6 @@ nl :-
nl(Stream) :-
put_char(Stream, '\n').
error(Error_term, Imp_def) :-
throw(error(Error_term, Imp_def)).

View File

@@ -17,6 +17,14 @@
:- use_module(library(pairs)).
write_error(Error) :-
write(' '),
( nonvar(Error),
functor(Error, error, 2) ->
writeq(Error)
; writeq(throw(Error))
).
'$print_message_and_fail'(Error) :-
( ( Error = error(existence_error(procedure, Expansion), Expansion)
; Error = error(evaluation_error((_:_)/_),Expansion)
@@ -25,12 +33,10 @@
; Expansion = term_expansion/2
) ->
true
; write('caught: '),
writeq(Error),
; write_error(Error),
nl
)
; write('caught: '),
writeq(Error),
; write_error(Error),
nl
),
'$fail'.

View File

@@ -129,8 +129,8 @@ run_goals([g(Gs0)|Goals]) :-
),
run_goals(Goals).
run_goals([Goal|_]) :-
write('caught: '),
write(error(domain_error(arg_type, Goal), run_goals/1)), nl,
loader:write_error(error(domain_error(arg_type, Goal), run_goals/1)),
nl,
halt.
repl :-
@@ -412,13 +412,12 @@ gather_equations([Var = Value | Pairs], OrigVarList, Goals) :-
print_exception(E) :-
( E == error('$interrupt_thrown', repl) -> nl % print the
% exception on a
% newline to evade
% "^C".
% exception on a
% newline to evade
% "^C".
; true
),
write_term('caught: ', [quoted(false), max_depth(20)]),
writeq(E),
loader:write_error(E),
nl.
print_exception_with_check(E) :-