append
insertを参考にappendを書いた。とりあえず動くように見える。
insert(1, X, L, [X | L]). insert(N, X, [Y | L], [Y | Z]) :- N > 1, N1 is N - 1, insert(N1, X, L, Z). my_append([], S, S). my_append([Fcar | Fcdr], S, [Fcar | R]) :- my_append(Fcdr, S, R). % test code my_append([], [], R), R = []. my_append([1], [], R), R = [1]. my_append([1, 2], [], R), R = [1, 2]. my_append([], [a], R), R = [a]. my_append([], [a, b], R), R = [a, b]. my_append([1], [a], R), R = [1, a]. my_append([1, 2], [a], R), R = [1, 2, a]. my_append([1, 2], [a, b], R), R = [1, 2, a, b]. my_append([1], [a, b], R), R = [1, a, b].