[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lua-l
Subject:    Re: Stack traces with tail calls: disabling tail recursion?
From:       Philipp Janda <siffiejoe () gmx ! net>
Date:       2014-02-26 9:54:46
Message-ID: lekdko$tab$1 () ger ! gmane ! org
[Download RAW message or body]

Am 26.02.2014 09:53 schröbte Thijs Schreijer:
> > Well, you could do something like this:
> > 
> > return notail( func( x, y, z ) )
> > 
> > where `notail` is
> > 
> > function notail( ... )
> > return ...
> > end
> > 
> 
> Didn't test it, but I don't think this would work. The original call remains a tail \
> call which remains indistinguishable, and now there is one more level on the stack, \
> but they all point to 'notail' which is also indistinguishable. So back to square \
> one... Or am I missing something?

The call to `notail` is a tailcall, but that's ok because it is only one 
level deep, and it is unlikely to cause an error, so it will never show 
up in a stack trace. `notail`s arguments are evaluated before that, so 
there can't be a tail call involved there (unless your compiler does 
function inlining). It also works in practice, I tested it before posting.

> 
> Some preprocessor magic could do the trick I think.
> 

Disabling it is easy by piping your code through the C preprocessor 
(`#define notail( x ) x`), but adding the `notail` calls in the first 
place is more difficult. I'd probably do that manually using a vim macro.

Philipp


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic