Merge pull request #363 from triska/master
Delay toplevel output until after the goal succeeds
This commit is contained in:
@@ -55,7 +55,7 @@
|
|||||||
Example:
|
Example:
|
||||||
|
|
||||||
?- phrase(format_("~s~n~`.t~w!~12|", ["hello",there]), Cs).
|
?- phrase(format_("~s~n~`.t~w!~12|", ["hello",there]), Cs).
|
||||||
%@ Cs = [h,e,l,l,o,'\n','.','.','.','.','.','.',t,h,e,r,e,!]
|
%@ Cs = "hello\n......there!"
|
||||||
%@ ; false.
|
%@ ; false.
|
||||||
|
|
||||||
I place this code in the public domain. Use it in any way you want.
|
I place this code in the public domain. Use it in any way you want.
|
||||||
@@ -444,38 +444,38 @@ indent_to(CurrentColumn, Indent) -->
|
|||||||
format_("~t~*|", [Delta]).
|
format_("~t~*|", [Delta]).
|
||||||
|
|
||||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
?- portray_clause(a), nl.
|
?- portray_clause(a).
|
||||||
a.
|
a.
|
||||||
|
|
||||||
?- nl, portray_clause((a :- b)), nl.
|
?- portray_clause((a :- b)).
|
||||||
a :-
|
a :-
|
||||||
b.
|
b.
|
||||||
|
|
||||||
?- nl, portray_clause((a :- b, c, d)), nl.
|
?- portray_clause((a :- b, c, d)).
|
||||||
a :-
|
a :-
|
||||||
b,
|
b,
|
||||||
c,
|
c,
|
||||||
d.
|
d.
|
||||||
|
|
||||||
|
|
||||||
?- nl, portray_clause([a,b,c,d]), nl.
|
?- portray_clause([a,b,c,d]).
|
||||||
"abcd".
|
"abcd".
|
||||||
|
|
||||||
?- nl, portray_clause(X).
|
?- portray_clause(X).
|
||||||
?- nl, portray_clause((f(X) :- X)).
|
?- portray_clause((f(X) :- X)).
|
||||||
|
|
||||||
?- nl, portray_clause((h :- ( a -> b; c))).
|
?- portray_clause((h :- ( a -> b; c))).
|
||||||
|
|
||||||
?- nl, portray_clause((h :- ( (a -> x ; y) -> b; c))).
|
?- portray_clause((h :- ( (a -> x ; y) -> b; c))).
|
||||||
|
|
||||||
?- nl, portray_clause((h(X) :- ( (a(X) ; y(A,B)) -> b; c))).
|
?- portray_clause((h(X) :- ( (a(X) ; y(A,B)) -> b; c))).
|
||||||
|
|
||||||
?- nl, portray_clause((h :- (a,d;b,c) ; (b,e;d))).
|
?- portray_clause((h :- (a,d;b,c) ; (b,e;d))).
|
||||||
|
|
||||||
?- nl, portray_clause((a :- b ; c ; d)).
|
?- portray_clause((a :- b ; c ; d)).
|
||||||
|
|
||||||
?- nl, portray_clause((h :- L = '.')).
|
?- portray_clause((h :- L = '.')).
|
||||||
|
|
||||||
?- nl, portray_clause(-->(a, (b, {t}, d))).
|
?- portray_clause(-->(a, (b, {t}, d))).
|
||||||
|
|
||||||
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||||
|
|||||||
@@ -46,16 +46,24 @@ instruction_match(Term, VarList) :-
|
|||||||
submit_query_and_print_results(Term, VarList)
|
submit_query_and_print_results(Term, VarList)
|
||||||
).
|
).
|
||||||
|
|
||||||
|
:- use_module(library(iso_ext)).
|
||||||
|
|
||||||
|
% auxiliary predicates, so that using them in setup_call_cleanup/3 works
|
||||||
|
get_b_value(B) :- '$get_b_value'(B).
|
||||||
|
clear_attribute_goals :- '$clear_attribute_goals'.
|
||||||
|
|
||||||
submit_query_and_print_results(Term0, VarList) :-
|
submit_query_and_print_results(Term0, VarList) :-
|
||||||
( expand_goals(Term0, Term) -> true
|
( expand_goals(Term0, Term) -> true
|
||||||
; Term0 = Term
|
; Term0 = Term
|
||||||
),
|
),
|
||||||
( '$get_b_value'(B), write(' '), call(Term), write_eqs_and_read_input(B, VarList),
|
setup_call_cleanup(bb_put('$first_answer', true),
|
||||||
!
|
( get_b_value(B), call(Term), write_eqs_and_read_input(B, VarList),
|
||||||
% clear attribute goal lists, which may be populated by
|
!
|
||||||
% copy_term/3 prior to failure.
|
; % clear attribute goal lists, which may be populated by
|
||||||
; '$clear_attribute_goals', write('false.'), nl
|
% copy_term/3 prior to failure.
|
||||||
).
|
clear_attribute_goals, write('false.'), nl
|
||||||
|
),
|
||||||
|
bb_put('$first_answer', false)).
|
||||||
|
|
||||||
needs_bracketing(Value, Op) :-
|
needs_bracketing(Value, Op) :-
|
||||||
catch((functor(Value, F, _),
|
catch((functor(Value, F, _),
|
||||||
@@ -132,6 +140,11 @@ write_eqs_and_read_input(B, VarList) :-
|
|||||||
sort(NewVarList, SortedVarList),
|
sort(NewVarList, SortedVarList),
|
||||||
'$get_b_value'(B0),
|
'$get_b_value'(B0),
|
||||||
gather_goals(SortedVarList, SortedVarList, Goals),
|
gather_goals(SortedVarList, SortedVarList, Goals),
|
||||||
|
( bb_get('$first_answer', true) ->
|
||||||
|
write(' '),
|
||||||
|
bb_put('$first_answer', false)
|
||||||
|
; true
|
||||||
|
),
|
||||||
( B0 == B ->
|
( B0 == B ->
|
||||||
( Goals == [] ->
|
( Goals == [] ->
|
||||||
write('true.'), nl
|
write('true.'), nl
|
||||||
|
|||||||
Reference in New Issue
Block a user