tjm25225
2019-6-23 10:07:31

@tjm25225 has joined the channel


fkingtop
2019-6-24 02:53:36

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


lexi.lambda
2019-6-24 03:00:24

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


lexi.lambda
2019-6-24 03:02:49

fkingtop
2019-6-24 03:15:08

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


lexi.lambda
2019-6-24 03:16:44

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.


lexi.lambda
2019-6-24 03:17:04

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


lexi.lambda
2019-6-24 03:18:00

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


notjack
2019-6-24 03:26:38

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?


lexi.lambda
2019-6-24 03:28:12

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.


notjack
2019-6-24 03:29:44

¯_(ツ)_/¯


fkingtop
2019-6-24 03:34:57

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


lexi.lambda
2019-6-24 03:36:06

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.


lexi.lambda
2019-6-24 03:36:48

And note that if has two “return” positions.


notjack
2019-6-24 03:37:07

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