Hacker News new | past | comments | ask | show | jobs | submit login

> CL has LOOP...

Oh gawd. The biggest wart on the language.

Let's just agree that it's controversial :-)




Blame Interlisp. We got it from there.

Still the point is, that Common Lisp prefers iteration by loop-like constructs (or higher-order mapping) to recursion, due to the lack of TCO in the standard: DOLIST, DOTIMES, DO, DO*, LOOP, MAPCAR, MAP, ... Many people prefer the design of the ITERATE macro, but LOOP is already included.


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 :-)


Iterate is so much cooler! defmacro-clause has been a godsend for my work.




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

Search: