I want to convert incomplete lists into difference lists and vice versa.
This is code to convert regular list to difference:
reg2diff(L,X-Y):-append(L,Y,X).
How do I go the other direction?
Incomplete to difference list:
inc2diff(L,Z):-
( nonvar(L)
-> ( L=[_|T] -> inc2diff(T,Z) ; L=[] -> Z=[] )
; L=Z
).
Use it as
23 ?- L=[1,2,3|_],inc2diff(L,X).
L = [1, 2, 3|X].
24 ?- L=[1,2,3|Z],inc2diff(L,X).
L = [1, 2, 3|X],
Z = X.
25 ?- L=[1,2,3],inc2diff(L,X).
L = [1, 2, 3],
X = [].
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With