mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-28 15:54:18 +00:00
Estimated hours taken: 6
Branches: main
Implement `undo' command in the declarative debugger.
The `undo' command takes the debugger back to the state it was in before the
last answer was given (`skip' is counted as an answer in this case).
browser/declarative_analyser.m:
Add an interface predicate which allows us to get the last question
asked by the analyser.
Do not handle `show_info' in process_answer, since `show_info' is
no longer considered an answer (see below).
browser/declarative_debugger.m:
Make `show_info' an oracle response, instead of an oracle answer,
since it doesn't affect the search space.
Get rid of diagnoser_{get,set}_{analyser,oracle}, because they serve
no abstraction purpose and maintaining them is a pain.
Add a new field to the diagnoser which records the state of the
diagnoser before the previous oracle answer. This turns the
diagnoser into a stack. Add predicates to push and pop
diagnosers from this stack.
Push the current diagnoser onto the stack when an oracle answer
is received from the user.
Pop the previous diagnoser when the `undo' command is issued.
browser/declarative_oracle.m:
Add `undo' to the set of possible oracle responses.
Add a predicate which makes the current knowledge base of one oracle
the revised knowledge base of another oracle.
Fix a spelling mistake.
Add a predicate to get the output stream used to communicate with the
user.
Report whether an answer came directly from the user or not in
query_oracle.
browser/declarative_user.m:
Add the `undo' user response.
Add a predicate to get the output stream used to communicate with the
user. This is used by the diagnoser to print a "Undo stack empty"
message.
doc/user_guide.texi
Document the new command.
tests/debugger/declarative/Mmakefile:
tests/debugger/declarative/undo.exp:
tests/debugger/declarative/undo.inp:
tests/debugger/declarative/undo.m:
Test the new command.
22 lines
316 B
Mathematica
22 lines
316 B
Mathematica
:- module undo.
|
|
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module list, int.
|
|
|
|
main(!IO) :-
|
|
sum([1, 2, 3, 4, 5, 6], S),
|
|
io.write_int(S, !IO),
|
|
io.nl(!IO).
|
|
|
|
:- pred sum(list(int)::in, int::out) is det.
|
|
|
|
sum([], 0).
|
|
sum([H | T], H + Sum) :- sum(T, Sum).
|