summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/clj/clojure/core.clj21
-rw-r--r--src/jvm/clojure/lang/Compiler.java2
-rw-r--r--src/jvm/clojure/lang/Fn.java16
3 files changed, 34 insertions, 5 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj
index 626facb8..d0b040d4 100644
--- a/src/clj/clojure/core.clj
+++ b/src/clj/clojure/core.clj
@@ -1042,8 +1042,6 @@
([state] (new clojure.lang.Agent state))
([state validate-fn] (new clojure.lang.Agent state validate-fn)))
-(defn ! [& args] (throw (new Exception "! is now send. See also send-off")))
-
(defn send
"Dispatch an action to an agent. Returns the agent immediately.
Subsequently, in a thread from a thread pool, the state of the agent
@@ -3399,11 +3397,15 @@
[x]
(instance? Number x))
-(defn fn?
+(defn ifn?
"Returns true if x implements IFn. Note that many data structures
(e.g. sets and maps) implement IFn"
[x] (instance? clojure.lang.IFn x))
+(defn fn?
+ "Returns true if x implements Fn, i.e. is an object created via fn."
+ [x] (instance? clojure.lang.Fn x))
+
(defn integer?
"Returns true if n is an integer"
[n]
@@ -3491,7 +3493,18 @@
"defs the supplied var names with no bindings, useful for making forward declarations."
[& names] `(do ~@(map #(list 'def %) names)))
-
+(defn trampoline [f]
+ "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)))
diff --git a/src/jvm/clojure/lang/Compiler.java b/src/jvm/clojure/lang/Compiler.java
index 55f2152a..24cc87df 100644
--- a/src/jvm/clojure/lang/Compiler.java
+++ b/src/jvm/clojure/lang/Compiler.java
@@ -2988,7 +2988,7 @@ static public class FnExpr implements Expr{
// ClassVisitor cv = new TraceClassVisitor(new CheckClassAdapter(cw), new PrintWriter(System.out));
//ClassVisitor cv = new TraceClassVisitor(cw, new PrintWriter(System.out));
cv.visit(V1_5, ACC_PUBLIC + ACC_SUPER, internalName, null,
- isVariadic() ? "clojure/lang/RestFn" : "clojure/lang/AFn", null);
+ isVariadic() ? "clojure/lang/RestFn" : "clojure/lang/AFn", new String[]{"clojure/lang/Fn"});
String source = (String) SOURCE.get();
int lineBefore = (Integer) LINE_BEFORE.get();
int lineAfter = (Integer) LINE_AFTER.get() + 1;
diff --git a/src/jvm/clojure/lang/Fn.java b/src/jvm/clojure/lang/Fn.java
new file mode 100644
index 00000000..db0657df
--- /dev/null
+++ b/src/jvm/clojure/lang/Fn.java
@@ -0,0 +1,16 @@
+/**
+ * Copyright (c) Rich Hickey. All rights reserved.
+ * The use and distribution terms for this software are covered by the
+ * Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
+ * which can be found in the file CPL.TXT at the root of this distribution.
+ * By using this software in any fashion, you are agreeing to be bound by
+ * the terms of this license.
+ * You must not remove this notice, or any other, from this software.
+ **/
+
+/* rich Nov 25, 2008 */
+
+package clojure.lang;
+
+public interface Fn{
+}