demo_app/3

Instantiations of arguments in appending

     /* ************************************************ */
     /*                                                  */
     /*   demo_app/3                                     */
     /*      Arg 1:  List                                */
     /*      Arg 2:  List                                */
     /*      Arg 3:  List                                */
     /*   Summary: calls demo_app/4.                     */
     /*   Author: P J Hancox                             */
     /*   Date:   16 October 1994                        */
     /*                                                  */
     /* ************************************************ */

     % 1
     demo_app(List1, List2, List3) :-
          demo_app(List1, List2, List3, 1).

     /* ************************************************ */
     /*                                                  */
     /*   demo_app/4                                     */
     /*      Arg 1:  List                                */
     /*      Arg 2:  List                                */
     /*      Arg 3:  List                                */
     /*      Arg 4:  Integer                             */
     /*   Summary: appends Arg 1 and Arg to give Arg 3.  */
     /*            Gives an output showing instantiation */
     /*            of arguments before and after         */
     /*            recursion.                            */
     /*   Author: P J Hancox                             */
     /*   Date:   16 October 1994                        */
     /*                                                  */
     /* ************************************************ */

     % 1 terminating condition
     demo_app([], List, List, Depth) :-
          tab(Depth * 5),
          write('At the termination condition'), 
          nl,
          tab((Depth * 5) + 3), 
          write('List1 is: '),
          write([]),
          nl,
          tab((Depth * 5) + 3), 
          write('List2 is: '),
          write(List),
          nl,
          tab((Depth * 5) + 3), 
          write('List3 is: '),
          write(List),
          nl.
     % 2 recursive
     demo_app([Hd|Tl1], List2, [Hd|Tl3], Depth1) :-
          tab(Depth1 * 5),
          write('Before recursion at depth '),
          write(Depth1), 
          nl,
          tab((Depth1 * 5) + 3), 
          write('List1 is: '),
          write([Hd|Tl1]),
          nl,
          tab((Depth1 * 5) + 3), 
          write('List2 is: '),
          write(List2),
          nl,
          tab((Depth1 * 5) + 3), 
          write('List3 is: '),
          write([Hd|Tl3]),
          nl,
          Depth2 is Depth1 + 1,
          demo_app(Tl1, List2, Tl3, Depth2),
          tab(Depth1 * 5),
          write('After recursion at depth '),
          write(Depth1), 
          nl,
          tab((Depth1 * 5) + 3), 
          write('List1 is: '),
          write([Hd|Tl1]),
          nl,
          tab((Depth1 * 5) + 3), 
          write('List2 is: '),
          write(List2),
          nl,
          tab((Depth1 * 5) + 3), 
          write('List3 is: '),
          write([Hd|Tl3]),
          nl.

     /* ************************************************ */
     /*                  End of program                  */
     /* ************************************************ */