
display_demo_0 :- (init_demo_series, reset_display_demo, set_flag(toplevel_module, opium_kernel)), opium_printf(help, "\n%w\n\n%w\n\n", [buggy(nqueens), "This goal loads the \"nqueens\" program in the traced session. Start the \nexecution in that session before going on with the demo."]), execute_demo_goal(buggy(nqueens)).

:- load_decl(opium_demo(name : display_demo_0, demo_goal : buggy(nqueens), condition : (init_demo_series, reset_display_demo, set_flag(toplevel_module, opium_kernel)), scenario : display, message : "This goal loads the \"nqueens\" program in the traced session. Start the \nexecution in that session before going on with the demo.")).

display_demo_1 :- opium_nl(help), opium_printf(help, "\n%w\n\n%w\n\n", [(set_default_parameters(display), p, next(10)), "This goal shows the default display of a trace sample."]), execute_demo_goal((set_default_parameters(display), p, next(10))).

:- load_decl(opium_demo(name : display_demo_1, demo_goal : (set_default_parameters(display), p, next(10)), condition : opium_nl(help), scenario : display, message : "This goal shows the default display of a trace sample.")).

display_demo_2 :- opium_nl(trace), opium_printf(help, "\n%w\n\n%w\n\n", [(indent(on), next(10)), "This goal shows the display of trace lines with the relative \nindentation on. The indentation starts for depths greater than the \ndepth of the line at which the indentation has been set."]), execute_demo_goal((indent(on), next(10))).

:- load_decl(opium_demo(name : display_demo_2, demo_goal : (indent(on), next(10)), condition : opium_nl(trace), scenario : display, message : "This goal shows the display of trace lines with the relative \nindentation on. The indentation starts for depths greater than the \ndepth of the line at which the indentation has been set.")).

display_demo_3 :- opium_nl(trace), opium_printf(help, "\n%w\n\n%w\n\n", [(set_parameter(list_display, [truncate, 3]), next(10)), "This goal shows the display of trace lines with the lists being \ntruncated. You may also try \"[nest, N]\" if the structures of your lists \nare complicated."]), execute_demo_goal((set_parameter(list_display, [truncate, 3]), next(10))).

:- load_decl(opium_demo(name : display_demo_3, demo_goal : (set_parameter(list_display, [truncate, 3]), next(10)), condition : opium_nl(trace), scenario : display, message : "This goal shows the display of trace lines with the lists being \ntruncated. You may also try \"[nest, N]\" if the structures of your lists \nare complicated.")).

display_demo_4 :- opium_nl(trace), opium_printf(help, "\n%w\n\n%w\n\n", [(set_parameter(slot_display, [on, on, on, on, off, on, on, off]), next(10)), "This goal shows the display of trace lines with the chronological \nline number and without the module name. If the pce interface is \nrunning you may want to use the parameter menu to set the parameter. \nIf it is a tty interface try \"set_parameter(slot_display).\""]), execute_demo_goal((set_parameter(slot_display, [on, on, on, on, off, on, on, off]), next(10))).

:- load_decl(opium_demo(name : display_demo_4, demo_goal : (set_parameter(slot_display, [on, on, on, on, off, on, on, off]), next(10)), condition : opium_nl(trace), scenario : display, message : "This goal shows the display of trace lines with the chronological \nline number and without the module name. If the pce interface is \nrunning you may want to use the parameter menu to set the parameter. \nIf it is a tty interface try \"set_parameter(slot_display).\"")).

display_demo_5 :- opium_nl(trace), opium_printf(help, "\n%w\n\n%w\n\n", [(set_parameter(arg_undisplay, [permutation / 2, 1]), next(10)), "This goal shows the display of trace lines with the first argument \nof \"permutation/2\" not being displayed. Parameter \"arg_undisplay\" \nis of type multiple (see Manual chapter about \"setting the debugging \nenvironment\".  If there are several arguments undisplayed and you \nwant to set some of them back to be displayed use \n\"unset_parameter/2\". If you want to set them ALL back to be \ndisplayed use \"set_default(arg_undisplay)\"."]), execute_demo_goal((set_parameter(arg_undisplay, [permutation / 2, 1]), next(10))).

:- load_decl(opium_demo(name : display_demo_5, demo_goal : (set_parameter(arg_undisplay, [permutation / 2, 1]), next(10)), condition : opium_nl(trace), scenario : display, message : "This goal shows the display of trace lines with the first argument \nof \"permutation/2\" not being displayed. Parameter \"arg_undisplay\" \nis of type multiple (see Manual chapter about \"setting the debugging \nenvironment\".  If there are several arguments undisplayed and you \nwant to set some of them back to be displayed use \n\"unset_parameter/2\". If you want to set them ALL back to be \ndisplayed use \"set_default(arg_undisplay)\".")).

display_demo_6 :- (f_get(_1371, _1372, _1373, _1374, permutation / 2), opium_nl(trace)), opium_printf(help, "\n%w\n\n%w\n\n", [curr_arg([X, _1386]), "Now, you occasionally may want to see the arguments you have hidden. \nThis is always possible! Let us move to a line whose predicate is \n\"permutation\". We can retrieve the arguments using \"curr_arg\". \nNote that you can use the unification to specify precisely which \nargument you want to see."]), execute_demo_goal(curr_arg([X, _1386])).

:- load_decl(opium_demo(name : display_demo_6, demo_goal : curr_arg([X, _1386]), condition : (f_get(_1371, _1372, _1373, _1374, permutation / 2), opium_nl(trace)), scenario : display, message : "Now, you occasionally may want to see the arguments you have hidden. \nThis is always possible! Let us move to a line whose predicate is \n\"permutation\". We can retrieve the arguments using \"curr_arg\". \nNote that you can use the unification to specify precisely which \nargument you want to see.")).

display_demo_7 :- opium_nl(trace), opium_printf(help, "\n%w\n\n%w\n\n", [(set_default(arg_undisplay), set_default(list_display)), "Before we go on with customizations, let set parameters \narg_undisplay and list_display back to default."]), execute_demo_goal((set_default(arg_undisplay), set_default(list_display))).

:- load_decl(opium_demo(name : display_demo_7, demo_goal : (set_default(arg_undisplay), set_default(list_display)), condition : opium_nl(trace), scenario : display, message : "Before we go on with customizations, let set parameters \narg_undisplay and list_display back to default.")).

display_demo_custom_1_1 :- true, opium_printf(help, "\n%w\n\n%w\n\n", [(man(print_line), implementation_link(command, print_line / 0, Impl, Module)), "Assume we want to customize the way the lines are displayed such \nthat the arguments are displayed only for call and exit lines. It is a \ngood idea to use the default implementation of \"print_line\" as much \nas possible because it is a tricky predicate which takes into account \nmany aspects such as Opium parameters, operators... To know what is \nthe name of the default implementation use \"implementation_link\". \nBefore customizing ask ofr the manual entry to know in which module \nthe command is defined and what is the type of the command (see Manual \nchapter about \"setting up the debugging environment\"."]), execute_demo_goal((man(print_line), implementation_link(command, print_line / 0, Impl, Module))).

:- load_decl(opium_demo(name : display_demo_custom_1_1, demo_goal : (man(print_line), implementation_link(command, print_line / 0, Impl, Module)), condition : true, scenario : display, message : "Assume we want to customize the way the lines are displayed such \nthat the arguments are displayed only for call and exit lines. It is a \ngood idea to use the default implementation of \"print_line\" as much \nas possible because it is a tricky predicate which takes into account \nmany aspects such as Opium parameters, operators... To know what is \nthe name of the default implementation use \"implementation_link\". \nBefore customizing ask ofr the manual entry to know in which module \nthe command is defined and what is the type of the command (see Manual \nchapter about \"setting up the debugging environment\".")).

display_demo_custom_1_2 :- opium_nl(trace), opium_printf(help, "\n%w\n\n%w\n\n", [(rebuild_object(command, print_line / 0, new_print_line, display, opium_kernel), next(10)), "Thus, we know that \"print_line\" is of type opium, in scenario \"display\" \nand loaded in module \"opium_kernel\". We can use \"rebuild_objec\"t to link \nthe \"print_line\" command to the new implementation given below which \nprints the arguments only for \"call\", \"exit_c\"  and \"exit\" ports. The \n\"argument\" slot is switched off by setting parameter \"slot_display\" \njust before printing, when on \"call\", \"exit_c\", or \"exit\" lines. The \n\"argument\" slot is then set back to its previous value right after \nprinting. \n   new_print_line :- \n\tcurr_port(CurrPort), \n\t( (CurrPort == call ; CurrPort == exit ; CurrPort == exit_c) \n\t-> print_line_Op \n\t;  get_parameter(slot_display,  \n\t\t\t [Chrono, Call, Depth, Port, Module, Pred, Arg, Arity]), \n\t   set_parameter(slot_display,  \n\t   \t\t [Chrono, Call, Depth, Port, Module, Pred, off, Arity]), \n\t   print_line_Op, \n\t   set_parameter(slot_display,  \n\t   \t\t [Chrono, Call, Depth, Port, Module, Pred, Arg, Arity]) \n\t)."]), execute_demo_goal((rebuild_object(command, print_line / 0, new_print_line, display, opium_kernel), next(10))).

:- load_decl(opium_demo(name : display_demo_custom_1_2, demo_goal : (rebuild_object(command, print_line / 0, new_print_line, display, opium_kernel), next(10)), condition : opium_nl(trace), scenario : display, message : "Thus, we know that \"print_line\" is of type opium, in scenario \"display\" \nand loaded in module \"opium_kernel\". We can use \"rebuild_objec\"t to link \nthe \"print_line\" command to the new implementation given below which \nprints the arguments only for \"call\", \"exit_c\"  and \"exit\" ports. The \n\"argument\" slot is switched off by setting parameter \"slot_display\" \njust before printing, when on \"call\", \"exit_c\", or \"exit\" lines. The \n\"argument\" slot is then set back to its previous value right after \nprinting. \n   new_print_line :- \n\tcurr_port(CurrPort), \n\t( (CurrPort == call ; CurrPort == exit ; CurrPort == exit_c) \n\t-> print_line_Op \n\t;  get_parameter(slot_display,  \n\t\t\t [Chrono, Call, Depth, Port, Module, Pred, Arg, Arity]), \n\t   set_parameter(slot_display,  \n\t   \t\t [Chrono, Call, Depth, Port, Module, Pred, off, Arity]), \n\t   print_line_Op, \n\t   set_parameter(slot_display,  \n\t   \t\t [Chrono, Call, Depth, Port, Module, Pred, Arg, Arity]) \n\t).")).

display_demo_custom_2_1 :- true, opium_printf(help, "\n%w\n\n%w\n\n", [(man(write_slot), implementation_link(procedure, write_slot / 2, Impl, Module)), "You can display the slots as you want by customizing procedure \"write_slot\"."]), execute_demo_goal((man(write_slot), implementation_link(procedure, write_slot / 2, Impl, Module))).

:- load_decl(opium_demo(name : display_demo_custom_2_1, demo_goal : (man(write_slot), implementation_link(procedure, write_slot / 2, Impl, Module)), condition : true, scenario : display, message : "You can display the slots as you want by customizing procedure \"write_slot\".")).

display_demo_custom_2_2 :- opium_nl(trace), opium_printf(help, "\n%w\n\n%w\n\n", [(rebuild_object(procedure, write_slot / 2, new_write_slot, display, opium_kernel), next(10)), "For example to have the \"depth\" slot displayed in between \"*\" instead of \nin between brackets you can link the following predicate to the \n\"write_slot\" procedure.  The \"depth\" slot of trace lines will be displayed \nin the customized way and the other slots in the default way. \n\tnew_write_slot(depth, D) :- \n \t\t!, \n \t\twrite_trace(*), \n \t\twrite_trace(D), \n \t\twrite_trace(*). \n  \tnew_write_slot(N, V) :- \n \t\twrite_slot_Op(N, V)."]), execute_demo_goal((rebuild_object(procedure, write_slot / 2, new_write_slot, display, opium_kernel), next(10))).

:- load_decl(opium_demo(name : display_demo_custom_2_2, demo_goal : (rebuild_object(procedure, write_slot / 2, new_write_slot, display, opium_kernel), next(10)), condition : opium_nl(trace), scenario : display, message : "For example to have the \"depth\" slot displayed in between \"*\" instead of \nin between brackets you can link the following predicate to the \n\"write_slot\" procedure.  The \"depth\" slot of trace lines will be displayed \nin the customized way and the other slots in the default way. \n\tnew_write_slot(depth, D) :- \n \t\t!, \n \t\twrite_trace(*), \n \t\twrite_trace(D), \n \t\twrite_trace(*). \n  \tnew_write_slot(N, V) :- \n \t\twrite_slot_Op(N, V).")).

display_demo_custom_3_1 :- (set_default(command, print_line / 0, display, opium_kernel), custom(show_queens)), opium_printf(help, "\n%w\n\n%w\n\n", [(man(write_nth_arg), implementation_link(procedure, write_nth_arg / 4, Impl, Module)), "If you want to display in a special way a particular argument of a \nparticular predicate, then customizing \"write_nth_arg(Argument, Rank, \nPred, Module)\" is better suited."]), execute_demo_goal((man(write_nth_arg), implementation_link(procedure, write_nth_arg / 4, Impl, Module))).

:- load_decl(opium_demo(name : display_demo_custom_3_1, demo_goal : (man(write_nth_arg), implementation_link(procedure, write_nth_arg / 4, Impl, Module)), condition : (set_default(command, print_line / 0, display, opium_kernel), custom(show_queens)), scenario : display, message : "If you want to display in a special way a particular argument of a \nparticular predicate, then customizing \"write_nth_arg(Argument, Rank, \nPred, Module)\" is better suited.")).

display_demo_custom_3_2 :- opium_nl(trace), opium_printf(help, "\n%w\n\n%w\n\n", [(rebuild_object(procedure, write_nth_arg / 4, new_write_nth_arg, display, opium_kernel), next(10)), "Assume the programmer has written a predicate \"show_queens/1\" to \nget a pretty-printed solution of \"nqueens/1\". This predicate can be \nused to get a nice display of the argument of \"safe/1\". The \nfollowing has been compiled: \n\tnew_write_nth_arg(Arg, 1, safe/1, M) :- \n\t\t!, \n\t\tshow_queens(Arg). \n\tnew_write_nth_arg(A, N, P, M) :- \n\t\twrite_nth_arg_Op(A, N, P, M)."]), execute_demo_goal((rebuild_object(procedure, write_nth_arg / 4, new_write_nth_arg, display, opium_kernel), next(10))).

:- load_decl(opium_demo(name : display_demo_custom_3_2, demo_goal : (rebuild_object(procedure, write_nth_arg / 4, new_write_nth_arg, display, opium_kernel), next(10)), condition : opium_nl(trace), scenario : display, message : "Assume the programmer has written a predicate \"show_queens/1\" to \nget a pretty-printed solution of \"nqueens/1\". This predicate can be \nused to get a nice display of the argument of \"safe/1\". The \nfollowing has been compiled: \n\tnew_write_nth_arg(Arg, 1, safe/1, M) :- \n\t\t!, \n\t\tshow_queens(Arg). \n\tnew_write_nth_arg(A, N, P, M) :- \n\t\twrite_nth_arg_Op(A, N, P, M).")).

display_demo_reset :- opium_nl(trace), opium_printf(help, "\n%w\n\n%w\n\n", [(set_default_parameters(display), set_default(procedure, write_slot / 2, display, opium_kernel), set_default(procedure, write_nth_arg / 4, display, opium_kernel), set_default(command, print_line / 0, display, opium_kernel), back(5)), "To set back the customized object to their default values use \n\"set_default/4\"."]), execute_demo_goal((set_default_parameters(display), set_default(procedure, write_slot / 2, display, opium_kernel), set_default(procedure, write_nth_arg / 4, display, opium_kernel), set_default(command, print_line / 0, display, opium_kernel), back(5))).

:- load_decl(opium_demo(name : display_demo_reset, demo_goal : (set_default_parameters(display), set_default(procedure, write_slot / 2, display, opium_kernel), set_default(procedure, write_nth_arg / 4, display, opium_kernel), set_default(command, print_line / 0, display, opium_kernel), back(5)), condition : opium_nl(trace), scenario : display, message : "To set back the customized object to their default values use \n\"set_default/4\".")).
