I am just learning Prolog and the concept of difference-lists in Prolog, so bear with me please.
I have following code:
:- op(400, xfx, \).
append(Xs, Ys, Zs) :-
append_dl( [Xs|T1]\T1, [Ys|T2]\T2, Zs\[]).
append_dl( Xs\Ys, Ys\Zs, Xs\Zs).
Now if i append Lists [1,2,3] and [a,b,c] in the SWI-interpreter it yields lists of lists
?- append([1,2,3],[a,b,c],Zs).
Zs = [[1, 2, 3], [a, b, c]].
Whereas if i do call append_dl direktly like so:
?- append_dl([1,2,3|T1]\T1,[a,b,c|T2]\T2,Zs\[]).
T1 = [a, b, c],
T2 = [],
Zs = [1, 2, 3, a, b, c].
it works...
What am i doing wrong and how should one wrap these functions using difference lists correctly?
Thank you guys for the Help :D
append([1,2,3],[a,b,c],Zs).
is actually callingappend_dl([[1,2,3]|T1]\T1, [[a,b,c]|T2]\T2, Zs\[]).
notappend_dl([1,2,3|T1]\T1, [a,b,c|T2]\T2, Zs\[]).
. Thus, the inconsistent results. - lurkerappend_dl(Xs-Ys, Ys-Zs, Xs-Zs).
- lurkerappend/3
is not. It's just fantasy that does not work. - false