demo_delete_element/3
Instantiations of arguments in deleting elements from a list
/* ************************************************ */
/* */
/* demo_delete_element/3 */
/* Arg 1: Elem to be found */
/* Arg 2: List with Elem in */
/* Arg 3: List without Elem in */
/* Summary: calls demo_delete_element/4. */
/* Author: P J Hancox */
/* Date: 19 October 1994 */
/* */
/* ************************************************ */
% 1
demo_delete_element(Elem, List1, List2) :-
demo_delete_element(Elem, List1, List2, 1).
/* ************************************************ */
/* */
/* demo_delete_element/4 */
/* Arg 1: Elem to be found */
/* Arg 2: List with Elem in */
/* Arg 3: List without Elem in */
/* Arg 4: Integer */
/* Summary: Arg 2 is Arg 3 without Elem. */
/* Gives an output showing instantiation */
/* of arguments before and after */
/* recursion. */
/* Author: P J Hancox */
/* Date: 19 October 1994 */
/* */
/* ************************************************ */
% 1 terminating condition
demo_delete_element(Elem, [Elem|Tail], Tail, Depth) :-
tab(Depth * 5),
write('At the termination condition'),
nl,
tab((Depth * 5) + 3),
write('Elem is: '),
write(Elem),
nl,
tab((Depth * 5) + 3),
write('"Search list" is: '),
write([Elem|Tail]),
nl,
tab((Depth * 5) + 3),
write('"Result list" is: '),
write(Tail),
nl.
% 2 recursive
demo_delete_element(Elem, [Head|Tail1], [Head|Tail2], Depth1) :-
tab(Depth1 * 5),
write('Before recursion at depth '),
write(Depth1),
nl,
tab((Depth1 * 5) + 3),
write('Elem is: '),
write(Elem),
nl,
tab((Depth1 * 5) + 3),
write('"Search list" is: '),
write([Head|Tail1]),
nl,
tab((Depth1 * 5) + 3),
write('"Result list" is: '),
write([Head|Tail2]),
nl,
Depth2 is Depth1 + 1,
demo_delete_element(Elem, Tail1, Tail2, Depth2),
tab(Depth1 * 5),
write('After recursion at depth '),
write(Depth1),
nl,
tab((Depth1 * 5) + 3),
write('Elem is: '),
write(Elem),
nl,
tab((Depth1 * 5) + 3),
write('"Search list" is: '),
write([Head|Tail1]),
nl,
tab((Depth1 * 5) + 3),
write('"Result list" is: '),
write([Head|Tail2]),
nl.
/* ************************************************ */
/* End of program */
/* ************************************************ */