Hello to everyone,
I am studying from a prolog tutorial, but I have stuck in a programm, and can't figure it out at all. It's the perm predicate, I think it's in the prolog or sth, it's definition is this(with the definition of takeout too that it uses):
takeout(X,[X|R],R).
takeout(X,[F|R],[F|S]) :- takeout(X,R,S).
perm([X|Y],Z) :- perm(Y,W), takeout(X,Z,W).
perm([],[]).
So, I ran it on Swi-prolog, and it has 4 answers I think. Even when I put the tracer, I couldn't get what it did. :S
I understand how the first solution comes out, but not the others. Please, can anyone help? I 'm stuck and I won't be able to understand the others....
I am studying from a prolog tutorial, but I have stuck in a programm, and can't figure it out at all. It's the perm predicate, I think it's in the prolog or sth, it's definition is this(with the definition of takeout too that it uses):
takeout(X,[X|R],R).
takeout(X,[F|R],[F|S]) :- takeout(X,R,S).
perm([X|Y],Z) :- perm(Y,W), takeout(X,Z,W).
perm([],[]).
So, I ran it on Swi-prolog, and it has 4 answers I think. Even when I put the tracer, I couldn't get what it did. :S
I understand how the first solution comes out, but not the others. Please, can anyone help? I 'm stuck and I won't be able to understand the others....