Any way to tail-recurse this?
- From: pineapple.link@xxxxxxxxx
- Date: Tue, 21 Aug 2007 15:49:30 -0700
Just adding up numbers in a list. I already know you could do the
below better, cleaner, and in fewer steps. My question is how to tail-
recurse it, if possible.
(the first arg in the predicate is the list, the second is the
"total")
Thanks.
---------------------
addlist([],0).
addlist([X],X).
addlist([H|[X]],Y) :- Y is H+X. %This pred is probably unnecessary,
but aids my understanding
addlist([H1|[H2|T]],Y1) :- addlist([H2|T],Y2), Y1 is H1+Y2.
.
- Follow-Ups:
- Re: Any way to tail-recurse this?
- From: pineapple . link
- Re: Any way to tail-recurse this?
- Prev by Date: Re: List of chars
- Next by Date: Re: Which free Prolog is the best one ?
- Previous by thread: List of chars
- Next by thread: Re: Any way to tail-recurse this?
- Index(es):