
@tjm25225 has joined the channel

Hi guys, is there a way to check if a call is tail call ?

DrRacket draws pink arrows to indicate tail calls if you hover over the open parens for a lambda or function definition.


@lexi.lambda I mean tail call detection algorithm
. I want to do tco.

Oh. Well, tail position is just “return” position, so: the last expression in a lambda body, the last expression in a begin
, the last expression in a let
body, etc.

A tail call is a function call that is in tail position.

It might be helpful to read the definition of “tail position” in the reference: https://docs.racket-lang.org/reference/eval-model.html#%28tech._tail._position%29

If you’re trying to detect tail calls in arbitrary source code for static analysis reasons then you’ll have to deal with macros, probably by expanding them away and ignoring residual code that’s not syntax-original?

I was guessing OP was doing this for non-Racket code, since they said they “want to do tco,” and Racket already has proper tail calls, but I could be wrong.

¯_(ツ)_/¯

@lexi.lambda @notjack I want to compile core-scheme to js and do some optimizations. e.g. transform self tail recursion to loop.

Then yes, you should be able to find all expressions in tail position by just recursively traversing the “return” positions in the AST until you find a function call.

And note that if
has two “return” positions.

What’s “core-scheme”? Scheme with all macros expanded?
