Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The lack of TCO in the standard is almost a non-issue considering that most of the implementations support it. Even Allegro has long done TCO on local calls (calls to functions defined with LABELS or FLET, within the scope of that construct).

The only people who need to worry about TCO are those writing portable libraries. Everyone else can assume it, at least for local calls, which represent 98% of the times that it matters anyway.



> almost a non-issue considering

Almost. It's just that that many implementations support it (ABCL not) and that the language does not support it. TCO interacts badly with many Lisp language features: dynamic binding, unwind-protect, ...

> Everyone else can assume it, at least for local calls, which represent 98% of the times that it matters anyway.

If the right optimizations settings are set.


> TCO interacts badly with many Lisp language features: dynamic binding, unwind-protect, ...

I've never understood this claim. I mean, I understand the technical point: that use of dynamic binding or UNWIND-PROTECT creates a barrier in the stack across which TCO cannot be done. But in practice it seems to me a non-issue. I can't recall ever, in 35 years of Lisp hacking, wanting to write a tail-recursive routine that used one of them on each iteration, in such a way as to cause unbounded stack growth. It just doesn't happen, at least not to me.

Maybe that's partly because I try to keep my usage of dynamic binding to a bare minimum. I think some people overuse it.


Ah right, I forgot about ABCL. I haven't used it, though I keep meaning to give it a try. Hmm, it can't do TCO even on local calls? My code may not run in it, then.


Btw., if you haven't seen it, here is an overview:

http://0branch.com/notes/tco-cl.html

Btw., Symbolics Genera also did not support TCO. ;-)


The overview is useful -- thanks. I see Allegro now does full TCO. Either that wasn't true when I was using it (a dozen years ago) or we just didn't have the right optimize switch settings to turn it on. In any case, I thought that the strategy of doing TCO only on local calls was pretty good -- it let me write loops tail-recursively with LABELS, but didn't significantly impact debugging because only local call frames got deleted.

I'm well aware that the LispMs did not do TCO -- I owned several (starting with a CADR) and still have an XL1200 rusting in my closet :-)




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: