pls confirm what approach is more efficient



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.

.



Relevant Pages

  • Re: Possible to register a foreign function dynamically?
    ... PL_get_atom_charsprovides a pointer to the actual string that is ... part of the Prolog atom. ... sum += ord&0xFF ...
    (comp.lang.prolog)
  • Re: 7the grade issue
    ... But of course I think Prolog can do a better job. ... list_sum([C|Cs], Sum):- Sum1 is Sum-C, ...
    (comp.lang.prolog)
  • Re: Any way to tail-recurse this?
    ... It can only check that the sum you supply is correct. ... Thanks (my own personal exercise, BTW - not a class I'm taking). ... What, exactly, is the "rule" for activating the ability to have Prolog ... in this case calculating the sum? ...
    (comp.lang.prolog)