pls confirm what approach is more efficient
- From: mneuhaber22@xxxxxxxxxx
- Date: 16 Jan 2006 20:23:48 -0800
Hello, as I delved deeper into Prolog I encountered coroutining.
The task below is to sum the elements in a list.
Assuming a very large input list, please confirm (or deny) my belief
that sum1 is more efficient because of the tail recursion than sum2.
Efficiency here is defined to mean that less computer resources must be
consumed to arrive at the result.
I promise I will not spam the group with stupid questions unless it's
really important to ask.
sum1([], S) :- S = 0.
sum1([H|T], S) :- freeze(S1, S is S1 + H), sum1(T, S1).
sum2([], S) :- S = 0.
sum2([H|T], S) :- sum2(T, S1), S is S1 + H.
.
- Follow-Ups:
- Re: pls confirm what approach is more efficient
- From: Bart Demoen
- Re: pls confirm what approach is more efficient
- Prev by Date: comp.lang.prolog Frequently Asked Questions
- Next by Date: Re: pls confirm what approach is more efficient
- Previous by thread: problem:4x4magicSquare in prolog
- Next by thread: Re: pls confirm what approach is more efficient
- Index(es):
Relevant Pages
|
|