Re:Rust will likely not support tail call optimization
by kvb on Wednesday April 10, 2013 @03:12PM
(#5527356)
Doesn't loop/recur only help in directly self-recursive calls, as opposed to mutual recursion or tail calls to function arguments?
[ Parent
| on HN ]
Re:Rust will likely not support tail call optimization
by anonymoushn on Wednesday April 10, 2013 @03:17PM
(#5527400)
That's correct. It should be possible to have an explicit guarantee of TCO while maintaining the ability to write things that aren't trivially reducible to loops...
Re:Rust will likely not support tail call optimization
by nicolast on Wednesday April 10, 2013 @03:33PM
(#5527512)
Which is +- what Scala allows with an annotation.
Re:Rust will likely not support tail call optimization
by fhars on Wednesday April 10, 2013 @04:33PM
(#5527956)
No, scala's @tailrec annotation only guarantees that calls that can trivially be compiled to loops in fact are. You can't do better on a standard JVM without jumping through hoops (or, rather, trampolines).
Re:Rust will likely not support tail call optimization
by dewitt on Wednesday April 10, 2013 @03:39PM
(#5527543)
Right. In Clojure you'd use an explicit trampoline for stack-free mutual recursion.
Re:Rust will likely not support tail call optimization
by andrewvc on Wednesday April 10, 2013 @04:58PM
(#5528116)
Mutual TCO is really uncommon for what it's worth. Of you need it that bad a trampoline should suffice
Re:Rust will likely not support tail call optimization
by kvb on Wednesday April 10, 2013 @05:07PM
(#5528176)
Direct mutual recursion is somewhat rare (but useful for encoding state machines, for instance). However, using continuation passing style (and tail calls to a continuation argument) to prevent stack overflow is a common idiom in some functional languages (e.g. when mapping over a binary tree).
Re:Rust will likely not support tail call optimization
by derefr on Wednesday April 10, 2013 @10:00PM
(#5529481)
Erlang uses mutual TCO everywhere. All actors/processes are state machines with the function they're in being their current state. To switch states, you just tail-call a new function (which doesn't have to be from the same module you were in.)