diff options
author | Chouser <chouser@n01se.net> | 2009-02-17 20:42:30 +0000 |
---|---|---|
committer | Chouser <chouser@n01se.net> | 2009-02-17 20:42:30 +0000 |
commit | d5701c377f826266d19e21ce11398616d63f25bb (patch) | |
tree | f7212ede149f60323a697e5834b9fa369eb8c73f | |
parent | ab67c84237f052fea57d7cbfc45d7908026f46fa (diff) |
Merged lazy branch into trunk:
svn merge -r472:477 ../branches/lazy/
-rw-r--r-- | src/clojure/contrib/duck_streams.clj | 12 | ||||
-rw-r--r-- | src/clojure/contrib/json/write.clj | 8 | ||||
-rw-r--r-- | src/clojure/contrib/seq_utils.clj | 12 | ||||
-rw-r--r-- | src/clojure/contrib/str_utils.clj | 13 | ||||
-rw-r--r-- | src/clojure/contrib/test_is.clj | 4 |
5 files changed, 28 insertions, 21 deletions
diff --git a/src/clojure/contrib/duck_streams.clj b/src/clojure/contrib/duck_streams.clj index 68d94c47..781449f1 100644 --- a/src/clojure/contrib/duck_streams.clj +++ b/src/clojure/contrib/duck_streams.clj @@ -1,7 +1,7 @@ ;;; duck_streams.clj -- duck-typed I/O streams for Clojure ;; by Stuart Sierra, http://stuartsierra.com/ -;; January 10, 2009 +;; February 16, 2009 ;; Copyright (c) Stuart Sierra, 2008. All rights reserved. The use ;; and distribution terms for this software are covered by the Eclipse @@ -26,6 +26,9 @@ ;; CHANGE LOG ;; +;; February 16, 2009: (lazy branch) fixed read-lines to work with lazy +;; Clojure. +;; ;; January 10, 2009: added *default-encoding*, so streams are always ;; opened as UTF-8. ;; @@ -169,9 +172,10 @@ closes the reader AFTER YOU CONSUME THE ENTIRE SEQUENCE." [f] (let [read-line (fn this [#^BufferedReader rdr] - (if-let [line (.readLine rdr)] - (lazy-cons line (this rdr)) - (.close rdr)))] + (lazy-seq + (if-let [line (.readLine rdr)] + (cons line (this rdr)) + (.close rdr))))] (read-line (reader f)))) (defn slurp* diff --git a/src/clojure/contrib/json/write.clj b/src/clojure/contrib/json/write.clj index c9e6852b..6983ad78 100644 --- a/src/clojure/contrib/json/write.clj +++ b/src/clojure/contrib/json/write.clj @@ -43,9 +43,9 @@ (loop [x s] (when (first x) (print-json (first x)) - (when (rest x) + (when (next x) (print ",") - (recur (rest x))))) + (recur (next x))))) (print "]")) (defmethod print-json :object [m] @@ -56,9 +56,9 @@ (print-json k) (print ":") (print-json v)) - (when (rest x) + (when (next x) (print ",") - (recur (rest x))))) + (recur (next x))))) (print "}")) (defn json-str diff --git a/src/clojure/contrib/seq_utils.clj b/src/clojure/contrib/seq_utils.clj index 36a8e07d..939905f4 100644 --- a/src/clojure/contrib/seq_utils.clj +++ b/src/clojure/contrib/seq_utils.clj @@ -77,7 +77,8 @@ (when-let [s (seq coll)] (let [fv (f (first s)) run (take-while #(= fv (f %)) s)] - (lazy-cons run (partition-by f (drop (count run) s)))))) + (lazy-seq + (cons run (partition-by f (drop (count run) s))))))) (defn frequencies "Returns a map from distinct items in coll to the number of times @@ -106,7 +107,7 @@ not be recursive." [binding-form expr & rec-exprs] `(let [rec-rest# (atom nil) - result# (lazy-cons ~expr (force @rec-rest#)) + result# (lazy-seq (cons ~expr (force @rec-rest#))) ~binding-form result#] (swap! rec-rest# (constantly (delay (lazy-cat ~@rec-exprs)))) result#)) @@ -137,9 +138,10 @@ "Lazily break s into chunks of length n (or less, for the final chunk)." [n s] - (when (seq s) - (lazy-cons (take n s) - (partition-all n (drop n s))))) + (lazy-seq + (when (seq s) + (cons (take n s) + (partition-all n (drop n s)))))) (defn shuffle "Return a random permutation of coll" diff --git a/src/clojure/contrib/str_utils.clj b/src/clojure/contrib/str_utils.clj index 74a5266e..d24bbb05 100644 --- a/src/clojure/contrib/str_utils.clj +++ b/src/clojure/contrib/str_utils.clj @@ -35,12 +35,13 @@ [#^Pattern re string] (let [m (re-matcher re string)] ((fn step [prevend] - (if (.find m) - (lazy-cons (.subSequence string prevend (.start m)) - (lazy-cons (re-groups m) - (step (+ (.start m) (count (.group m)))))) - (when (< prevend (.length string)) - (list (.subSequence string prevend (.length string)))))) + (lazy-seq + (if (.find m) + (cons (.subSequence string prevend (.start m)) + (cons (re-groups m) + (step (+ (.start m) (count (.group m)))))) + (when (< prevend (.length string)) + (list (.subSequence string prevend (.length string))))))) 0))) (defn re-gsub diff --git a/src/clojure/contrib/test_is.clj b/src/clojure/contrib/test_is.clj index aac934be..23bcae24 100644 --- a/src/clojure/contrib/test_is.clj +++ b/src/clojure/contrib/test_is.clj @@ -391,7 +391,7 @@ ;; Asserts that evaluating expr throws an exception of class c. ;; Returns the exception thrown. (let [klass (second form) - body (rrest form)] + body (nthnext form 2)] `(try ~@body (report :fail ~msg '~form nil) (catch ~klass e# @@ -405,7 +405,7 @@ ;; (with re-matches) the regular expression re. (let [klass (nth form 1) re (nth form 2) - body (nthrest form 3)] + body (nthnext form 3)] `(try ~@body (report :fail ~msg '~form nil) (catch ~klass e# |