aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChouser <chouser@n01se.net>2009-02-17 22:08:16 +0000
committerChouser <chouser@n01se.net>2009-02-17 22:08:16 +0000
commit81b9e71effbaf6aa2945cd684802d87c762cdcdd (patch)
tree716012900fd73190e11d8869a4efbc44fa231f7a /src
parentd7695aa72adcdbdffe396b87d8f0a2dea363ffc1 (diff)
Batch of changes for lazier clojure.
Diffstat (limited to 'src')
-rw-r--r--src/clojure/contrib/command_line.clj2
-rw-r--r--src/clojure/contrib/error_kit.clj6
-rw-r--r--src/clojure/contrib/lazy_xml.clj39
-rw-r--r--src/clojure/contrib/repl_utils.clj2
-rw-r--r--src/clojure/contrib/shell_out.clj4
-rw-r--r--src/clojure/contrib/zip_filter.clj8
-rw-r--r--src/clojure/contrib/zip_filter/xml.clj2
7 files changed, 33 insertions, 30 deletions
diff --git a/src/clojure/contrib/command_line.clj b/src/clojure/contrib/command_line.clj
index 4f4302f5..a323ee69 100644
--- a/src/clojure/contrib/command_line.clj
+++ b/src/clojure/contrib/command_line.clj
@@ -30,7 +30,7 @@
:else (if-let [found (key-data keybase)]
(if (= \? (last (:sym found)))
(recur r (assoc cmdmap (:sym found) true))
- (recur (rest r) (assoc cmdmap (:sym found)
+ (recur (next r) (assoc cmdmap (:sym found)
(if (or (nil? r) (= \- (ffirst r)))
(:default found)
(first r)))))
diff --git a/src/clojure/contrib/error_kit.clj b/src/clojure/contrib/error_kit.clj
index 908caa64..2e52fdea 100644
--- a/src/clojure/contrib/error_kit.clj
+++ b/src/clojure/contrib/error_kit.clj
@@ -86,7 +86,7 @@
((:unhandled err) err)
(let [[{:keys [htag] :as handler}] hs]
(if (and htag (not (isa? err-tag htag)))
- (recur (rest hs))
+ (recur (next hs))
(let [rtn ((:hfunc handler) err)]
(if-not (vector? rtn)
(throw-to handler (list rtn))
@@ -97,7 +97,7 @@
(do (prn *continues*) (throw
(Exception.
(str "Unbound continue name " (rtn 1))))))
- ::do-not-handle (recur (rest hs))
+ ::do-not-handle (recur (next hs))
(throw-to handler (list rtn)))))))))))
(defmacro raise
@@ -176,7 +176,7 @@
:when (= (resolve type) #'bind-continue)]
[(list `quote (first more))
`{:blockid '~blockid
- :rfunc (fn ~@(rest more))}]))]
+ :rfunc (fn ~@(next more))}]))]
`(try
(binding [*handler-stack* (list* ~@handlers @#'*handler-stack*)
*continues* (merge @#'*continues* ~@continues)]
diff --git a/src/clojure/contrib/lazy_xml.clj b/src/clojure/contrib/lazy_xml.clj
index b44f1b45..6abc212e 100644
--- a/src/clojure/contrib/lazy_xml.clj
+++ b/src/clojure/contrib/lazy_xml.clj
@@ -10,7 +10,6 @@
(ns clojure.contrib.lazy-xml
(:require [clojure.xml :as xml])
- (:use [clojure.contrib.fcase :only (case)])
(:import (org.xml.sax Attributes InputSource)
(org.xml.sax.helpers DefaultHandler)
(javax.xml.parsers SAXParserFactory)
@@ -25,7 +24,7 @@
(defn- parse-seq-pull [& _])
(try (load "lazy_xml/with_pull")
(catch Exception e
- (when-not (re-seq #"XmlPullParser" (str e))
+ (when-not (re-find #"XmlPullParser" (str e))
(throw e))))
(defn startparse-sax [s ch]
@@ -51,9 +50,10 @@
agt (agent nil)
s (if (instance? Reader s) (InputSource. s) s)
step (fn step []
- (if-let [x (.take q)]
- (lazy-cons x (step))
- @agt)) ;will be nil, touch agent just to propagate errors
+ (lazy-seq
+ (if-let [x (.take q)]
+ (cons x (step))
+ @agt))) ;will be nil, touch agent just to propagate errors
keep-alive (WeakReference. step)
enqueue (fn [x]
(if (.get keep-alive)
@@ -84,22 +84,25 @@
(defstruct element :tag :attrs :content)
-(def mktree)
-
-(defn- siblings
- [[event & rst :as s]]
- (case (:type event)
- :characters (lazy-cons (:str event) (siblings rst))
- :start-element (let [t (mktree s)]
- (lazy-cons (first t) (siblings (rest t))))
- :end-element [rst]))
+(declare mktree)
+
+(defn- siblings [coll]
+ (lazy-seq
+ (when-let [s (seq coll)]
+ (let [event (first s)]
+ (condp = (:type event)
+ :characters (cons (:str event) (siblings (rest s)))
+ :start-element (let [t (mktree s)]
+ (cons (first t) (siblings (rest t))))
+ :end-element [(rest s)])))))
(defn- mktree
[[elem & events]]
- (let [sibs (siblings events)]
- (lazy-cons
- (struct element (:name elem) (:attrs elem) (drop-last sibs))
- (last sibs))))
+ (lazy-seq
+ (let [sibs (siblings events)]
+ (cons
+ (struct element (:name elem) (:attrs elem) (drop-last sibs))
+ (last sibs)))))
(defn parse-trim
"Parses the source s, which can be a File, InputStream or String
diff --git a/src/clojure/contrib/repl_utils.clj b/src/clojure/contrib/repl_utils.clj
index f1107d52..5ba37373 100644
--- a/src/clojure/contrib/repl_utils.clj
+++ b/src/clojure/contrib/repl_utils.clj
@@ -78,7 +78,7 @@
(:member (nth members selector))
(let [pred (if (ifn? selector)
selector
- #(re-seq (re-pattern (str "(?i)" selector)) (:name %)))]
+ #(re-find (re-pattern (str "(?i)" selector)) (:name %)))]
(println "=== " (Modifier/toString (.getModifiers c)) c " ===")
(doseq [[i m] (indexed members)]
(when (pred m)
diff --git a/src/clojure/contrib/shell_out.clj b/src/clojure/contrib/shell_out.clj
index 768bb34b..79bebd4b 100644
--- a/src/clojure/contrib/shell_out.clj
+++ b/src/clojure/contrib/shell_out.clj
@@ -50,8 +50,8 @@
(if-not args
opts
(if (keyword? arg)
- (recur (rrest args) (assoc opts arg (second args)))
- (recur (rest args) (update-in opts [:cmd] conj arg))))))
+ (recur (nnext args) (assoc opts arg (second args)))
+ (recur (next args) (update-in opts [:cmd] conj arg))))))
(defn- as-env-key [arg]
"Helper so that callers can use symbols, keywords, or strings
diff --git a/src/clojure/contrib/zip_filter.clj b/src/clojure/contrib/zip_filter.clj
index ca11cb59..8b78be04 100644
--- a/src/clojure/contrib/zip_filter.clj
+++ b/src/clojure/contrib/zip_filter.clj
@@ -23,11 +23,11 @@
(defn right-locs
"Returns a lazy sequence of locations to the right of loc, starting with loc."
- [loc] (when loc (lazy-cons (auto false loc) (right-locs (zip/right loc)))))
+ [loc] (lazy-seq (when loc (cons (auto false loc) (right-locs (zip/right loc))))))
(defn left-locs
"Returns a lazy sequence of locations to the left of loc, starting with loc."
- [loc] (when loc (lazy-cons (auto false loc) (left-locs (zip/left loc)))))
+ [loc] (lazy-seq (when loc (cons (auto false loc) (left-locs (zip/left loc))))))
(defn leftmost?
"Returns true if there are no more nodes to the left of location loc."
@@ -55,13 +55,13 @@
(defn descendants
"Returns a lazy sequence of all descendants of location loc, in
depth-first order, left-to-right, starting with loc."
- [loc] (lazy-cons (auto false loc) (mapcat descendants (children loc))))
+ [loc] (lazy-seq (cons (auto false loc) (mapcat descendants (children loc)))))
(defn ancestors
"Returns a lazy sequence of all ancestors of location loc, starting
with loc and proceeding to loc's parent node and on through to the
root of the tree."
- [loc] (when loc (lazy-cons (auto false loc) (ancestors (zip/up loc)))))
+ [loc] (lazy-seq (when loc (cons (auto false loc) (ancestors (zip/up loc))))))
(defn- fixup-apply
"Calls (pred loc), and then converts the result to the 'appropriate'
diff --git a/src/clojure/contrib/zip_filter/xml.clj b/src/clojure/contrib/zip_filter/xml.clj
index 1455acaa..e6e8cb3d 100644
--- a/src/clojure/contrib/zip_filter/xml.clj
+++ b/src/clojure/contrib/zip_filter/xml.clj
@@ -52,7 +52,7 @@
"Returns a query predicate that matches a node when its xml content
matches the query expresions given."
#^{:private true}
- [preds] (fn [loc] (and (apply xml-> loc preds) (list loc))))
+ [preds] (fn [loc] (and (seq (apply xml-> loc preds)) (list loc))))
(defn xml->
"The loc is passed to the first predicate. If the predicate returns