Merge pull request #1482 from triska/multiple_of_five_answers

ENHANCED: "f" on toplevel to report answers up to the next multiple of 5.
This commit is contained in:
Mark Thom
2022-05-21 12:35:35 -06:00
committed by GitHub
3 changed files with 14 additions and 10 deletions

View File

@@ -202,8 +202,9 @@ predicates it defines. For example, with the program shown above:
Press `SPACE` to show further answers, if any exist. Press `RETURN` Press `SPACE` to show further answers, if any exist. Press `RETURN`
or `.` to abort the search and return to the or `.` to abort the search and return to the
toplevel prompt. Press `f` to see the next 5 answers, and toplevel prompt. Press `f` to see up to the next multiple of
`a` to see all answers. Press `h` to show a help message. 5 answers, and `a` to see all answers. Press `h` to show a help
message.
Use `TAB` to complete atoms and predicate names in queries. For Use `TAB` to complete atoms and predicate names in queries. For
instance, after consulting the program above, typing `decl` followed instance, after consulting the program above, typing `decl` followed

View File

@@ -119,7 +119,7 @@ report_time(ID) :-
time_state(ID, T0), time_state(ID, T0),
'$cpu_now'(T), '$cpu_now'(T),
Time is T - T0, Time is T - T0,
( bb_get('$first_answer', true) -> ( bb_get('$answer_count', 0) ->
Pre = " ", Post = "" Pre = " ", Post = ""
; Pre = "", Post = " " ; Pre = "", Post = " "
), ),

View File

@@ -134,7 +134,6 @@ run_goals([Goal|_]) :-
halt. halt.
repl :- repl :-
bb_put('$first_answer', true),
catch(read_and_match, E, print_exception(E)), catch(read_and_match, E, print_exception(E)),
false. %% this is for GC, until we get actual GC. false. %% this is for GC, until we get actual GC.
repl :- repl :-
@@ -185,7 +184,7 @@ submit_query_and_print_results_(Term, VarList) :-
write_eqs_and_read_input(B, VarList), write_eqs_and_read_input(B, VarList),
!. !.
submit_query_and_print_results_(_, _) :- submit_query_and_print_results_(_, _) :-
( bb_get('$first_answer', true) -> ( bb_get('$answer_count', 0) ->
write(' ') write(' ')
; true ; true
), ),
@@ -199,7 +198,7 @@ submit_query_and_print_results(Term0, VarList) :-
% in the first argument, which is done by call/N % in the first argument, which is done by call/N
; expand_goal(Term0, user, Term) ; expand_goal(Term0, user, Term)
), ),
bb_put('$first_answer', true), bb_put('$answer_count', 0),
submit_query_and_print_results_(Term, VarList). submit_query_and_print_results_(Term, VarList).
@@ -305,11 +304,13 @@ write_eqs_and_read_input(B, VarList) :-
append([AttrGoalVars | EquationVars], Vars1), append([AttrGoalVars | EquationVars], Vars1),
term_variables(Vars1, Vars2), % deduplicate vars of Vars1 but preserve their order. term_variables(Vars1, Vars2), % deduplicate vars of Vars1 but preserve their order.
charsio:extend_var_list(Vars2, VarList, NewVarList0, fabricated), charsio:extend_var_list(Vars2, VarList, NewVarList0, fabricated),
( bb_get('$first_answer', true) -> bb_get('$answer_count', Count),
write(' '), ( Count =:= 0 ->
bb_put('$first_answer', false) write(' ')
; true ; true
), ),
Count1 is Count + 1,
bb_put('$answer_count', Count1),
( B0 == B -> ( B0 == B ->
( Goals == [] -> ( Goals == [] ->
write('true.'), nl write('true.'), nl
@@ -353,7 +354,9 @@ read_input(ThreadedGoals, NewVarList) :-
bb_put('$report_all', true), bb_put('$report_all', true),
nl, write('; '), false nl, write('; '), false
; C = f -> ; C = f ->
bb_put('$report_n_more', 5), bb_get('$answer_count', Count),
More is 5 - Count mod 5,
bb_put('$report_n_more', More),
nl, write('; '), false nl, write('; '), false
; read_input(ThreadedGoals, NewVarList) ; read_input(ThreadedGoals, NewVarList)
). ).