我學習Prolog的一個大學考試,我有這個練習的問題: Implement the predicate not_member(X,L) that is TRUE if the element X does not belong to the list L . 如果我的推論是正確的,我已經找到了解決辦法: % FACT (BASE CASE): It is TRUE that X is not in
我開始學習Prolog。該程序試圖獲取給定元素的所有事件: occurences(_, [], Res):- Res is [].
occurences(X, [X|T], Res):-
occurences(X,T,TMP),
Res is [X,TMP].
occurences(X, [_|T], Res):- occurences(X,T,Res).
但這裏是錯誤
是什麼這之間的區別: X \= Y
和這段代碼: dif(X, Y)
我認爲他們應該做的相同,但他們不相同。這裏的例子: n_puta(L, N, X) :- nputa(L, N, 0, X).
nputa([], N, C, _) :- N = C.
nputa([G|R], N, C, X) :- G = X, nputa(R, N, Y, X), C is Y - 1.
np