Re: Sys.time( ) and Unix.gettimeofday( ) ;;

"Hendrik Boom [email protected] [ocaml_beginners]" <[email protected]> Mon, 7 Mar 2016 12:54:25 -0500
Newsgroups gmane.comp.lang.ocaml.beginners
Message-ID <[email protected]>
On Mon, Mar 07, 2016 at 11:40:58AM -0600, Douglas Lewit [email protected] [ocaml_beginners] wrote:

> 
> First off, EXACTLY WHAT IS TAIL RECURSION.  I'm assuming that any recursive
> function that uses an "accumulator" is tail-recursive, but that seems like
> a pretty poor definition of tail-recursion.  So exactly what is the key
> difference between normal recursion ( or forward recursion ) and
> tail-recursion?  Is it true that tail-recursion is always faster and more
> efficient than forward recursion?  Are there any notable exceptions to that
> rule?

A recursive call where the caller has nothing more to do upon return 
is tail-recursive.   In this case the callee can just return to the 
caller's caller directly instead of returning to the caller and 
haveiir the caller in turn return to its caller.

The advantages for efficiency is that one less return instructino need 
be execute, and that it saves a stack frame.  The caller's stack frame 
is replaced by the cellee's stack frame.  Deep tail-recursion this 
need not make a huge stack.

-- hendrik