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).
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…