]> Repositorios git - scryer-prolog.git/commitdiff
ENHANCED: "f" on toplevel to report answers up to the next multiple of 5.
authorMarkus Triska <[email protected]>
Sat, 21 May 2022 16:20:08 +0000 (18:20 +0200)
committerMarkus Triska <[email protected]>
Sat, 21 May 2022 16:20:08 +0000 (18:20 +0200)
This makes counting solutions easy.

README.md
src/lib/time.pl
src/toplevel.pl

index 68fab560ed92bc4d1b112280dd57aab388883efe..bc31310c8870ade693e338b7822a7b1da635a835 100644 (file)
--- a/README.md
+++ b/README.md
@@ -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`
 or&nbsp;`.` to abort the search and return to the
-toplevel&nbsp;prompt. Press&nbsp;`f` to see the next 5 answers, and
-`a` to see all answers. Press&nbsp;`h` to show a help message.
+toplevel&nbsp;prompt. Press&nbsp;`f` to see up to the next multiple of
+5 answers, and `a` to see all answers. Press&nbsp;`h` to show a help
+message.
 
 Use `TAB` to complete atoms and predicate names in queries. For
 instance, after consulting the program above, typing `decl` followed
index 5da5bb594508c49f58858d11995bcdabb84679f1..20187c2d7dee1a0f82f40e30eb782e2ddbd59091 100644 (file)
@@ -119,7 +119,7 @@ report_time(ID) :-
         time_state(ID, T0),
         '$cpu_now'(T),
         Time is T - T0,
-        (   bb_get('$first_answer', true) ->
+        (   bb_get('$answer_count', 0) ->
             Pre = "   ", Post = ""
         ;   Pre = "", Post = "   "
         ),
index 171b76d5aaf2431d39a5438ca38cdb73bc97f158..4b3e0b34c88ea080be3d8c958d89ebc51649e41e 100644 (file)
@@ -134,7 +134,6 @@ run_goals([Goal|_]) :-
     halt.
 
 repl :-
-    bb_put('$first_answer', true),
     catch(read_and_match, E, print_exception(E)),
     false. %% this is for GC, until we get actual GC.
 repl :-
@@ -185,7 +184,7 @@ submit_query_and_print_results_(Term, VarList) :-
     write_eqs_and_read_input(B, VarList),
     !.
 submit_query_and_print_results_(_, _) :-
-    (   bb_get('$first_answer', true) ->
+    (   bb_get('$answer_count', 0) ->
         write('   ')
     ;   true
     ),
@@ -199,7 +198,7 @@ submit_query_and_print_results(Term0, VarList) :-
                     % in the first argument, which is done by call/N
     ;  expand_goal(Term0, user, Term)
     ),
-    bb_put('$first_answer', true),
+    bb_put('$answer_count', 0),
     submit_query_and_print_results_(Term, VarList).
 
 
@@ -305,11 +304,13 @@ write_eqs_and_read_input(B, VarList) :-
     append([AttrGoalVars | EquationVars], Vars1),
     term_variables(Vars1, Vars2), % deduplicate vars of Vars1 but preserve their order.
     charsio:extend_var_list(Vars2, VarList, NewVarList0, fabricated),
-    (   bb_get('$first_answer', true) ->
-        write('   '),
-        bb_put('$first_answer', false)
+    bb_get('$answer_count', Count),
+    (   Count =:= 0 ->
+        write('   ')
     ;   true
     ),
+    Count1 is Count + 1,
+    bb_put('$answer_count', Count1),
     (  B0 == B ->
        (  Goals == [] ->
           write('true.'), nl
@@ -353,7 +354,9 @@ read_input(ThreadedGoals, NewVarList) :-
        bb_put('$report_all', true),
        nl, write(';  '), false
     ;  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
     ;  read_input(ThreadedGoals, NewVarList)
     ).