diff options
author | Rich Hickey <richhickey@gmail.com> | 2009-01-25 20:30:13 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2009-01-25 20:30:13 +0000 |
commit | daab7f25995d9922f04a3b43d9a5e8d5fefcfa43 (patch) | |
tree | 2c359071966ce04ae3098f81d39c4289e4d4d7a6 | |
parent | 6254b8d8262a4159c73abb435300c2bef3cbca34 (diff) |
Made Atream.Iter an IFn, so can act as generatorstreams
-rw-r--r-- | src/clj/clojure/core.clj | 13 | ||||
-rw-r--r-- | src/jvm/clojure/lang/AStream.java | 5 |
2 files changed, 8 insertions, 10 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj index 6527f926..caa3669a 100644 --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -1299,7 +1299,7 @@ (. ref (touch)) (. ref (get))) -(def #^{:tag clojure.lang.Closer} *io-context* nil) +(def *io-context* nil) (defmacro sync "transaction-flags => TBD, pass nil for now @@ -1316,8 +1316,6 @@ (. clojure.lang.LockingTransaction (runInTransaction (fn [] ~@body))))) - - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; fn stuff ;;;;;;;;;;;;;;;; @@ -1995,17 +1993,14 @@ "If an io! block occurs in a transaction, throws an IllegalStateException, else runs body in an implicit do. If the first expression in body is a literal string, will use that as the - exception message. Establishes a dynamic io context for use with io-scope." + exception message." [& body] (let [message (when (string? (first body)) (first body)) body (if message (rest body) body)] `(if (clojure.lang.LockingTransaction/isRunning) (throw (new IllegalStateException ~(or message "I/O in transaction"))) - (binding [*io-context* (clojure.lang.Closer.)] - (try - ~@body - (finally - (.close *io-context*))))))) + (binding [*io-context* true] + ~@body)))) (def *scope* nil) diff --git a/src/jvm/clojure/lang/AStream.java b/src/jvm/clojure/lang/AStream.java index bfad8a14..94b1905d 100644 --- a/src/jvm/clojure/lang/AStream.java +++ b/src/jvm/clojure/lang/AStream.java @@ -47,7 +47,7 @@ final public class AStream implements Seqable, Streamable, Sequential { return iter = new Iter(this); } - static public class Iter { + static public class Iter extends AFn{ final AStream s; Iter(AStream s) { @@ -96,6 +96,9 @@ final public class AStream implements Seqable, Streamable, Sequential { } } + public Object invoke(Object arg1) throws Exception { + return next(arg1); + } } static class Seq extends ASeq { |