I have written the following small knowledge base for reversing a given list,
reverse_list([],[]).
reverse_list([X|L1], [L2|X]) :-
reverse_list(L1, L2).
Currently, when executed
reverse_list([a,b,c,d], X).
It produces,
X = [[[[[]|d]|c]|b]|a].
An explanation of why it happens would be much appreciated. And, how can I get around this problem?
I think at last step L2 becomes [] and during back propagation it becomes like that.
How can I get the output like , X = [d,c,b,a]
using a modification of this approach.
P.S: I am new at Prolog.