3 ms·
Any word on tail-call optimization? Clojure's recur macro is pretty clever but true compiler-level support for recursion would be nice.
by drunkpotato 17y ago
Any word on tail-call optimization? Clojure's recur macro is pretty clever but true compiler-level support for recursion would be nice.
- Xurinos 17y agoI have not played with Clojure since it was introduced, but I have a question about recur or tail recursion. Here is a trivial CL example (nontrivial might be approaches to parsing): (defun find-nth-match (test from n) (if (= n 0) from (martial-n test (1+ from) n))) (defun martial-n (test from n) (find-nth-match test from (if (funcall test from) (1- n) n))) (find-nth-match #'evenp 1 5) => 10 The idea is that tail recursion is not just recursing into the exact same function you appear to be in. Is this available with current clojure? Can recur help me somehow?
- rarrrrrr 17y agoFor mutual recursion, you need to use trampoline. http://groups.google.com/group/clojure/browse_frm/thread/6257cbc4454bcb85/7d5fd827cd549080#7d5fd827cd549080 http://groups.google.com/group/clojure/browse_frm/thread/625...
- cgrand-net 17y agoNo recur won't help you: it's only for self tail recursion, not for mutual tail-recursive calls. You can use a trampoline or refactor your code.
- dangrover 17y agoOne time Guy Steele was speaking at my school, and a professor asked him about why Java did not have tail recursion, and Steele said it was something he'd lobbied for but wasn't able to make it in the final spec.
- papercrane 17y agoTail-call optimization is part of the Da Vinci project. I have no idea if it's on track for Java 7. http://openjdk.java.net/projects/mlvm/subprojects.html#TailCall http://openjdk.java.net/projects/mlvm/subprojects.html#TailC...