From: Rich Hickey <richhic...@gmail.com>
Date: Tue, 25 Nov 2008 06:05:06 -0800 (PST)
Local: Tues, Nov 25 2008 9:05 am
Subject: trampoline for mutual recursion
I've added trampoline to ease the conversion/creation of mutually
recursive algorithms in Clojure. Trampolines are a well known technique for implementing TCO - instead
In order to do this I've made the following changes (SVN 1122):
Added clojure.lang.Fn marker interface, used on all true fns.
Here's how it works. Normally, if you have mutual recursion (i.e.
(declare bar)
(defn foo [n]
(defn bar [n]
(foo 1000000)
To convert to a trampoline, simply return closures over your tail
(declare bar)
(defn foo [n]
(defn bar [n]
Then make the top-level call via trampoline:
(trampoline #(foo 1000000))
Rich
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||