tag:blogger.com,1999:blog-7056990295646173627.post8368566343631102968..comments2022-12-03T16:26:38.645+00:00Comments on Learning Clojure: How on earth do you program without *recursion*?John Lawrence Aspdenhttp://www.blogger.com/profile/02587130870181071109noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-7056990295646173627.post-71357909525490537792013-09-23T10:22:08.746+01:002013-09-23T10:22:08.746+01:00Here's a macro for transforming to tail calls....Here's a macro for transforming to tail calls. Not complete though.<br /><br />https://github.com/cjfrisz/clojure-tcoAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-7056990295646173627.post-74549179042490696372013-09-23T09:29:59.072+01:002013-09-23T09:29:59.072+01:00We've got recursion, just no TCO, so no real c...We've got recursion, just no TCO, so no real co-recursion.<br /><br />And regarding that rage inducing part of your post -- well memoize[1] gives you your fn wrapped in a LUT accessing fn, so on memo miss you call two fns for every original call. Also first run from 160 down does not utilize cache (all checks miss), because you're going down from 160 without entries in LUT. So you just exhaust your stack faster. Using memoize[1] for recursion is a hack and is not algorithm opaque (=requires hacking around populating the memo map from ground up). As Craig said -- use trampoline[2].<br /><br />[1] http://clojuredocs.org/clojure_core/clojure.core/memoize<br />[2] http://clojuredocs.org/clojure_core/clojure.core/trampolineSMGhttps://www.blogger.com/profile/08618550249386447191noreply@blogger.comtag:blogger.com,1999:blog-7056990295646173627.post-69119269711870598502013-09-23T02:25:04.737+01:002013-09-23T02:25:04.737+01:00You mean, like this? http://clojuredocs.org/clojur...You mean, like this? http://clojuredocs.org/clojure_core/clojure.core/trampoline <br /><br />:)Craig Anderahttps://www.blogger.com/profile/17084199593129216563noreply@blogger.com