>From SICP: "With a tail-recursive implementation, iteration can be expressed using the ordinary procedure call mechanism". As I understand this, a tail call is a loop with functional notation but not actually a function call. That's why I find this issue difficult to follow, since loops are internal details of a function/method and don't get involved with calls, stack frames, access security, or how the jit-compiled code may or may not be optimized. So there's something key here that I'm missing.
In a little project of mine I plan on doing this (hand-coded with ASM as my compiler doesn't do TCO yet). That seems to work but I wonder what issues may come up. int fact(int n, int r) { if (n == 0) return r; else return fact(n-1, n*r); } 0: iload_0 1: ifne 6 4: iload_1 5: ireturn 6: iload_0 7: istore_2 // temp for n 8: iload_2 9: iconst_1 10: isub 11: istore_0 12: iload_2 13: iload_1 14: imul 15: istore_1 16: goto 0 On Jan 26, 11:20 am, Luc Prefontaine <lprefonta...@softaddicts.ca> wrote: > From what I recall from a previous thread it would require so much byte code > tweaking that > Hot Spot optimizations would become useless. > > You can search the mailing list, you will find a couple of instructive > discussions > about this. > > Luc P. > > On Wed, 26 Jan 2011 10:01:04 -0800 > > Raoul Duke <rao...@gmail.com> wrote: > > On Wed, Jan 26, 2011 at 7:41 AM, Michael Gardner > > <gardne...@gmail.com> wrote: > > > However, the JVM does not support tail-call optimization. > > > Apparently Clojure can't support implicit TCO without support from > > > the JVM > > > always wondered about that also wrt scala etc., am under the > > impression that it is implementable, but it would be too slow? > > -- > Luc P. > > ================ > The rabid Muppet -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en