有人可以帮助我只是执行递归prolog函数的基础知识..
append([],X,X). % base append([X|Y],Z,[X|W]) :- append(Y,Z,W). %recursive % base case addup([], 0). % sum of the empty list of numbers is zero % recursive case: if the base-case rule does not match, this one must: addup([FirstNumber | RestOfList], Total) :- addup(RestOfList, TotalOfRest), % add up the numbers in RestOfList Total is FirstNumber + TotalOfRest.有人可以用英语或C / C ++ / Java解释一下这些步骤。 我实际上更愿意看到像追加或反转的东西..我主要只是操纵变量列表而不是整数..(我试图通过追加10次...呃)。
can someone please help me just w/ the basics on performing recursive prolog functions..
append([],X,X). % base append([X|Y],Z,[X|W]) :- append(Y,Z,W). %recursive % base case addup([], 0). % sum of the empty list of numbers is zero % recursive case: if the base-case rule does not match, this one must: addup([FirstNumber | RestOfList], Total) :- addup(RestOfList, TotalOfRest), % add up the numbers in RestOfList Total is FirstNumber + TotalOfRest.Can someone explain either in English or in C/C++/Java whatever.. how the steps. I actually would prefer to see something like append or reverse.. I'm mostly just manipulating lists of variables instead of integers.. (I've tried to work through append like 10 times.. ugh).
最满意答案
免费在线书“立即学习Prolog”有一节专门解释追加的步骤:
http://cs.union.edu/~striegnk/learn-prolog-now/html/node47.html#subsec.l6.defining.append
The free online book "Learn Prolog Now" has a section dedicated to explaining the steps that append performs:
http://cs.union.edu/~striegnk/learn-prolog-now/html/node47.html#subsec.l6.defining.append
更多推荐
发布评论