summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/clj/clojure/core.clj25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj
index d0b040d4..b896754c 100644
--- a/src/clj/clojure/core.clj
+++ b/src/clj/clojure/core.clj
@@ -3493,18 +3493,21 @@
"defs the supplied var names with no bindings, useful for making forward declarations."
[& names] `(do ~@(map #(list 'def %) names)))
-(defn trampoline [f]
+(defn trampoline
"trampoline can be used to convert algorithms requiring mutual
- recursion without stack consumption. f must be a fn of no
- arguments. Calls f. If f returns a fn, calls that fn with no
- arguments, and continues to repeat, until the return value is not a
- fn, then returns that non-fn value. Note that if you want to return
- a fn as a final value, you must wrap it in some data structure and
- unpack it after trampoline returns."
- (let [ret (f)]
- (if (fn? ret)
- (recur ret)
- ret)))
+ recursion without stack consumption. Calls f with supplied args, if
+ any. If f returns a fn, calls that fn with no arguments, and
+ continues to repeat, until the return value is not a fn, then
+ returns that non-fn value. Note that if you want to return a fn as a
+ final value, you must wrap it in some data structure and unpack it
+ after trampoline returns."
+ ([f]
+ (let [ret (f)]
+ (if (fn? ret)
+ (recur ret)
+ ret)))
+ ([f & args]
+ (trampoline #(apply f args))))