Netherbeast
Programmer
Im new to this language and am having a hard time manipulating atoms in the list.
All im trying to do is add the numbers of a given list, say like add([2, 3, 4], Total).
and the Total = 9.
I can count how many elements are in the list using this code:
len([], 0).
len([CAR|CDR], X) :- len(CDR, X1), X is X1+1.
but getting it to add all the numbers is harder than I thought.
Thanks in advance
All im trying to do is add the numbers of a given list, say like add([2, 3, 4], Total).
and the Total = 9.
I can count how many elements are in the list using this code:
len([], 0).
len([CAR|CDR], X) :- len(CDR, X1), X is X1+1.
but getting it to add all the numbers is harder than I thought.
Thanks in advance