
step_demo_0 :- (init_demo_series, reset_step_demo, set_flag(toplevel_module, opium)), opium_printf(help, "\n%w\n\n%w\n\n", [buggy(nqueens), "This goal loads the nqueens program in the traced session. \nYou may want to start the goal in the traced session and type \n\"continue\" to see its overall behavior."]), execute_demo_goal(buggy(nqueens)).

:- load_decl(opium_demo(name : step_demo_0, demo_goal : buggy(nqueens), condition : (init_demo_series, reset_step_demo, set_flag(toplevel_module, opium)), scenario : step_by_step, message : "This goal loads the nqueens program in the traced session. \nYou may want to start the goal in the traced session and type \n\"continue\" to see its overall behavior.")).

step_demo_1 :- (goto_np(1), set_parameter(slot_display, [on, on, on, on, off, on, on, off])), opium_printf(help, "\n%w\n\n%w\n\n", [(set_default_parameters(step_by_step), get_parameter(traced_ports, Default), n(10)), "This goal shows which lines the \"next\" command shows by default. The \nfirst slot of the trace lines is the chronological line number. Note \nthat there are some \"holes\" due to skipped lines (\"unify\" and \"redo\")."]), execute_demo_goal((set_default_parameters(step_by_step), get_parameter(traced_ports, Default), n(10))).

:- load_decl(opium_demo(name : step_demo_1, demo_goal : (set_default_parameters(step_by_step), get_parameter(traced_ports, Default), n(10)), condition : (goto_np(1), set_parameter(slot_display, [on, on, on, on, off, on, on, off])), scenario : step_by_step, message : "This goal shows which lines the \"next\" command shows by default. The \nfirst slot of the trace lines is the chronological line number. Note \nthat there are some \"holes\" due to skipped lines (\"unify\" and \"redo\").")).

step_demo_2 :- opium_nl(trace), opium_printf(help, "\n%w\n\n%w\n\n", [(set_parameter(traced_ports, [[call, next, exit, exit_c, fail, delay, resume, leave, unify, redo]]), back(10)), "This goal sets all the trace lines to be traced. Note that as \"unify\" \nand \"redo\" have been added to the list of traced ports the 10 lines \nshown by \"back(10)\" are not the same as the 10 lines previously shown."]), execute_demo_goal((set_parameter(traced_ports, [[call, next, exit, exit_c, fail, delay, resume, leave, unify, redo]]), back(10))).

:- load_decl(opium_demo(name : step_demo_2, demo_goal : (set_parameter(traced_ports, [[call, next, exit, exit_c, fail, delay, resume, leave, unify, redo]]), back(10)), condition : opium_nl(trace), scenario : step_by_step, message : "This goal sets all the trace lines to be traced. Note that as \"unify\" \nand \"redo\" have been added to the list of traced ports the 10 lines \nshown by \"back(10)\" are not the same as the 10 lines previously shown.")).

step_demo_3 :- opium_nl(trace), opium_printf(help, "\n%w\n\n%w\n\n", [(next, curr_port(Port), Port \== unify, Port \== next), "Trace till condition: This goal traces lines forwards according to \n\"traced_port\" and will not stop at lines whose port is \"unify\" or \"next\". \nIt does not set anything permanently as opposed to setting these ports \nleashed.  (Type \";\" in the Opium-1 window to get further trace lines.)"]), execute_demo_goal((next, curr_port(Port), Port \== unify, Port \== next)).

:- load_decl(opium_demo(name : step_demo_3, demo_goal : (next, curr_port(Port), Port \== unify, Port \== next), condition : opium_nl(trace), scenario : step_by_step, message : "Trace till condition: This goal traces lines forwards according to \n\"traced_port\" and will not stop at lines whose port is \"unify\" or \"next\". \nIt does not set anything permanently as opposed to setting these ports \nleashed.  (Type \";\" in the Opium-1 window to get further trace lines.)")).

step_demo_4 :- opium_nl(trace), opium_printf(help, "\n%w\n\n%w\n\n", [(next, curr_port(Port), (Port == unify ; Port == next)), "Trace till condition: This goal will trace all lines forwards \naccording to \"traced_port\" and will stop only at \"unify\" and \"next\" (if \nthese ports ports are set to be traced!).(Type \";\" in the Opium-1  \nwindow to get further trace lines.)"]), execute_demo_goal((next, curr_port(Port), (Port == unify ; Port == next))).

:- load_decl(opium_demo(name : step_demo_4, demo_goal : (next, curr_port(Port), (Port == unify ; Port == next)), condition : opium_nl(trace), scenario : step_by_step, message : "Trace till condition: This goal will trace all lines forwards \naccording to \"traced_port\" and will stop only at \"unify\" and \"next\" (if \nthese ports ports are set to be traced!).(Type \";\" in the Opium-1  \nwindow to get further trace lines.)")).

step_demo_5 :- opium_nl(trace), opium_printf(help, "\n%w\n\n%w\n\n", [(next_np, curr_port(Port), Port \== unify, Port \== next, print_line), "Skip till condition: This goal skips all the coming \"unify\" and \"next\" \ntrace lines. \"next_np\" retrieves the next line (according to \"traced_ports\")  \nbut does not print it.  It does not set anything permanently as \nopposed to setting these two ports untraced with the \"traced_port\" \nparameter.  (Type \";\" in the Opium-1 window to get further trace \nlines.)"]), execute_demo_goal((next_np, curr_port(Port), Port \== unify, Port \== next, print_line)).

:- load_decl(opium_demo(name : step_demo_5, demo_goal : (next_np, curr_port(Port), Port \== unify, Port \== next, print_line), condition : opium_nl(trace), scenario : step_by_step, message : "Skip till condition: This goal skips all the coming \"unify\" and \"next\" \ntrace lines. \"next_np\" retrieves the next line (according to \"traced_ports\")  \nbut does not print it.  It does not set anything permanently as \nopposed to setting these two ports untraced with the \"traced_port\" \nparameter.  (Type \";\" in the Opium-1 window to get further trace \nlines.)")).

step_demo_6 :- opium_nl(trace), opium_printf(help, "\n%w\n\n%w\n\n", [(next_np, curr_port(Port), (Port == unify ; Port == next), print_line), "Skip till condition: This goal will go directly to a trace line \ncorresponding to a \"unify\" or a \"next\" (if they are traced!). Note that if \nyou want to be sure to trace the \"unify\" and \"next\" lines even if they are \nset untraced you can use \"f_get(_,_,_, [unify, next], _)\"."]), execute_demo_goal((next_np, curr_port(Port), (Port == unify ; Port == next), print_line)).

:- load_decl(opium_demo(name : step_demo_6, demo_goal : (next_np, curr_port(Port), (Port == unify ; Port == next), print_line), condition : opium_nl(trace), scenario : step_by_step, message : "Skip till condition: This goal will go directly to a trace line \ncorresponding to a \"unify\" or a \"next\" (if they are traced!). Note that if \nyou want to be sure to trace the \"unify\" and \"next\" lines even if they are \nset untraced you can use \"f_get(_,_,_, [unify, next], _)\".")).

step_demo_7_1 :- (opium_clear(help, pce), opium_clear(source, pce), system(clear), goto(1)), opium_printf(help, "\n%w\n\n%w\n\n", [((spy safe / 1), leap, leap, leap), "The computation fails, we want to check how \"safe/1\" behaves. \"spy/1\" \nsets a break point on it, and \"leap/0\" retrieves and prints the lines  \nrelated to spied points."]), execute_demo_goal(((spy safe / 1), leap, leap, leap)).

:- load_decl(opium_demo(name : step_demo_7_1, demo_goal : ((spy safe / 1), leap, leap, leap), condition : (opium_clear(help, pce), opium_clear(source, pce), system(clear), goto(1)), scenario : step_by_step, message : "The computation fails, we want to check how \"safe/1\" behaves. \"spy/1\" \nsets a break point on it, and \"leap/0\" retrieves and prints the lines  \nrelated to spied points.")).

step_demo_7_2 :- opium_nl(trace), opium_printf(help, "\n%w\n\n%w\n\n", [(leap_np, curr_port(fail), print_line), "The previous goal showed that a breakpoint is not precise enough. \nActually seeing the failing of \"safe/1\" would be enough."]), execute_demo_goal((leap_np, curr_port(fail), print_line)).

:- load_decl(opium_demo(name : step_demo_7_2, demo_goal : (leap_np, curr_port(fail), print_line), condition : opium_nl(trace), scenario : step_by_step, message : "The previous goal showed that a breakpoint is not precise enough. \nActually seeing the failing of \"safe/1\" would be enough.")).

step_demo_7_3 :- (opium_nl(trace), lib(show_queens)), opium_printf(help, "\n%w\n\n%w\n\n", [(leap_np, curr_port(fail), print_line, curr_arg([X]), show_queens(X)), "In order to determine more easily whether the failure of \"safe/1\" is  \ncorrect or not, we can use a progam which displays the chessboard. \nThe goal is the same as the previous one except that the value of the \nargument of safe is retrieved ans printed with the \"show_queens/1\" \npredicate."]), execute_demo_goal((leap_np, curr_port(fail), print_line, curr_arg([X]), show_queens(X))).

:- load_decl(opium_demo(name : step_demo_7_3, demo_goal : (leap_np, curr_port(fail), print_line, curr_arg([X]), show_queens(X)), condition : (opium_nl(trace), lib(show_queens)), scenario : step_by_step, message : "In order to determine more easily whether the failure of \"safe/1\" is  \ncorrect or not, we can use a progam which displays the chessboard. \nThe goal is the same as the previous one except that the value of the \nargument of safe is retrieved ans printed with the \"show_queens/1\" \npredicate.")).

step_demo_7_4 :- opium_nl(trace), opium_printf(help, "\n%w\n\n%w\n\n", [(leap_np, curr_port(fail), curr_arg([X]), (X == [2, 4, 1, 3] ; X == [3, 1, 4, 2]), print_line, show_queens(X)), "\"safe/1\" calls itself recursively and there are too many failures to \ncheck. We know that it should not fail for [2,4,1,3] and [3,1,2,4]. \nThe goal checks whether these two cases occur. (Type \";\" in the \nOpium-1 window to see the second case). \"safe/1\" definitely needs  \nto be debugged further."]), execute_demo_goal((leap_np, curr_port(fail), curr_arg([X]), (X == [2, 4, 1, 3] ; X == [3, 1, 4, 2]), print_line, show_queens(X))).

:- load_decl(opium_demo(name : step_demo_7_4, demo_goal : (leap_np, curr_port(fail), curr_arg([X]), (X == [2, 4, 1, 3] ; X == [3, 1, 4, 2]), print_line, show_queens(X)), condition : opium_nl(trace), scenario : step_by_step, message : "\"safe/1\" calls itself recursively and there are too many failures to \ncheck. We know that it should not fail for [2,4,1,3] and [3,1,2,4]. \nThe goal checks whether these two cases occur. (Type \";\" in the \nOpium-1 window to see the second case). \"safe/1\" definitely needs  \nto be debugged further.")).

step_demo_7_5 :- true, opium_printf(help, "\n%w\n\n%w\n\n", [((nospy safe / 1), leap), "Removes the breakpoint from \"safe/1\"."]), execute_demo_goal(((nospy safe / 1), leap)).

:- load_decl(opium_demo(name : step_demo_7_5, demo_goal : ((nospy safe / 1), leap), condition : true, scenario : step_by_step, message : "Removes the breakpoint from \"safe/1\".")).

step_demo_custom_1_1 :- (opium_clear(help, pce), opium_clear(source, pce), system(clear)), opium_printf(help, "\n%w\n\n%w\n\n", [(man(next), implementation_link(command, next / 0, Default, Module)), "Assume you want to customize the \"next/0\" command. You first ask \nfor its manual entry to know the type of the command (\"man\"). Then \nyou ask for the name of the default implementation which you want to \nreuse (\"implementation_link\")."]), execute_demo_goal((man(next), implementation_link(command, next / 0, Default, Module))).

:- load_decl(opium_demo(name : step_demo_custom_1_1, demo_goal : (man(next), implementation_link(command, next / 0, Default, Module)), condition : (opium_clear(help, pce), opium_clear(source, pce), system(clear)), scenario : step_by_step, message : "Assume you want to customize the \"next/0\" command. You first ask \nfor its manual entry to know the type of the command (\"man\"). Then \nyou ask for the name of the default implementation which you want to \nreuse (\"implementation_link\").")).

step_demo_custom_1_2 :- opium_nl(trace), opium_printf(help, "\n%w\n\n%w\n\n", [(rebuild_object(command, next / 0, new_next_impl, step_by_step, opium), next(10)), "Now that we know that the \"next\" command is of type trace, we know \nthat the new implementation should not print any trace line (see \nchapter of manual about \"setting the environement\"). Assume that we \nwant the \"next\" command to always print a newline before \"call\" \nlines. We can define a \"new_next_impl\" predicate as defined below. And \ntell Opium to use it as implementation for the \"next\" command using \n\"rebuild_object\". \n\tnew_next_impl :-  \n        \tnext_Op,  \n        \t(  curr_port(call) \n        \t-> opium_nl(trace) \n        \t;  true \n\t\t)."]), execute_demo_goal((rebuild_object(command, next / 0, new_next_impl, step_by_step, opium), next(10))).

:- load_decl(opium_demo(name : step_demo_custom_1_2, demo_goal : (rebuild_object(command, next / 0, new_next_impl, step_by_step, opium), next(10)), condition : opium_nl(trace), scenario : step_by_step, message : "Now that we know that the \"next\" command is of type trace, we know \nthat the new implementation should not print any trace line (see \nchapter of manual about \"setting the environement\"). Assume that we \nwant the \"next\" command to always print a newline before \"call\" \nlines. We can define a \"new_next_impl\" predicate as defined below. And \ntell Opium to use it as implementation for the \"next\" command using \n\"rebuild_object\". \n\tnew_next_impl :-  \n        \tnext_Op,  \n        \t(  curr_port(call) \n        \t-> opium_nl(trace) \n        \t;  true \n\t\t).")).

step_demo_custom_2 :- opium_nl(trace), opium_printf(help, "\n%w\n\n%w\n\n", [(set_default(command, next / 0, step_by_step, opium), n(5)), "If you want to set the customized commands back to their default \nvalues use \"set_default/4\"."]), execute_demo_goal((set_default(command, next / 0, step_by_step, opium), n(5))).

:- load_decl(opium_demo(name : step_demo_custom_2, demo_goal : (set_default(command, next / 0, step_by_step, opium), n(5)), condition : opium_nl(trace), scenario : step_by_step, message : "If you want to set the customized commands back to their default \nvalues use \"set_default/4\".")).

step_demo_reset :- true, opium_printf(help, "\n%w\n\n%w\n\n", [reset_step_demo, "Resets all parameters and customizations done for the steo_by_step \ndemos."]), execute_demo_goal(reset_step_demo).

:- load_decl(opium_demo(name : step_demo_reset, demo_goal : reset_step_demo, condition : true, scenario : step_by_step, message : "Resets all parameters and customizations done for the steo_by_step \ndemos.")).
