Monday, 15 March 2010

prolog - Incomplete to difference lists -



prolog - Incomplete to difference lists -

i want convert incomplete lists difference lists , vice versa.

this code convert regular list difference:

reg2diff(l,x-y):-append(l,y,x).

how go other direction?

incomplete difference list:

inc2diff(l,z):- ( nonvar(l) -> ( l=[_|t] -> inc2diff(t,z) ; l=[] -> z=[] ) ; l=z ).

use 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 = [].

prolog difference-lists

No comments:

Post a Comment