diff options
author | Rich Hickey <richhickey@gmail.com> | 2009-02-14 19:05:50 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2009-02-14 19:05:50 +0000 |
commit | 20331a1681ebc7ba714d0e55563cb51d143c1afc (patch) | |
tree | e6eb1e8ddcb65237ec78bdd636a9f043d084b0d7 | |
parent | 8c59f860762c7b202f0926be401a19e031bfa110 (diff) |
[lazy] renamed rest to next, renamed more to rest
39 files changed, 729 insertions, 737 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj index 3cdeb73c..1c164fe3 100644 --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -49,13 +49,13 @@ #^{:arglists '([coll]) :doc "Returns a seq of the items after the first. Calls seq on its argument. If there are no more items, returns nil."} - rest (fn rest [x] (. clojure.lang.RT (rest x)))) + next (fn next [x] (. clojure.lang.RT (next x)))) (def #^{:arglists '([coll]) :doc "Returns a seqable collection of the items after the first. May return nil. Calls seq on its argument."} - more (fn more [x] (. clojure.lang.RT (more x)))) + rest (fn rest [x] (. clojure.lang.RT (more x)))) (def #^{:arglists '([coll x] [coll x & xs]) @@ -66,13 +66,13 @@ ([coll x] (. clojure.lang.RT (conj coll x))) ([coll x & xs] (if xs - (recur (conj coll x) (first xs) (rest xs)) + (recur (conj coll x) (first xs) (next xs)) (conj coll x))))) (def - #^{:doc "Same as (first (rest x))" + #^{:doc "Same as (first (next x))" :arglists '([x])} - second (fn second [x] (first (rest x)))) + second (fn second [x] (first (next x)))) (def #^{:doc "Same as (first (first x))" @@ -80,19 +80,19 @@ ffirst (fn ffirst [x] (first (first x)))) (def - #^{:doc "Same as (rest (first x))" + #^{:doc "Same as (next (first x))" :arglists '([x])} - rfirst (fn rfirst [x] (rest (first x)))) + nfirst (fn nfirst [x] (next (first x)))) (def - #^{:doc "Same as (first (rest x))" + #^{:doc "Same as (first (next x))" :arglists '([x])} - frest (fn frest [x] (first (rest x)))) + fnext (fn fnext [x] (first (next x)))) (def - #^{:doc "Same as (rest (rest x))" + #^{:doc "Same as (next (next x))" :arglists '([x])} - rrest (fn rrest [x] (rest (rest x)))) + nnext (fn nnext [x] (next (next x)))) (def #^{:arglists '([coll]) @@ -141,7 +141,7 @@ (if (sequence? (first fdecl)) (loop [ret [] fdecl fdecl] (if fdecl - (recur (conj ret (first (first fdecl))) (rest fdecl)) + (recur (conj ret (first (first fdecl))) (next fdecl)) (seq ret))) (list (first fdecl))))) @@ -157,7 +157,7 @@ ([map key val & kvs] (let [ret (assoc map key val)] (if kvs - (recur ret (first kvs) (second kvs) (rrest kvs)) + (recur ret (first kvs) (second kvs) (nnext kvs)) ret))))) ;;;;;;;;;;;;;;;;; metadata ;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -179,8 +179,8 @@ #^{:arglists '([coll]) :doc "Return the last item in coll, in linear time"} last (fn last [s] - (if (rest s) - (recur (rest s)) + (if (next s) + (recur (next s)) (first s)))) (def @@ -188,8 +188,8 @@ :doc "Return a sequence of all but the last item in coll, in linear time"} butlast (fn butlast [s] (loop [ret [] s s] - (if (rest s) - (recur (conj ret (first s)) (rest s)) + (if (next s) + (recur (conj ret (first s)) (next s)) (seq ret))))) (def @@ -204,13 +204,13 @@ {:doc (first fdecl)} {}) fdecl (if (string? (first fdecl)) - (rest fdecl) + (next fdecl) fdecl) m (if (map? (first fdecl)) (conj m (first fdecl)) m) fdecl (if (map? (first fdecl)) - (rest fdecl) + (next fdecl) fdecl) fdecl (if (vector? (first fdecl)) (list fdecl) @@ -303,7 +303,7 @@ (defmacro if [tst & etc] (if* (assert-if-lazy-seq?) (let [tstsym 'G__0_0] - (list 'let [tstsym tst] + (list 'clojure.core/let [tstsym tst] (list 'if* (list 'clojure.core/instance? clojure.lang.LazySeq tstsym) (list 'throw (list 'new Exception "LazySeq used in 'if'")) (cons 'if* (cons tstsym etc))))) @@ -350,7 +350,7 @@ ([x & ys] ((fn [#^StringBuilder sb more] (if more - (recur (. sb (append (str (first more)))) (rest more)) + (recur (. sb (append (str (first more)))) (next more)) (str sb))) (new StringBuilder #^String (str x)) ys))) @@ -389,19 +389,19 @@ [& clauses] (when clauses (list 'if (first clauses) - (if (rest clauses) + (if (next clauses) (second clauses) (throw (IllegalArgumentException. "cond requires an even number of forms"))) - (cons 'clojure.core/cond (rest (rest clauses)))))) + (cons 'clojure.core/cond (next (next clauses)))))) (defn spread {:private true} [arglist] (cond (nil? arglist) nil - (nil? (rest arglist)) (seq (first arglist)) - :else (cons (first arglist) (spread (rest arglist))))) + (nil? (next arglist)) (seq (first arglist)) + :else (cons (first arglist) (spread (next arglist))))) (defn apply "Applies fn f to the argument list formed by prepending args to argseq." @@ -437,16 +437,16 @@ (lazy-seq (let [s (seq x)] (if s - (cons (first s) (concat (more s) y)) + (cons (first s) (concat (rest s) y)) y)))) ([x y & zs] (let [cat (fn cat [xys zs] (lazy-seq (let [xys (seq xys)] (if xys - (cons (first xys) (cat (more xys) zs)) + (cons (first xys) (cat (rest xys) zs)) (when zs - (cat (first zs) (rest zs)))))))] + (cat (first zs) (next zs)))))))] (cat (concat x y) zs)))) ;;;;;;;;;;;;;;;;at this point all the support for syntax-quote exists;;;;;;;;;;;;;;;;;;;;;; @@ -488,8 +488,8 @@ ([x y] (clojure.lang.Util/equiv x y)) ([x y & more] (if (= x y) - (if (rest more) - (recur y (first more) (rest more)) + (if (next more) + (recur y (first more) (next more)) (= y (first more))) false))) @@ -519,9 +519,9 @@ the value of the last expr. (and) returns true." ([] true) ([x] x) - ([x & rest] + ([x & next] `(let [and# ~x] - (if and# (and ~@rest) and#)))) + (if and# (and ~@next) and#)))) (defmacro or "Evaluates exprs one at a time, from left to right. If a form @@ -530,9 +530,9 @@ value of the last expression. (or) returns nil." ([] nil) ([x] x) - ([x & rest] + ([x & next] `(let [or# ~x] - (if or# or# (or ~@rest))))) + (if or# or# (or ~@next))))) ;;;;;;;;;;;;;;;;;;; sequence fns ;;;;;;;;;;;;;;;;;;;;;;; (defn reduce @@ -550,7 +550,7 @@ (if s (if (instance? clojure.lang.IReduce s) (. #^clojure.lang.IReduce s (reduce f)) - (reduce f (first s) (rest s))) + (reduce f (first s) (next s))) (f)))) ([f val coll] (let [s (seq coll)] @@ -558,7 +558,7 @@ (. #^clojure.lang.IReduce s (reduce f val)) ((fn [f val s] (if s - (recur f (f val (first s)) (rest s)) + (recur f (f val (first s)) (next s)) val)) f val s))))) @@ -617,8 +617,8 @@ ([x y] (. clojure.lang.Numbers (lt x y))) ([x y & more] (if (< x y) - (if (rest more) - (recur y (first more) (rest more)) + (if (next more) + (recur y (first more) (next more)) (< y (first more))) false))) @@ -631,8 +631,8 @@ ([x y] (. clojure.lang.Numbers (lte x y))) ([x y & more] (if (<= x y) - (if (rest more) - (recur y (first more) (rest more)) + (if (next more) + (recur y (first more) (next more)) (<= y (first more))) false))) @@ -645,8 +645,8 @@ ([x y] (. clojure.lang.Numbers (gt x y))) ([x y & more] (if (> x y) - (if (rest more) - (recur y (first more) (rest more)) + (if (next more) + (recur y (first more) (next more)) (> y (first more))) false))) @@ -659,8 +659,8 @@ ([x y] (. clojure.lang.Numbers (gte x y))) ([x y & more] (if (>= x y) - (if (rest more) - (recur y (first more) (rest more)) + (if (next more) + (recur y (first more) (next more)) (>= y (first more))) false))) @@ -672,8 +672,8 @@ ([x y] (. clojure.lang.Numbers (equiv x y))) ([x y & more] (if (== x y) - (if (rest more) - (recur y (first more) (rest more)) + (if (next more) + (recur y (first more) (next more)) (== y (first more))) false))) @@ -883,7 +883,7 @@ "For a list or queue, returns a new list/queue without the first item, for a vector, returns a new vector without the last item. If the collection is empty, throws an exception. Note - not the same - as rest/butlast." + as next/butlast." [coll] (. clojure.lang.RT (pop coll))) (defn nth @@ -920,7 +920,7 @@ ([map key & ks] (let [ret (dissoc map key)] (if ks - (recur ret (first ks) (rest ks)) + (recur ret (first ks) (next ks)) ret)))) (defn disj @@ -932,7 +932,7 @@ ([set key & ks] (let [ret (disj set key)] (if ks - (recur ret (first ks) (rest ks)) + (recur ret (first ks) (next ks)) ret)))) (defn find @@ -949,7 +949,7 @@ (if entry (conj ret entry) ret) - (rest keys))) + (next keys))) ret))) (defn keys @@ -1022,7 +1022,7 @@ list already. If there are more forms, inserts the first form as the second item in second form, etc." ([x form] (if (sequence? form) - `(~(first form) ~x ~@(rest form)) + `(~(first form) ~x ~@(next form)) (list form x))) ([x form & more] `(-> (-> ~x ~form) ~@more))) @@ -1039,16 +1039,16 @@ (first options) nil) options (if (string? (first options)) - (rest options) + (next options) options) m (if (map? (first options)) (first options) {}) options (if (map? (first options)) - (rest options) + (next options) options) dispatch-fn (first options) - options (rest options) + options (next options) m (assoc m :tag 'clojure.lang.MultiFn) m (if docstring (assoc m :doc docstring) @@ -1092,7 +1092,7 @@ `(do (when-not ~(first pairs) (throw (IllegalArgumentException. ~(str fnname " requires " (second pairs))))) - ~(let [more (rrest pairs)] + ~(let [more (nnext pairs)] (when more (list* `assert-args fnname more))))) @@ -1141,7 +1141,7 @@ (loop [ret [] vvs (seq var-vals)] (if vvs (recur (conj (conj ret `(var ~(first vvs))) (second vvs)) - (rest (rest vvs))) + (next (next vvs))) (seq ret))))] `(do (. clojure.lang.Var (pushThreadBindings (hash-map ~@(var-ize bindings)))) @@ -1392,7 +1392,7 @@ exception message." [& body] (let [message (when (string? (first body)) (first body)) - body (if message (rest body) body)] + body (if message (next body) body)] `(if (clojure.lang.LockingTransaction/isRunning) (throw (new IllegalStateException ~(or message "I/O in transaction"))) (do ~@body)))) @@ -1408,9 +1408,9 @@ [& fs] (let [fs (reverse fs)] (fn [& args] - (loop [ret (apply (first fs) args) fs (rest fs)] + (loop [ret (apply (first fs) args) fs (next fs)] (if fs - (recur ((first fs) ret) (rest fs)) + (recur ((first fs) ret) (next fs)) ret))))) (defn partial @@ -1435,7 +1435,7 @@ [pred coll] (if (seq coll) (and (pred (first coll)) - (recur pred (rest coll))) + (recur pred (next coll))) true)) (def @@ -1452,7 +1452,7 @@ (some #{:fred} coll)" [pred coll] (when (seq coll) - (or (pred (first coll)) (recur pred (rest coll))))) + (or (pred (first coll)) (recur pred (next coll))))) (def #^{:tag Boolean @@ -1470,25 +1470,25 @@ ([f coll] (lazy-seq (when-let [s (seq coll)] - (cons (f (first s)) (map f (more s)))))) + (cons (f (first s)) (map f (rest s)))))) ([f c1 c2] (lazy-seq (let [s1 (seq c1) s2 (seq c2)] (when (and s1 s2) (cons (f (first s1) (first s2)) - (map f (more s1) (more s2))))))) + (map f (rest s1) (rest s2))))))) ([f c1 c2 c3] (lazy-seq (let [s1 (seq c1) s2 (seq c2) s3 (seq c3)] (when (and s1 s2 s3) (cons (f (first s1) (first s2) (first s3)) - (map f (more s1) (more s2) (more s3))))))) + (map f (rest s1) (rest s2) (rest s3))))))) ([f c1 c2 c3 & colls] (let [step (fn step [cs] (lazy-seq (let [ss (map seq cs)] (when (every? identity ss) - (cons (map first ss) (step (map more ss)))))))] + (cons (map first ss) (step (map rest ss)))))))] (map #(apply f %) (step (conj colls c3 c2 c1)))))) (defn mapcat @@ -1504,8 +1504,8 @@ (let [step (fn [p c] (when-let [s (seq c)] (if (p (first s)) - (clojure.lang.Cons. (first s) (filter p (more s))) - (recur p (more s)))))] + (clojure.lang.Cons. (first s) (filter p (rest s))) + (recur p (rest s)))))] (lazy-seq (step pred coll)))) @@ -1522,7 +1522,7 @@ (lazy-seq (when (pos? n) (when-let [s (seq coll)] - (cons (first s) (take (dec n) (more s))))))) + (cons (first s) (take (dec n) (rest s))))))) (defn take-while "Returns a lazy sequence of successive items from coll while @@ -1531,7 +1531,7 @@ (lazy-seq (when-let [s (seq coll)] (when (pred (first s)) - (cons (first s) (take-while pred (more s))))))) + (cons (first s) (take-while pred (rest s))))))) (defn drop "Returns a lazy sequence of all but the first n items in coll." @@ -1539,7 +1539,7 @@ (let [step (fn [n coll] (let [s (seq coll)] (if (and (pos? n) s) - (recur (dec n) (more s)) + (recur (dec n) (rest s)) s)))] (lazy-seq (step n coll)))) @@ -1555,7 +1555,7 @@ (let [step (fn [pred coll] (let [s (seq coll)] (if (and s (pred (first s))) - (recur pred (more s)) + (recur pred (rest s)) s)))] (lazy-seq (step pred coll)))) @@ -1634,8 +1634,8 @@ vs (seq vals)] (if (and ks vs) (recur (assoc map (first ks) (first vs)) - (rest ks) - (rest vs)) + (next ks) + (next vs)) map))) (defn line-seq @@ -1716,27 +1716,27 @@ ~(if more-groups (apply emit more-groups) `(do ~@body))) - (recur (rest sq#)))))))] + (recur (next sq#)))))))] (apply emit groups))) (defn dorun "When lazy sequences are produced via functions that have side effects, any effects other than those needed to produce the first element in the seq do not occur until the seq is consumed. dorun can - be used to force any effects. Walks through the successive rests of + be used to force any effects. Walks through the successive nexts of the seq, does not retain the head and returns nil." ([coll] (when (and (seq coll) (or (first coll) true)) - (recur (rest coll)))) + (recur (next coll)))) ([n coll] (when (and (seq coll) (pos? n) (or (first coll) true)) - (recur (dec n) (rest coll))))) + (recur (dec n) (next coll))))) (defn doall "When lazy sequences are produced via functions that have side effects, any effects other than those needed to produce the first element in the seq do not occur until the seq is consumed. doall can - be used to force any effects. Walks through the successive rests of + be used to force any effects. Walks through the successive nexts of the seq, retains the head and returns it, thus causing the entire seq to reside in memory at one time." ([coll] @@ -1812,7 +1812,7 @@ c (symbol (.substring n (inc dot)))] (. ns (importClass c (. clojure.lang.RT (classForName (name spec)))))) (let [pkg (first spec) - classes (rest spec)] + classes (next spec)] (doseq [c classes] (. ns (importClass c (. clojure.lang.RT (classForName (str pkg "." c))))))))))) @@ -1834,7 +1834,7 @@ [to from] (let [ret to items (seq from)] (if items - (recur (conj ret (first items)) (rest items)) + (recur (conj ret (first items)) (next items)) ret))) (defn #^{:private true} @@ -2081,7 +2081,7 @@ `(let [~gx ~x] ~@(map (fn [f] (if (sequence? f) - `(~(first f) ~gx ~@(rest f)) + `(~(first f) ~gx ~@(next f)) `(~f ~gx))) forms) ~gx))) @@ -2209,7 +2209,7 @@ (loop [i 0 xs (seq coll)] (when xs (aset ret i (to-array (first xs))) - (recur (inc i) (rest xs)))) + (recur (inc i) (next xs)))) ret)) (defn macroexpand-1 @@ -2300,8 +2300,8 @@ (loop [ret {} es (seq amap)] (if es (if (pred (keyfn (first es))) - (recur (assoc ret (key (first es)) (val (first es))) (rest es)) - (recur ret (rest es))) + (recur (assoc ret (key (first es)) (val (first es))) (next es)) + (recur ret (next es))) ret))) (defn find-ns @@ -2485,12 +2485,12 @@ ([] (. clojure.lang.PersistentArrayMap EMPTY)) ([& keyvals] (new clojure.lang.PersistentArrayMap (to-array keyvals)))) -(defn nthrest - "Returns the nth rest of coll, (seq coll) when n is 0." +(defn nthnext + "Returns the nth next of coll, (seq coll) when n is 0." [coll n] (loop [n n xs (seq coll)] (if (and xs (pos? n)) - (recur (dec n) (rest xs)) + (recur (dec n) (next xs)) xs))) @@ -2508,16 +2508,16 @@ (if (seq bs) (let [firstb (first bs)] (cond - (= firstb '&) (recur (pb ret (second bs) (list `nthrest gvec n)) + (= firstb '&) (recur (pb ret (second bs) (list `nthnext gvec n)) n - (rrest bs) + (nnext bs) true) (= firstb :as) (pb ret (second bs) gvec) :else (if seen-rest? (throw (new Exception "Unsupported binding form, only :as can follow & parameter")) (recur (pb ret firstb (list `nth gvec n nil)) (inc n) - (rest bs) + (next bs) seen-rest?)))) ret)))) pmap @@ -2539,7 +2539,7 @@ (recur (pb ret bb (if has-default (list `get gmap bk (defaults bb)) (list `get gmap bk))) - (rest bes))) + (next bes))) ret))))] (cond (symbol? b) (-> bvec (conj b) (conj v)) @@ -2566,15 +2566,15 @@ "(fn name? [params* ] exprs*) (fn name? ([params* ] exprs*)+) - params => positional-params* , or positional-params* & rest-param + params => positional-params* , or positional-params* & next-param positional-param => binding-form - rest-param => binding-form + next-param => binding-form name => symbol Defines a function" [& sigs] (let [name (if (symbol? (first sigs)) (first sigs) nil) - sigs (if name (rest sigs) sigs) + sigs (if name (next sigs) sigs) sigs (if (vector? (first sigs)) (list sigs) sigs) psig (fn [sig] (let [[params & body] sig] @@ -2585,9 +2585,9 @@ lets []] (if params (if (symbol? (first params)) - (recur (rest params) (conj new-params (first params)) lets) + (recur (next params) (conj new-params (first params)) lets) (let [gparam (gensym "p__")] - (recur (rest params) (conj new-params gparam) + (recur (next params) (conj new-params gparam) (-> lets (conj (first params)) (conj gparam))))) `(~new-params (let ~lets @@ -2677,10 +2677,10 @@ `(let [iterys# ~(emit more-groups) fs# (seq (iterys# ~next-seq))] (if fs# - (concat fs# (~giter (more ~gxs))) - (recur (more ~gxs)))) - `(cons ~expr (~giter (more ~gxs)))) - (recur (more ~gxs)))))))))))] + (concat fs# (~giter (rest ~gxs))) + (recur (rest ~gxs)))) + `(cons ~expr (~giter (rest ~gxs)))) + (recur (rest ~gxs)))))))))))] `(let [iter# ~(emit (to-groups seq-exprs))] (iter# ~(second seq-exprs)))))) @@ -2967,8 +2967,8 @@ ((fn [[f :as xs] seen] (when-let [s (seq xs)] (if (seen f) - (recur (more s) seen) - (cons f (step (more s) (conj seen f)))))) + (recur (rest s) seen) + (cons f (step (rest s) (conj seen f)))))) xs seen)))] (step coll #{}))) @@ -3006,7 +3006,7 @@ HALF_EVEN, UP, DOWN and UNNECESSARY; it defaults to HALF_UP." [precision & exprs] (let [[body rm] (if (= (first exprs) :rounding) - [(rest (rest exprs)) + [(next (next exprs)) `((. java.math.RoundingMode ~(second exprs)))] [exprs nil])] `(binding [*math-context* (java.math.MathContext. ~precision ~@rm)] @@ -3026,12 +3026,12 @@ (let [include (bound-fn sc test key)] (if (#{> >=} test) (when-let [[e :as s] (. sc seqFrom key true)] - (if (include e) s (rest s))) + (if (include e) s (next s))) (take-while include (. sc seq true))))) ([#^clojure.lang.Sorted sc start-test start-key end-test end-key] (when-let [[e :as s] (. sc seqFrom start-key true)] (take-while (bound-fn sc end-test end-key) - (if ((bound-fn sc start-test start-key) e) s (rest s)))))) + (if ((bound-fn sc start-test start-key) e) s (next s)))))) (defn rsubseq "sc must be a sorted collection, test(s) one of <, <=, > or @@ -3041,12 +3041,12 @@ (let [include (bound-fn sc test key)] (if (#{< <=} test) (when-let [[e :as s] (. sc seqFrom key false)] - (if (include e) s (rest s))) + (if (include e) s (next s))) (take-while include (. sc seq false))))) ([#^clojure.lang.Sorted sc start-test start-key end-test end-key] (when-let [[e :as s] (. sc seqFrom end-key false)] (take-while (bound-fn sc start-test start-key) - (if ((bound-fn sc end-test end-key) e) s (rest s)))))) + (if ((bound-fn sc end-test end-key) e) s (next s)))))) (defn repeatedly "Takes a function of no args, presumably with side effects, and returns an infinite @@ -3407,7 +3407,7 @@ `(~(symbol "clojure.core" (clojure.core/name kname)) ~@(map #(list 'quote %) args))) docstring (when (string? (first references)) (first references)) - references (if docstring (rest references) references) + references (if docstring (next references) references) name (if docstring (with-meta name (assoc (meta name) :doc docstring)) @@ -3415,7 +3415,7 @@ gen-class-clause (first (filter #(= :gen-class (first %)) references)) gen-class-call (when gen-class-clause - (list* `gen-class :name (.replace (str name) \- \_) :impl-ns name :main true (rest gen-class-clause))) + (list* `gen-cla |