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: Oliver Bandel <oliver@f...>
Subject: Re: [Caml-list] Warning on not-tail recursive functions
Zitat von Brian Hurt <bhurt@spnz.org>:

>
>
> On Sat, 4 Aug 2007, tmp123@menta.net wrote:
>
> > Hello,
> >
> > 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.


Well, during I've learned on tail-recursion I have habituized to always
write functions tailrecursive, so that when I want to try a non-tailrec
function, I really have to think a log about it...

...really!

It's only a way of what one is used to do very often.
If you get accustomed to tailrec function writing,
then it's "natural".

Before I knew how to write tailrec code, it was the other way around
and I had to tjink a lot about how to get it tailrec.



[...]
>
> 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.


What ist with a

  ...
   ignore (maybe_tailcall())
  ...



???

Does ignore REALLY ignore the values (does not generate them), so that
this call is like a true tail-call, 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).


Ciao,
   Oliver