我想要计算列表中出现多少个g项,下面是我现在正在尝试的代码,但返回时我得到了错误。Prolog计算列表中的元素
g(E) :- memberchk(E, [apple, orange, pear, grape, lycee, pineapple,dragonfruit]).
countFruit([], No):- write(' >> No of Fruits : '), write(No), nl.
countFruit([H|T], No) :- not(g(H)), countFruit(T,No).
countFruit([H|T], No) :- No1 is No+1, countFruit(T,No1).
?countFruit(H,0). (H is a list).
嗨,我能和你聊聊吗? – user236501
@ user236501 - 你想聊什么? – Enigmativity
澄清打印元素问题 – user236501