5 ms·
> CL makes it hard not to write recursive. Say what? Are you sure that you don't mean Scheme? CL has LOOP…
by wtbob 12y ago
> CL makes it hard not to write recursive.
Say what? Are you sure that you don't mean Scheme? CL has LOOP…
- ScottBurson 12y ago> CL has LOOP... Oh gawd. The biggest wart on the language. Let's just agree that it's controversial :-)
- lispm 12y agoBlame 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.
- ScottBurson 12y agoThe 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.
- lispm 12y ago> 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.
- ScottBurson 12y ago> 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.
- ScottBurson 12y agoAh 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.
- lispm 12y agoBtw., if you haven't seen it, here is an overview: http://0branch.com/notes/tco-cl.html http://0branch.com/notes/tco-cl.html Btw., Symbolics Genera also did not support TCO. ;-)
- ScottBurson 12y agoThe 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 :-)
- enupten 12y agoIterate is so much cooler! defmacro-clause has been a godsend for my work.