Version française
Home     About     Download     Resources     Contact us    
Browse thread
Warning on not-tail recursive functions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Julien Moutinho <julien.moutinho@g...>
Subject: Re: [Caml-list] Warning on not-tail recursive functions
On Sat, Aug 04, 2007 at 02:34:21PM +0200, Oliver Bandel wrote:
> Zitat von Brian Hurt <bhurt@spnz.org>:
> > On Sat, 4 Aug 2007, tmp123@menta.net wrote:
> > > Please, knows someone if "ocamlopt" can print a warning message when a
> > > recursive function is not tail recursive, and code with the "jmp"
> > > optimization has not been generated?.
> >
> > The problem is that I often write recursive functions which are not tail
> > recursive, and that's OK.
Ibid.

> > The rules for what is or is not tail recursive are pretty simple.  Boiled
> > down, they are:
> > 1) The tail call must not be within a try expression
> > 2) You can not do anything except return, uninspected and unmodified, the
> > returned value from the call.
I agree Mr.Hurt.

> Does ignore REALLY ignore the values (does not generate them), so that
> this call is like a true tail-call,
No, [ignore] is not a macro, so it always triggers the calculation of its argument.
Think about ignore as if it would be [let ignore _ = ()]
Note however that it is not truly the case, and that [ignore == ignore] is false,
since [ignore] is actually defined as an external value
[external ignore : 'a -> unit = "%ignore"]

> or will the maybe_tailcall
> generate and give back results to the ignore-call and then
> ignore throws away the stuff (then it would be NO tailcall).
Yes, AFAICS with the -S option, neither [ignore] nor [let _ = your_rec_fun in ()]
are segregated from the other functions to produce jumps.
And I perfectly understand that the Inrians work on more important
optimizations than those.