內置謂詞成員(x,List)檢查成員是否存在於列表中,但是當列表中有列表時,它只檢查第一個深度。我試圖準確找出一個成員是在什麼深度,例如:如何在序言中找到成員在列表中的深度?
?- memberDepth(a, [b, c, [d], [[e, f, [], [g], a], j], [k]], Depth).
Depth = 3 .
因此,基本上,它發現「A」列表中的第一個實例的深度。如果成員不存在,它會返回深度= 0。這也將是有用的,如果我能找到該成員的所有實例的深度,從而,例如:
?- memberDepthAll(a, [b, c, [a], [[e], a], [[a]]], Depth).
Depth = 2 ;
Depth = 2 ;
Depth = 3 ;
Depth = 0 ;
false.
我很新的序言,所以任何幫助將不勝感激。
標記爲家庭作業。這個問題非常相似,其實—事實上是相同的,實際上—到今天上午的問題,http://stackoverflow.com/questions/9287942/prolog-list-search,海報維護它的地方是他自己的東西。我很懷疑。 – 2012-02-16 01:04:20