このディレクトリの索引
#  Hi there. I tried to understand how this code works but i failed.
#  It concatenates two lists and then it reverses the result.
#  
#  reverse(L, RL):- reverse(L, [], RL).
#  reverse([], RL, RL).
#  reverse([H|T], S, RL):- reverse(T, [H|S], RL).
#  
#  
#  concat([], L, L).
#  concat([H|T1], L2, [H|T]):- concat(T1, L2, T).
#  
#  
#  concat_reverse(L1,L2,L):-concat(L1,L2,LN),reverse(LN,L)
#  My teacher told me to go to debug mode and trace the query to understand
#  but it didnt helped.
#  
#  here is an example
#  
#  5 ?- trace,concat_reverse([1,3],[4,5],S).
#     Call: (7) concat_reverse([1, 3], [4, 5], _G1444) ? creep
#     Call: (8) concat([1, 3], [4, 5], _G1569) ? creep
#     Call: (9) concat([3], [4, 5], _G1564) ? creep
#     Call: (10) concat([], [4, 5], _G1567) ? creep
#     Exit: (10) concat([], [4, 5], [4, 5]) ? creep
#     Exit: (9) concat([3], [4, 5], [3, 4, 5]) ? creep
#     Exit: (8) concat([1, 3], [4, 5], [1, 3, 4, 5]) ? creep
#     Call: (8) reverse([1, 3, 4, 5], _G1444) ? creep
#     Call: (9) reverse([1, 3, 4, 5], [], _G1444) ? creep
#     Call: (10) reverse([3, 4, 5], [1], _G1444) ? creep
#     Call: (11) reverse([4, 5], [3, 1], _G1444) ? creep
#     Call: (12) reverse([5], [4, 3, 1], _G1444) ? creep
#     Call: (13) reverse([], [5, 4, 3, 1], _G1444) ? creep
#     Exit: (13) reverse([], [5, 4, 3, 1], [5, 4, 3, 1]) ? creep
#     Exit: (12) reverse([5], [4, 3, 1], [5, 4, 3, 1]) ? creep
#     Exit: (11) reverse([4, 5], [3, 1], [5, 4, 3, 1]) ? creep
#     Exit: (10) reverse([3, 4, 5], [1], [5, 4, 3, 1]) ? creep
#     Exit: (9) reverse([1, 3, 4, 5], [], [5, 4, 3, 1]) ? creep
#     Exit: (8) reverse([1, 3, 4, 5], [5, 4, 3, 1]) ? creep
#     Exit: (7) concat_reverse([1, 3], [4, 5], [5, 4, 3, 1]) ? creep
#  S = [5, 4, 3, 1].
#  

concat_reverse(L1,L2,L) :-
        concat_reverse(L1,L2,[],L).

concat_reverse([],[],L,L).
concat_reverse([],[B|R2],L3,L) :-
        concat_reverse([],R2,[B|L3],L).
concat_reverse([A|R1],L2,L3,L) :-
        concat_reverse(R1,L2,[A|L3],L).