Domanda
Are the two terms [a,b,c,d,e] and [[X] | [b,c,d,e]] unifiable? I need confirmation I think they are not because you cannot get [X] = a in any way?
Soluzione
I think you need to unify with [X | [b,c,d,e]]
, not [[X] | [b,c,d,e]]
, i.e. you can get X=a
, not [X]=a
.
Altri suggerimenti
Your assumption is correct: [X]
, that we can rewrite as .(X,[])
cannot be unified with the atom a
.
We can rewrite [X|[b,c,d,e]]
as .(_G231,.(b,.(c,.(d,.(e,[])))))
, i.e. [X,a,b,c,d,e]
.
You can inspect see the shape without syntax sugar using display/1.
if X needs to be enclosed in a list for some reason, you will not be able to have this unify (as described by chac). but you can use the append predicate to get a match:
?- append([X], [b,c,d,e], [a,b,c,d,e]).
X = a
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow