我很困惑为什么[a,b,c,d]和[a,b | [c,d]]统一。从我有限的理解,“|”运算符分割头部和尾部产生[a,b]和[[c,d]]。那么这个带有明显双重列表的结果对象怎么能与第一个的c,d统一呢?
答案 0 :(得分:1)
列表[a,b,c,d]
和[a,b|[c,d]]
是相同的,“|”将列表拆分为头a
和尾部[b,c,d]
(参见@Will Ness的评论)。请看下面更好地理解它:
[a,b,c] unifies with [Head|Tail] resulting in Head=a and Tail=[b,c]
[a] unifies with [H|T] resulting in H=a and T=[]
[a,b,c] unifies with [a|T] resulting in T=[b,c]
[a,b,c] doesn't unify with [b|T]
[] doesn't unify with [H|T]
[] unifies with []. Two empty lists always match
在第二个示例中,您可以看到[a]
与[a|[]]
相同,而在第三个示例中:[a,b,c]
与[a|[b,c]]
统一,这与您的示例相同