lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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