前缀列表如何在序言中工作

How list of prefix works in prolog

我试图理解这段代码是如何工作的,但我做不到。

prefix(P,L) :- append(P,_,L).

我用过这样的查询prefix(X,[a,b,c,d]).如果你有时间,你能向我解释一下它是如何工作的吗?。谢谢。

查看 append 你可以看到

append(L1,L2,L3) will hold when the list L3 is the result of concatenating the lists L1 and L2 together (concatenating means joining the lists together, end to end)

所以你上面的谓词说某物是某物的prefix,如果你可以将任何东西(即_)附加到前者并获得后者。

很有道理,不是吗?序言很好。