Hi everybody, I'm having a little problem with finding sum of nested list in Prolog. So far what I have is
totalSum(,0). totalSum([H|T],S):- totalSum(T,Sum), S is Sum + H. totalSum([H|T],S):- totalSum(H,Sum1), totalSum(T,Sum2), S is Sum1+Sum2.
With first two predicates, I have no problems getting sum of not-nested list. Anybody with a tip as to how I can modify the third predicate so that it can handle nested list? I've tried passing off [H] instead of just H and many other but it hasn't worked so far. Any comment would be deeply appreciated.