aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorStuart Halloway <stu@thinkrelevance.com>2010-04-28 15:56:24 -0400
committerStuart Halloway <stu@thinkrelevance.com>2010-04-28 15:56:24 -0400
commit78ee9b3e64c5ac6082fb223fc79292175e8e4f0c (patch)
tree5905333ee083d6a15fbc13124c1529f6aa66e884 /src/main
parenta1c66df5287776b4397cf3929a5f498fbb34ea32 (diff)
update contrib to remove seq fns promoted to clojure.core
Diffstat (limited to 'src/main')
-rw-r--r--src/main/clojure/clojure/contrib/command_line.clj3
-rw-r--r--src/main/clojure/clojure/contrib/datalog/literals.clj3
-rw-r--r--src/main/clojure/clojure/contrib/lazy_seqs.clj8
-rw-r--r--src/main/clojure/clojure/contrib/monads.clj10
-rw-r--r--src/main/clojure/clojure/contrib/pprint/cl_format.clj4
-rw-r--r--src/main/clojure/clojure/contrib/seq.clj99
-rw-r--r--src/main/clojure/clojure/contrib/seq_utils.clj98
7 files changed, 37 insertions, 188 deletions
diff --git a/src/main/clojure/clojure/contrib/command_line.clj b/src/main/clojure/clojure/contrib/command_line.clj
index b93e251b..907b009f 100644
--- a/src/main/clojure/clojure/contrib/command_line.clj
+++ b/src/main/clojure/clojure/contrib/command_line.clj
@@ -12,11 +12,10 @@
#^{:author "Chris Houser",
:doc "Process command-line arguments according to a given cmdspec"}
clojure.contrib.command-line
- (:require (clojure.contrib [seq :as su]))
(:use (clojure.contrib [string :only (join)])))
(defn make-map [args cmdspec]
- (let [{spec true [rest-sym] false} (su/group-by vector? cmdspec)
+ (let [{spec true [rest-sym] false} (group-by vector? cmdspec)
rest-str (str rest-sym)
key-data (into {} (for [[syms [_ default]] (map #(split-with symbol? %)
(conj spec '[help? h?]))
diff --git a/src/main/clojure/clojure/contrib/datalog/literals.clj b/src/main/clojure/clojure/contrib/datalog/literals.clj
index 8a9e7948..37e5d8c9 100644
--- a/src/main/clojure/clojure/contrib/datalog/literals.clj
+++ b/src/main/clojure/clojure/contrib/datalog/literals.clj
@@ -18,8 +18,7 @@
(:use clojure.contrib.datalog.util)
(:use clojure.contrib.datalog.database)
(:use [clojure.set :only (intersection)])
- (:use [clojure.contrib.set :only (subset?)])
- (:use [clojure.contrib.seq :only (flatten)]))
+ (:use [clojure.contrib.set :only (subset?)]))
;;; Type Definitions
diff --git a/src/main/clojure/clojure/contrib/lazy_seqs.clj b/src/main/clojure/clojure/contrib/lazy_seqs.clj
index dda5aac5..6b42d0a6 100644
--- a/src/main/clojure/clojure/contrib/lazy_seqs.clj
+++ b/src/main/clojure/clojure/contrib/lazy_seqs.clj
@@ -21,7 +21,9 @@
;;
;; == Lazy sequence functions ==
;;
-;; (rotations, partition-all, shuffle, rand-elt moved to seq_utils.clj)
+;; (partition-all, shuffle moved to clojure.core)
+;; (rand-elt moved to clojure.core/rand-nth)
+;; (rotations, moved to seq_utils.clj)
;; (permutations and combinations moved to combinatorics.clj)
;;
;; [1] http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf
@@ -46,7 +48,9 @@
==== Lazy sequence functions ====
- (rotations, partition-all, shuffle, rand-elt moved to seq_utils.clj)
+ (partition-all, shuffle moved to clojure.core)
+ (rand-elt moved to clojure.core/rand-nth)
+ (rotations, rand-elt moved to seq_utils.clj)
(permutations and combinations moved to combinatorics.clj)
[1] http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf
diff --git a/src/main/clojure/clojure/contrib/monads.clj b/src/main/clojure/clojure/contrib/monads.clj
index 8d287105..8f90c01b 100644
--- a/src/main/clojure/clojure/contrib/monads.clj
+++ b/src/main/clojure/clojure/contrib/monads.clj
@@ -268,13 +268,13 @@
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-(defn- flatten
+(defn- flatten*
"Like #(apply concat %), but fully lazy: it evaluates each sublist
only when it is needed."
[ss]
(lazy-seq
(when-let [s (seq ss)]
- (concat (first s) (flatten (rest s))))))
+ (concat (first s) (flatten* (rest s))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
@@ -313,10 +313,10 @@
[m-result (fn m-result-sequence [v]
(list v))
m-bind (fn m-bind-sequence [mv f]
- (flatten (map f mv)))
+ (flatten* (map f mv)))
m-zero (list)
m-plus (fn m-plus-sequence [& mvs]
- (flatten mvs))
+ (flatten* mvs))
])
; Set monad
@@ -543,7 +543,7 @@
(fn m-bind-sequence-t [mv f]
(m-bind mv
(fn [xs]
- (m-fmap flatten
+ (m-fmap flatten*
(m-map f xs))))))
m-zero (with-monad m (m-result (list)))
m-plus (with-monad m
diff --git a/src/main/clojure/clojure/contrib/pprint/cl_format.clj b/src/main/clojure/clojure/contrib/pprint/cl_format.clj
index 145697ff..0488a079 100644
--- a/src/main/clojure/clojure/contrib/pprint/cl_format.clj
+++ b/src/main/clojure/clojure/contrib/pprint/cl_format.clj
@@ -249,7 +249,7 @@ for improved performance"
(clojure.core/format format-str val)
(base-str base val))))
-(defn- group-by [unit lis]
+(defn- group-by* [unit lis]
(reverse
(first
(consume (fn [x] [(seq (reverse (take unit x))) (seq (drop unit x))]) (reverse lis)))))
@@ -261,7 +261,7 @@ for improved performance"
pos-arg (if neg (- arg) arg)
raw-str (opt-base-str base pos-arg)
group-str (if (:colon params)
- (let [groups (map #(apply str %) (group-by (:commainterval params) raw-str))
+ (let [groups (map #(apply str %) (group-by* (:commainterval params) raw-str))
commas (repeat (count groups) (:commachar params))]
(apply str (next (interleave commas groups))))
raw-str)
diff --git a/src/main/clojure/clojure/contrib/seq.clj b/src/main/clojure/clojure/contrib/seq.clj
index 8575e732..5b335be5 100644
--- a/src/main/clojure/clojure/contrib/seq.clj
+++ b/src/main/clojure/clojure/contrib/seq.clj
@@ -14,13 +14,23 @@
;; Change Log
;;
+;; April 28, 2010 (Stuart Halloway):
+;;
+;; * BREAKING CHANGE:
+;; moved to clojure.core: flatten, partition-all, frequencies,
+;; reductions, shuffle, partition-by
+;; moved with semantic changes:
+;; group-by now returns an *unsorted* map
+;; moved with name changes:
+;; rand-elt => clojure.core/rand-nth
+;; includes? => clojure.core/seq-contains?
+;;
;; January 10, 2009 (Stuart Sierra):
;;
;; * BREAKING CHANGE: "includes?" now takes collection as first
;; argument. This is more consistent with Clojure collection
;; functions; see discussion at http://groups.google.com/group/clojure/browse_thread/thread/8b2c8dc96b39ddd7/a8866d34b601ff43
-
(ns
#^{:author "Stuart Sierra (and others)",
:doc "Sequence utilities for Clojure"}
@@ -29,29 +39,12 @@
(java.lang.ref WeakReference)))
-;; 'flatten' written by Rich Hickey,
-;; see http://groups.google.com/group/clojure/msg/385098fabfcaad9b
-(defn flatten
- "Takes any nested combination of sequential things (lists, vectors,
- etc.) and returns their contents as a single, flat sequence.
- (flatten nil) returns nil."
- [x]
- (filter (complement sequential?)
- (rest (tree-seq sequential? seq x))))
-
(defn separate
"Returns a vector:
[ (filter f s), (filter (complement f) s) ]"
[f s]
[(filter f s) (filter (complement f) s)])
-(defn includes?
- "Returns true if coll contains something equal (with =) to x,
- in linear time."
- [coll x]
- (if (some (fn [y] (= y x)) coll)
- true false))
-
(defn indexed
"Returns a lazy sequence of [index, item] pairs, where items come
from 's' and indexes count up from zero.
@@ -60,40 +53,6 @@
[s]
(map vector (iterate inc 0) s))
-;; group-by written by Rich Hickey;
-;; see http://paste.lisp.org/display/64190
-(defn group-by
- "Returns a sorted map of the elements of coll keyed by the result of
- f on each element. The value at each key will be a vector of the
- corresponding elements, in the order they appeared in coll."
- [f coll]
- (reduce
- (fn [ret x]
- (let [k (f x)]
- (assoc ret k (conj (get ret k []) x))))
- (sorted-map) coll))
-
-;; partition-by originally written by Rich Hickey;
-;; modified by Stuart Sierra
-(defn partition-by
- "Applies f to each value in coll, splitting it each time f returns
- a new value. Returns a lazy seq of lazy seqs."
- [f coll]
- (when-let [s (seq coll)]
- (let [fst (first s)
- fv (f fst)
- run (cons fst (take-while #(= fv (f %)) (rest 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
- they appear."
- [coll]
- (reduce (fn [counts x]
- (assoc counts x (inc (get counts x 0))))
- {} coll))
-
;; recursive sequence helpers by Christophe Grand
;; see http://clj-me.blogspot.com/2009/01/recursive-seqs.html
(defmacro rec-seq
@@ -109,19 +68,6 @@
[binding-name & exprs]
`(rec-seq ~binding-name (lazy-cat ~@exprs)))
-
-;; reductions by Chris Houser
-;; see http://groups.google.com/group/clojure/browse_thread/thread/3edf6e82617e18e0/58d9e319ad92aa5f?#58d9e319ad92aa5f
-(defn reductions
- "Returns a lazy seq of the intermediate values of the reduction (as
- per reduce) of coll by f, starting with init."
- ([f coll]
- (if (seq coll)
- (rec-seq self (cons (first coll) (map f self (rest coll))))
- (cons (f) nil)))
- ([f init coll]
- (rec-seq self (cons init (map f self coll)))))
-
(defn rotations
"Returns a lazy seq of all rotations of a seq"
[x]
@@ -132,29 +78,6 @@
(iterate inc 0) x)
(list nil)))
-(defn partition-all
- "Returns a lazy sequence of lists like clojure.core/partition, but may
- include lists with fewer than n items at the end."
- ([n coll]
- (partition-all n n coll))
- ([n step coll]
- (lazy-seq
- (when-let [s (seq coll)]
- (cons (take n s) (partition-all n step (drop step s)))))))
-
-(defn shuffle
- "Return a random permutation of coll"
- [coll]
- (let [l (java.util.ArrayList. coll)]
- (java.util.Collections/shuffle l)
- (seq l)))
-
-(defn rand-elt
- "Return a random element of this seq"
- [s]
- (nth s (rand-int (count s))))
-
-
;; seq-on written by Konrad Hinsen
(defmulti seq-on
"Returns a seq on the object s. Works like the built-in seq but as
diff --git a/src/main/clojure/clojure/contrib/seq_utils.clj b/src/main/clojure/clojure/contrib/seq_utils.clj
index ad913f70..406f0d3e 100644
--- a/src/main/clojure/clojure/contrib/seq_utils.clj
+++ b/src/main/clojure/clojure/contrib/seq_utils.clj
@@ -14,6 +14,17 @@
;; Change Log
;;
+;; April 28, 2010 (Stuart Halloway):
+;;
+;; * BREAKING CHANGE:
+;; moved to clojure.core: flatten, partition-all, frequencies,
+;; reductions, shuffle, partition-by
+;; moved with semantic changes:
+;; group-by now returns an *unsorted* map
+;; moved with name changes:
+;; rand-elt => clojure.core/rand-nth
+;; includes? => clojure.core/seq-contains?
+;;
;; January 10, 2009 (Stuart Sierra):
;;
;; * BREAKING CHANGE: "includes?" now takes collection as first
@@ -29,29 +40,12 @@
(java.lang.ref WeakReference)))
-;; 'flatten' written by Rich Hickey,
-;; see http://groups.google.com/group/clojure/msg/385098fabfcaad9b
-(defn flatten
- "Takes any nested combination of sequential things (lists, vectors,
- etc.) and returns their contents as a single, flat sequence.
- (flatten nil) returns nil."
- [x]
- (filter (complement sequential?)
- (rest (tree-seq sequential? seq x))))
-
(defn separate
"Returns a vector:
[ (filter f s), (filter (complement f) s) ]"
[f s]
[(filter f s) (filter (complement f) s)])
-(defn includes?
- "Returns true if coll contains something equal (with =) to x,
- in linear time."
- [coll x]
- (if (some (fn [y] (= y x)) coll)
- true false))
-
(defn indexed
"Returns a lazy sequence of [index, item] pairs, where items come
from 's' and indexes count up from zero.
@@ -60,40 +54,6 @@
[s]
(map vector (iterate inc 0) s))
-;; group-by written by Rich Hickey;
-;; see http://paste.lisp.org/display/64190
-(defn group-by
- "Returns a sorted map of the elements of coll keyed by the result of
- f on each element. The value at each key will be a vector of the
- corresponding elements, in the order they appeared in coll."
- [f coll]
- (reduce
- (fn [ret x]
- (let [k (f x)]
- (assoc ret k (conj (get ret k []) x))))
- (sorted-map) coll))
-
-;; partition-by originally written by Rich Hickey;
-;; modified by Stuart Sierra
-(defn partition-by
- "Applies f to each value in coll, splitting it each time f returns
- a new value. Returns a lazy seq of lazy seqs."
- [f coll]
- (when-let [s (seq coll)]
- (let [fst (first s)
- fv (f fst)
- run (cons fst (take-while #(= fv (f %)) (rest 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
- they appear."
- [coll]
- (reduce (fn [counts x]
- (assoc counts x (inc (get counts x 0))))
- {} coll))
-
;; recursive sequence helpers by Christophe Grand
;; see http://clj-me.blogspot.com/2009/01/recursive-seqs.html
(defmacro rec-seq
@@ -109,19 +69,6 @@
[binding-name & exprs]
`(rec-seq ~binding-name (lazy-cat ~@exprs)))
-
-;; reductions by Chris Houser
-;; see http://groups.google.com/group/clojure/browse_thread/thread/3edf6e82617e18e0/58d9e319ad92aa5f?#58d9e319ad92aa5f
-(defn reductions
- "Returns a lazy seq of the intermediate values of the reduction (as
- per reduce) of coll by f, starting with init."
- ([f coll]
- (if (seq coll)
- (rec-seq self (cons (first coll) (map f self (rest coll))))
- (cons (f) nil)))
- ([f init coll]
- (rec-seq self (cons init (map f self coll)))))
-
(defn rotations
"Returns a lazy seq of all rotations of a seq"
[x]
@@ -132,29 +79,6 @@
(iterate inc 0) x)
(list nil)))
-(defn partition-all
- "Returns a lazy sequence of lists like clojure.core/partition, but may
- include lists with fewer than n items at the end."
- ([n coll]
- (partition-all n n coll))
- ([n step coll]
- (lazy-seq
- (when-let [s (seq coll)]
- (cons (take n s) (partition-all n step (drop step s)))))))
-
-(defn shuffle
- "Return a random permutation of coll"
- [coll]
- (let [l (java.util.ArrayList. coll)]
- (java.util.Collections/shuffle l)
- (seq l)))
-
-(defn rand-elt
- "Return a random element of this seq"
- [s]
- (nth s (rand-int (count s))))
-
-
;; seq-on written by Konrad Hinsen
(defmulti seq-on
"Returns a seq on the object s. Works like the built-in seq but as