News for hackers. Stuff that matters.
Re:Tell HN: We are trying to get tail calls into the WebAsse... by kamaal on Tuesday July 12, 2022 @12:02PM (#32071876)
I think its Rich Hickey who said something to the effect that tail calls are so fundamental that the underlying platform should be providing them.
Re:Tell HN: We are trying to get tail calls into the WebAsse... by convolvatron on Tuesday July 12, 2022 @01:00PM (#32072779)
tail calls are so fundamental that its trivial to build a call-push, return-pop stack calling protocol on top of them, but not the converse
Re:Tell HN: We are trying to get tail calls into the WebAsse... by kaba0 on Tuesday July 12, 2022 @02:05PM (#32073634)
Could you point me to some further info on this?
Re:Tell HN: We are trying to get tail calls into the WebAsse... by convolvatron on Tuesday July 12, 2022 @02:24PM (#32073872)
sorry, its kind of ... basic?

the kind of generalized tail call I'm talking about is generally referred to as a continuation. its easiest to think of it as a jump. so you can imagine that if we have jump and a stack register, we can push+jump and thats the same as 'call'. we can pop+jump and thats the same as 'return'. since 'call' and 'return' have side effects, we cant really use them to replace jump.

so thats really straightforward, but things do get a bit screwy. if we can support arbitrary jumps, and the frame storage (arguments + locals) cant necessarily go on a stack because our frames might have arbitrary liftimes, so we cant reclaim them in stack order.

so in a scheme for example we just pull in a gc and track references to these closures and dust our hands off with a smirk. if that doesn't work for you then you have to adopt some kind of framework that lets you know explicitly when these can be released. reference counting is a poor choice here because these references between frames can easily be cyclic.

Re:Tell HN: We are trying to get tail calls into the WebAsse... by morenoh149 on Wednesday July 13, 2022 @03:05AM (#32079776)
Re:Tell HN: We are trying to get tail calls into the WebAsse... by dan-robertson on Wednesday July 13, 2022 @02:55AM (#32079721)
And yet Clojure doesn’t have general tail calls (it has recur which allows something like tail calls so long as they are non-mutually recursive) and seems to do ok.
Re:Tell HN: We are trying to get tail calls into the WebAsse... by kamaal on Wednesday July 13, 2022 @07:07AM (#32081076)
Yes its in the context of Clojure, his point is tail calls should be provided in JVM itself, it can then be added to Clojure.