prolog中的递归(列表中)(recursion in prolog (on lists))

编程入门 行业动态 更新时间:2024-10-26 10:39:41
prolog中的递归(列表中)(recursion in prolog (on lists))

有人可以帮助我只是执行递归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

更多推荐

本文发布于:2023-07-31 07:12:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1341894.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:递归   列表中   prolog   recursion   lists

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!