Prolog change from a list to a conjunction
suppose i have a list
[p(X,Y) , h(n,U) , f(U,R)]
i want to change to a conjunction and assign the conjunction to a variable the output should be : Output:
Variabile = p(X,Y) , h(n,U) , f(U,R)
you ha开发者_StackOverflow社区ve any idea?
You can only assign terms to variables. Conjunction of terms is not a valid term.
Maybe you want this:
list_to_conj([H], H) :- !.
list_to_conj([H | T], ','(H, Conj)) :-
list_to_conj(T, Conj).
Usage examples:
?- list_to_conj([], Variable).
false.
?- list_to_conj([a], Variable).
Variable = a.
?- list_to_conj([a, b], Variable).
Variable = (a, b).
?- list_to_conj([p(X,Y) , h(n,U) , f(U,R)], Variable).
Variable = (p(X, Y), h(n, U), f(U, R)).
?- list_to_conj([writeln(hello), writeln(world)], Variable), call(Variable).
hello
world
Variable = (writeln(hello), writeln(world)).
精彩评论