
% myappend(L1, L2, Result)
% ----------------------
% append the contents of list L2 to the contents of list L1 and unify with Result,
% e.g.  myappend([1,2,3], [4,5], R) should unify R with [1,2,3,4,5]

% error checking, results in guaranteed fail
myappend(L1, _, error) :- not(is_list(L1)), !.
myappend(_, L2, error) :- not(is_list(L2)), !.

% base cases
myappend([], L2, L2).         % first list is empty
myappend([H|T], [], [H|T]).   % second list is empty, first list is not

% general case
myappend([H|T], L2, [H|R]) :- myappend(T, L2, R), !.

