From 2ede388a9267d175bfaa7781ee9d57532eb4f20f Mon Sep 17 00:00:00 2001 From: Stuart Sierra Date: Wed, 20 Jan 2010 15:39:56 -0500 Subject: Move source files into Maven-style directory structure. --- src/clojure/contrib/accumulators.clj | 324 ---- src/clojure/contrib/accumulators/examples.clj | 93 - src/clojure/contrib/agent_utils.clj | 35 - src/clojure/contrib/apply_macro.clj | 43 - src/clojure/contrib/base64.clj | 99 -- src/clojure/contrib/classpath.clj | 39 - src/clojure/contrib/combinatorics.clj | 164 -- src/clojure/contrib/command_line.clj | 122 -- src/clojure/contrib/complex_numbers.clj | 293 ---- src/clojure/contrib/cond.clj | 34 - src/clojure/contrib/condition.clj | 147 -- src/clojure/contrib/condition/Condition.clj | 43 - src/clojure/contrib/condition/example.clj | 66 - src/clojure/contrib/core.clj | 81 - src/clojure/contrib/core/tests.clj | 36 - src/clojure/contrib/dataflow.clj | 508 ------ src/clojure/contrib/datalog.clj | 64 - src/clojure/contrib/datalog/database.clj | 287 --- src/clojure/contrib/datalog/example.clj | 116 -- src/clojure/contrib/datalog/literals.clj | 414 ----- src/clojure/contrib/datalog/magic.clj | 128 -- src/clojure/contrib/datalog/rules.clj | 207 --- src/clojure/contrib/datalog/softstrat.clj | 161 -- src/clojure/contrib/datalog/tests/test.clj | 45 - .../contrib/datalog/tests/test_database.clj | 153 -- .../contrib/datalog/tests/test_literals.clj | 187 -- src/clojure/contrib/datalog/tests/test_magic.clj | 72 - src/clojure/contrib/datalog/tests/test_rules.clj | 130 -- .../contrib/datalog/tests/test_softstrat.clj | 233 --- src/clojure/contrib/datalog/tests/test_util.clj | 69 - src/clojure/contrib/datalog/util.clj | 89 - src/clojure/contrib/def.clj | 147 -- src/clojure/contrib/duck_streams.clj | 416 ----- src/clojure/contrib/error_kit.clj | 289 --- src/clojure/contrib/except.clj | 95 - src/clojure/contrib/fcase.clj | 108 -- src/clojure/contrib/find_namespaces.clj | 136 -- src/clojure/contrib/fnmap.clj | 36 - src/clojure/contrib/fnmap/PersistentFnMap.clj | 70 - src/clojure/contrib/gen_html_docs.clj | 539 ------ src/clojure/contrib/generic.clj | 54 - src/clojure/contrib/generic/arithmetic.clj | 201 --- src/clojure/contrib/generic/collection.clj | 116 -- src/clojure/contrib/generic/comparison.clj | 177 -- src/clojure/contrib/generic/functor.clj | 40 - src/clojure/contrib/generic/math_functions.clj | 114 -- src/clojure/contrib/graph.clj | 228 --- src/clojure/contrib/greatest_least.clj | 65 - src/clojure/contrib/http/agent.clj | 379 ---- src/clojure/contrib/http/connection.clj | 59 - src/clojure/contrib/import_static.clj | 63 - src/clojure/contrib/jar.clj | 35 - src/clojure/contrib/java_utils.clj | 223 --- src/clojure/contrib/javadoc.clj | 3 - src/clojure/contrib/javadoc/browse.clj | 50 - src/clojure/contrib/javadoc/browse_ui.clj | 30 - src/clojure/contrib/jmx.clj | 121 -- src/clojure/contrib/jmx/Bean.clj | 35 - src/clojure/contrib/jmx/client.clj | 95 - src/clojure/contrib/jmx/data.clj | 104 -- src/clojure/contrib/jmx/server.clj | 18 - src/clojure/contrib/json/read.clj | 338 ---- src/clojure/contrib/json/write.clj | 193 -- src/clojure/contrib/lazy_seqs.clj | 86 - src/clojure/contrib/lazy_xml.clj | 189 -- src/clojure/contrib/lazy_xml/with_pull.clj | 58 - src/clojure/contrib/load_all.clj | 91 - src/clojure/contrib/logging.clj | 349 ---- src/clojure/contrib/macro_utils.clj | 270 --- src/clojure/contrib/macros.clj | 84 - src/clojure/contrib/map_utils.clj | 55 - src/clojure/contrib/math.clj | 247 --- src/clojure/contrib/math/tests.clj | 118 -- src/clojure/contrib/miglayout.clj | 79 - src/clojure/contrib/miglayout/example.clj | 60 - src/clojure/contrib/miglayout/internal.clj | 120 -- src/clojure/contrib/miglayout/test.clj | 145 -- src/clojure/contrib/mmap.clj | 90 - src/clojure/contrib/mock.clj | 285 --- src/clojure/contrib/mock/test_adapter.clj | 38 - src/clojure/contrib/monadic_io_streams.clj | 145 -- src/clojure/contrib/monads.clj | 580 ------ src/clojure/contrib/monads/examples.clj | 425 ----- src/clojure/contrib/ns_utils.clj | 106 -- src/clojure/contrib/pprint.clj | 35 - src/clojure/contrib/pprint/ColumnWriter.clj | 89 - src/clojure/contrib/pprint/PrettyWriter.clj | 486 ------ src/clojure/contrib/pprint/cl_format.clj | 1843 -------------------- src/clojure/contrib/pprint/dispatch.clj | 447 ----- src/clojure/contrib/pprint/examples/hexdump.clj | 63 - src/clojure/contrib/pprint/examples/json.clj | 142 -- src/clojure/contrib/pprint/examples/multiply.clj | 23 - src/clojure/contrib/pprint/examples/props.clj | 25 - src/clojure/contrib/pprint/examples/show_doc.clj | 50 - src/clojure/contrib/pprint/examples/xml.clj | 117 -- src/clojure/contrib/pprint/pprint_base.clj | 342 ---- src/clojure/contrib/pprint/utilities.clj | 104 -- .../examples_finite_distributions.clj | 209 --- .../contrib/probabilities/examples_monte_carlo.clj | 73 - .../contrib/probabilities/finite_distributions.clj | 203 --- src/clojure/contrib/probabilities/monte_carlo.clj | 240 --- .../contrib/probabilities/random_numbers.clj | 63 - src/clojure/contrib/profile.clj | 110 -- src/clojure/contrib/prxml.clj | 166 -- src/clojure/contrib/repl_ln.clj | 274 --- src/clojure/contrib/repl_utils.clj | 195 --- src/clojure/contrib/repl_utils/javadoc.clj | 83 - src/clojure/contrib/seq_utils.clj | 223 --- src/clojure/contrib/server_socket.clj | 94 - src/clojure/contrib/set.clj | 47 - src/clojure/contrib/shell_out.clj | 146 -- src/clojure/contrib/singleton.clj | 54 - src/clojure/contrib/sql.clj | 203 --- src/clojure/contrib/sql/internal.clj | 194 --- src/clojure/contrib/sql/test.clj | 207 --- src/clojure/contrib/str_utils.clj | 100 -- src/clojure/contrib/str_utils2.clj | 373 ---- src/clojure/contrib/stream_utils.clj | 276 --- src/clojure/contrib/stream_utils/examples.clj | 117 -- src/clojure/contrib/swing_utils.clj | 152 -- src/clojure/contrib/test_contrib.clj | 45 - .../contrib/test_contrib/complex_numbers.clj | 313 ---- src/clojure/contrib/test_contrib/fnmap.clj | 39 - .../contrib/test_contrib/greatest_least.clj | 65 - src/clojure/contrib/test_contrib/java_utils.clj | 10 - src/clojure/contrib/test_contrib/macro_utils.clj | 67 - src/clojure/contrib/test_contrib/mock_test.clj | 131 -- .../test_contrib/mock_test/test_adapter_test.clj | 18 - src/clojure/contrib/test_contrib/monads.clj | 78 - .../contrib/test_contrib/pprint/cl_format.clj | 670 ------- src/clojure/contrib/test_contrib/pprint/helper.clj | 21 - src/clojure/contrib/test_contrib/pprint/pretty.clj | 127 -- .../contrib/test_contrib/seq_utils_test.clj | 127 -- src/clojure/contrib/test_contrib/shell_out.clj | 41 - src/clojure/contrib/test_contrib/str_utils.clj | 33 - src/clojure/contrib/test_contrib/str_utils2.clj | 119 -- src/clojure/contrib/test_contrib/test_dataflow.clj | 90 - src/clojure/contrib/test_contrib/test_graph.clj | 187 -- .../contrib/test_contrib/test_java_utils.clj | 123 -- src/clojure/contrib/test_contrib/test_jmx.clj | 166 -- .../contrib/test_contrib/test_lazy_seqs.clj | 21 - src/clojure/contrib/test_contrib/test_trace.clj | 16 - src/clojure/contrib/test_contrib/walk.clj | 34 - src/clojure/contrib/test_contrib/with_ns_test.clj | 19 - src/clojure/contrib/test_is.clj | 118 -- src/clojure/contrib/trace.clj | 98 -- src/clojure/contrib/types.clj | 275 --- src/clojure/contrib/types/examples.clj | 152 -- src/clojure/contrib/with_ns.clj | 38 - src/clojure/contrib/zip_filter.clj | 92 - src/clojure/contrib/zip_filter/xml.clj | 170 -- 151 files changed, 23750 deletions(-) delete mode 100644 src/clojure/contrib/accumulators.clj delete mode 100644 src/clojure/contrib/accumulators/examples.clj delete mode 100644 src/clojure/contrib/agent_utils.clj delete mode 100644 src/clojure/contrib/apply_macro.clj delete mode 100644 src/clojure/contrib/base64.clj delete mode 100644 src/clojure/contrib/classpath.clj delete mode 100644 src/clojure/contrib/combinatorics.clj delete mode 100644 src/clojure/contrib/command_line.clj delete mode 100644 src/clojure/contrib/complex_numbers.clj delete mode 100644 src/clojure/contrib/cond.clj delete mode 100644 src/clojure/contrib/condition.clj delete mode 100644 src/clojure/contrib/condition/Condition.clj delete mode 100644 src/clojure/contrib/condition/example.clj delete mode 100644 src/clojure/contrib/core.clj delete mode 100644 src/clojure/contrib/core/tests.clj delete mode 100644 src/clojure/contrib/dataflow.clj delete mode 100644 src/clojure/contrib/datalog.clj delete mode 100644 src/clojure/contrib/datalog/database.clj delete mode 100644 src/clojure/contrib/datalog/example.clj delete mode 100644 src/clojure/contrib/datalog/literals.clj delete mode 100644 src/clojure/contrib/datalog/magic.clj delete mode 100644 src/clojure/contrib/datalog/rules.clj delete mode 100644 src/clojure/contrib/datalog/softstrat.clj delete mode 100644 src/clojure/contrib/datalog/tests/test.clj delete mode 100644 src/clojure/contrib/datalog/tests/test_database.clj delete mode 100644 src/clojure/contrib/datalog/tests/test_literals.clj delete mode 100644 src/clojure/contrib/datalog/tests/test_magic.clj delete mode 100644 src/clojure/contrib/datalog/tests/test_rules.clj delete mode 100644 src/clojure/contrib/datalog/tests/test_softstrat.clj delete mode 100644 src/clojure/contrib/datalog/tests/test_util.clj delete mode 100644 src/clojure/contrib/datalog/util.clj delete mode 100644 src/clojure/contrib/def.clj delete mode 100644 src/clojure/contrib/duck_streams.clj delete mode 100644 src/clojure/contrib/error_kit.clj delete mode 100644 src/clojure/contrib/except.clj delete mode 100644 src/clojure/contrib/fcase.clj delete mode 100644 src/clojure/contrib/find_namespaces.clj delete mode 100644 src/clojure/contrib/fnmap.clj delete mode 100644 src/clojure/contrib/fnmap/PersistentFnMap.clj delete mode 100644 src/clojure/contrib/gen_html_docs.clj delete mode 100644 src/clojure/contrib/generic.clj delete mode 100644 src/clojure/contrib/generic/arithmetic.clj delete mode 100644 src/clojure/contrib/generic/collection.clj delete mode 100644 src/clojure/contrib/generic/comparison.clj delete mode 100644 src/clojure/contrib/generic/functor.clj delete mode 100644 src/clojure/contrib/generic/math_functions.clj delete mode 100644 src/clojure/contrib/graph.clj delete mode 100644 src/clojure/contrib/greatest_least.clj delete mode 100644 src/clojure/contrib/http/agent.clj delete mode 100644 src/clojure/contrib/http/connection.clj delete mode 100644 src/clojure/contrib/import_static.clj delete mode 100644 src/clojure/contrib/jar.clj delete mode 100644 src/clojure/contrib/java_utils.clj delete mode 100644 src/clojure/contrib/javadoc.clj delete mode 100644 src/clojure/contrib/javadoc/browse.clj delete mode 100644 src/clojure/contrib/javadoc/browse_ui.clj delete mode 100644 src/clojure/contrib/jmx.clj delete mode 100644 src/clojure/contrib/jmx/Bean.clj delete mode 100644 src/clojure/contrib/jmx/client.clj delete mode 100644 src/clojure/contrib/jmx/data.clj delete mode 100644 src/clojure/contrib/jmx/server.clj delete mode 100644 src/clojure/contrib/json/read.clj delete mode 100644 src/clojure/contrib/json/write.clj delete mode 100644 src/clojure/contrib/lazy_seqs.clj delete mode 100644 src/clojure/contrib/lazy_xml.clj delete mode 100644 src/clojure/contrib/lazy_xml/with_pull.clj delete mode 100644 src/clojure/contrib/load_all.clj delete mode 100644 src/clojure/contrib/logging.clj delete mode 100644 src/clojure/contrib/macro_utils.clj delete mode 100644 src/clojure/contrib/macros.clj delete mode 100644 src/clojure/contrib/map_utils.clj delete mode 100644 src/clojure/contrib/math.clj delete mode 100644 src/clojure/contrib/math/tests.clj delete mode 100644 src/clojure/contrib/miglayout.clj delete mode 100644 src/clojure/contrib/miglayout/example.clj delete mode 100644 src/clojure/contrib/miglayout/internal.clj delete mode 100644 src/clojure/contrib/miglayout/test.clj delete mode 100644 src/clojure/contrib/mmap.clj delete mode 100644 src/clojure/contrib/mock.clj delete mode 100644 src/clojure/contrib/mock/test_adapter.clj delete mode 100644 src/clojure/contrib/monadic_io_streams.clj delete mode 100644 src/clojure/contrib/monads.clj delete mode 100644 src/clojure/contrib/monads/examples.clj delete mode 100644 src/clojure/contrib/ns_utils.clj delete mode 100644 src/clojure/contrib/pprint.clj delete mode 100644 src/clojure/contrib/pprint/ColumnWriter.clj delete mode 100644 src/clojure/contrib/pprint/PrettyWriter.clj delete mode 100644 src/clojure/contrib/pprint/cl_format.clj delete mode 100644 src/clojure/contrib/pprint/dispatch.clj delete mode 100644 src/clojure/contrib/pprint/examples/hexdump.clj delete mode 100644 src/clojure/contrib/pprint/examples/json.clj delete mode 100644 src/clojure/contrib/pprint/examples/multiply.clj delete mode 100644 src/clojure/contrib/pprint/examples/props.clj delete mode 100644 src/clojure/contrib/pprint/examples/show_doc.clj delete mode 100644 src/clojure/contrib/pprint/examples/xml.clj delete mode 100644 src/clojure/contrib/pprint/pprint_base.clj delete mode 100644 src/clojure/contrib/pprint/utilities.clj delete mode 100644 src/clojure/contrib/probabilities/examples_finite_distributions.clj delete mode 100644 src/clojure/contrib/probabilities/examples_monte_carlo.clj delete mode 100644 src/clojure/contrib/probabilities/finite_distributions.clj delete mode 100644 src/clojure/contrib/probabilities/monte_carlo.clj delete mode 100644 src/clojure/contrib/probabilities/random_numbers.clj delete mode 100644 src/clojure/contrib/profile.clj delete mode 100755 src/clojure/contrib/prxml.clj delete mode 100644 src/clojure/contrib/repl_ln.clj delete mode 100644 src/clojure/contrib/repl_utils.clj delete mode 100644 src/clojure/contrib/repl_utils/javadoc.clj delete mode 100644 src/clojure/contrib/seq_utils.clj delete mode 100644 src/clojure/contrib/server_socket.clj delete mode 100644 src/clojure/contrib/set.clj delete mode 100644 src/clojure/contrib/shell_out.clj delete mode 100644 src/clojure/contrib/singleton.clj delete mode 100644 src/clojure/contrib/sql.clj delete mode 100644 src/clojure/contrib/sql/internal.clj delete mode 100644 src/clojure/contrib/sql/test.clj delete mode 100644 src/clojure/contrib/str_utils.clj delete mode 100644 src/clojure/contrib/str_utils2.clj delete mode 100644 src/clojure/contrib/stream_utils.clj delete mode 100644 src/clojure/contrib/stream_utils/examples.clj delete mode 100644 src/clojure/contrib/swing_utils.clj delete mode 100644 src/clojure/contrib/test_contrib.clj delete mode 100644 src/clojure/contrib/test_contrib/complex_numbers.clj delete mode 100644 src/clojure/contrib/test_contrib/fnmap.clj delete mode 100644 src/clojure/contrib/test_contrib/greatest_least.clj delete mode 100644 src/clojure/contrib/test_contrib/java_utils.clj delete mode 100644 src/clojure/contrib/test_contrib/macro_utils.clj delete mode 100644 src/clojure/contrib/test_contrib/mock_test.clj delete mode 100644 src/clojure/contrib/test_contrib/mock_test/test_adapter_test.clj delete mode 100644 src/clojure/contrib/test_contrib/monads.clj delete mode 100644 src/clojure/contrib/test_contrib/pprint/cl_format.clj delete mode 100644 src/clojure/contrib/test_contrib/pprint/helper.clj delete mode 100644 src/clojure/contrib/test_contrib/pprint/pretty.clj delete mode 100644 src/clojure/contrib/test_contrib/seq_utils_test.clj delete mode 100644 src/clojure/contrib/test_contrib/shell_out.clj delete mode 100644 src/clojure/contrib/test_contrib/str_utils.clj delete mode 100644 src/clojure/contrib/test_contrib/str_utils2.clj delete mode 100644 src/clojure/contrib/test_contrib/test_dataflow.clj delete mode 100644 src/clojure/contrib/test_contrib/test_graph.clj delete mode 100644 src/clojure/contrib/test_contrib/test_java_utils.clj delete mode 100644 src/clojure/contrib/test_contrib/test_jmx.clj delete mode 100644 src/clojure/contrib/test_contrib/test_lazy_seqs.clj delete mode 100644 src/clojure/contrib/test_contrib/test_trace.clj delete mode 100644 src/clojure/contrib/test_contrib/walk.clj delete mode 100644 src/clojure/contrib/test_contrib/with_ns_test.clj delete mode 100644 src/clojure/contrib/test_is.clj delete mode 100644 src/clojure/contrib/trace.clj delete mode 100644 src/clojure/contrib/types.clj delete mode 100644 src/clojure/contrib/types/examples.clj delete mode 100644 src/clojure/contrib/with_ns.clj delete mode 100644 src/clojure/contrib/zip_filter.clj delete mode 100644 src/clojure/contrib/zip_filter/xml.clj (limited to 'src/clojure') diff --git a/src/clojure/contrib/accumulators.clj b/src/clojure/contrib/accumulators.clj deleted file mode 100644 index dcd03dd1..00000000 --- a/src/clojure/contrib/accumulators.clj +++ /dev/null @@ -1,324 +0,0 @@ -;; Accumulators - -;; by Konrad Hinsen -;; last updated May 19, 2009 - -;; This module defines various accumulators (list, vector, map, -;; sum, product, counter, and combinations thereof) with a common -;; interface defined by the multimethods add and combine. -;; For each accumulator type, its empty value is defined in this module. -;; Applications typically use this as a starting value and add data -;; using the add multimethod. - -;; Copyright (c) Konrad Hinsen, 2009. All rights reserved. The use -;; and distribution terms for this software are covered by the Eclipse -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) -;; which can be found in the file epl-v10.html at the root of this -;; distribution. By using this software in any fashion, you are -;; agreeing to be bound by the terms of this license. You must not -;; remove this notice, or any other, from this software. - -(ns - #^{:author "Konrad Hinsen" - :doc "A generic accumulator interface and implementations of various - accumulators."} - clojure.contrib.accumulators - (:refer-clojure :exclude (deftype)) - (:use [clojure.contrib.types :only (deftype)]) - (:use [clojure.contrib.def :only (defvar defvar- defmacro-)]) - (:require [clojure.contrib.generic.arithmetic :as ga])) - -(defmulti add - "Add item to the accumulator acc. The exact meaning of adding an - an item depends on the type of the accumulator." - {:arglists '([acc item])} - (fn [acc item] (type acc))) - -(defn add-items - "Add all elements of a collection coll to the accumulator acc." - [acc items] - (reduce add acc items)) - -(defmulti combine - "Combine the values of the accumulators acc1 and acc2 into a - single accumulator of the same type." - {:arglists '([& accs])} - (fn [& accs] (type (first accs)))) - -; -; An ::accumulator type tag is attached to tbe built-in types -; when used as accumulators, and new types are derived from it. -; Multimethods add and combine for ::accumulator sub-dispatch on class. -; We also define generic addition as the combine operation. -; -(let [meta-map {:type ::accumulator}] - (defn- with-acc-tag - [x] - (with-meta x meta-map))) - -(defmethod add ::accumulator - [a e] - ((get-method add (class a)) a e)) - -(defmethod combine ::accumulator - [& as] - (apply (get-method combine (class (first as))) as)) - -(defmethod ga/+ ::accumulator - [x y] - (combine x y)) - -; -; Vector accumulator -; -(defvar empty-vector (with-acc-tag []) - "An empty vector accumulator. Adding an item appends it at the end.") - -(defmethod combine clojure.lang.IPersistentVector - [& vs] - (with-acc-tag (vec (apply concat vs)))) - -(defmethod add clojure.lang.IPersistentVector - [v e] - (with-acc-tag (conj v e))) - -; -; List accumulator -; -(defvar empty-list (with-acc-tag '()) - "An empty list accumulator. Adding an item appends it at the beginning.") - -(defmethod combine clojure.lang.IPersistentList - [& vs] - (with-acc-tag (apply concat vs))) - -(defmethod add clojure.lang.IPersistentList - [v e] - (with-acc-tag (conj v e))) - -; -; Queue accumulator -; -(defvar empty-queue (with-acc-tag clojure.lang.PersistentQueue/EMPTY) - "An empty queue accumulator. Adding an item appends it at the end.") - -(defmethod combine clojure.lang.PersistentQueue - [& vs] - (add-items (first vs) (apply concat (rest vs)))) - -(defmethod add clojure.lang.PersistentQueue - [v e] - (with-acc-tag (conj v e))) - -; -; Set accumulator -; -(defvar empty-set (with-acc-tag #{}) - "An empty set accumulator.") - -(defmethod combine (class empty-set) - [& vs] - (with-acc-tag (apply clojure.set/union vs))) - -(defmethod add (class empty-set) - [v e] - (with-acc-tag (conj v e))) - -; -; String accumulator -; -(defvar empty-string "" - "An empty string accumulator. Adding an item (string or character) - appends it at the end.") - -(defmethod combine java.lang.String - [& vs] - (apply str vs)) - -(defmethod add java.lang.String - [v e] - (str v e)) - -; -; Map accumulator -; -(defvar empty-map (with-acc-tag {}) - "An empty map accumulator. Items to be added must be [key value] pairs.") - -(defmethod combine clojure.lang.IPersistentMap - [& vs] - (with-acc-tag (apply merge vs))) - -(defmethod add clojure.lang.IPersistentMap - [v e] - (with-acc-tag (conj v e))) - -; -; Numerical accumulators: sum, product, minimum, maximum -; -(defmacro- defacc - [name op empty doc-string] - (let [type-tag (keyword (str *ns*) (str name)) - empty-symbol (symbol (str "empty-" name))] - `(let [op# ~op] - (deftype ~type-tag ~name - (fn [~'x] {:value ~'x}) - (fn [~'x] (list (:value ~'x)))) - (derive ~type-tag ::accumulator) - (defvar ~empty-symbol (~name ~empty) ~doc-string) - (defmethod combine ~type-tag [& vs#] - (~name (apply op# (map :value vs#)))) - (defmethod add ~type-tag [v# e#] - (~name (op# (:value v#) e#)))))) - -(defacc sum + 0 - "An empty sum accumulator. Only numbers can be added.") - -(defacc product * 1 - "An empty sum accumulator. Only numbers can be added.") - -; The empty maximum accumulator should have value -infinity. -; This is represented by nil and taken into account in an -; adapted max function. In the minimum accumulator, nil is -; similarly used to represent +infinity. - -(defacc maximum (fn [& xs] - (when-let [xs (seq (filter identity xs))] - (apply max xs))) - nil - "An empty maximum accumulator. Only numbers can be added.") - -(defacc minimum (fn [& xs] - (when-let [xs (seq (filter identity xs))] - (apply min xs))) - nil - "An empty minimum accumulator. Only numbers can be added.") - -; -; Numeric min-max accumulator -; (combination of minimum and maximum) -; -(deftype ::min-max min-max - (fn [min max] {:min min :max max}) - (fn [mm] (list (:min mm) (:max mm)))) - -(derive ::min-max ::accumulator) - -(defvar empty-min-max (min-max nil nil) - "An empty min-max accumulator, combining minimum and maximum. - Only numbers can be added.") - -(defmethod combine ::min-max - [& vs] - (let [total-min (apply min (map :min vs)) - total-max (apply max (map :max vs))] - (min-max total-min total-max))) - -(defmethod add ::min-max - [v e] - (let [min-v (:min v) - max-v (:max v) - new-min (if (nil? min-v) e (min min-v e)) - new-max (if (nil? max-v) e (max max-v e))] - (min-max new-min new-max))) - -; -; Mean and variance accumulator -; -(deftype ::mean-variance mean-variance) - -(derive ::mean-variance ::accumulator) - -(defvar empty-mean-variance (mean-variance {:n 0 :mean 0 :variance 0}) - "An empty mean-variance accumulator, combining sample mean and - sample variance. Only numbers can be added.") - -(defmethod combine ::mean-variance - ([mv] - mv) - - ([mv1 mv2] - (let [{n1 :n mean1 :mean var1 :variance} mv1 - {n2 :n mean2 :mean var2 :variance} mv2 - n (+ n1 n2) - mean (/ (+ (* n1 mean1) (* n2 mean2)) n) - sq #(* % %) - c (+ (* n1 (sq (- mean mean1))) (* n2 (sq (- mean mean2)))) - var (if (< n 2) - 0 - (/ (+ c (* (dec n1) var1) (* (dec n2) var2)) (dec n)))] - (mean-variance {:n n :mean mean :variance var}))) - - ([mv1 mv2 & mvs] - (reduce combine (combine mv1 mv2) mvs))) - -(defmethod add ::mean-variance - [mv x] - (let [{n :n mean :mean var :variance} mv - n1 (inc n) - d (- x mean) - new-mean (+ mean (/ d n1)) - new-var (if (zero? n) 0 (/ (+ (* (dec n) var) (* d (- x new-mean))) n))] - (mean-variance {:n n1 :mean new-mean :variance new-var}))) - -; -; Counter accumulator -; -(deftype ::counter counter) - -(derive ::counter ::accumulator) - -(defvar empty-counter (counter {}) - "An empty counter accumulator. Its value is a map that stores for - every item the number of times it was added.") - -(defmethod combine ::counter - [v & vs] - (letfn [(add-item [cntr [item n]] - (assoc cntr item (+ n (get cntr item 0)))) - (add-two [c1 c2] (reduce add-item c1 c2))] - (reduce add-two v vs))) - -(defmethod add ::counter - [v e] - (assoc v e (inc (get v e 0)))) - -; -; Counter accumulator with total count -; -(deftype ::counter-with-total counter-with-total) -(derive ::counter-with-total ::counter) - -(defvar empty-counter-with-total - (counter-with-total {:total 0}) - "An empty counter-with-total accumulator. It works like the counter - accumulator, except that the total number of items added is stored as the - value of the key :total.") - -(defmethod add ::counter-with-total - [v e] - (assoc v e (inc (get v e 0)) - :total (inc (:total v)))) - -; -; Accumulator n-tuple -; -(deftype ::tuple acc-tuple) - -(derive ::tuple ::accumulator) - -(defn empty-tuple - "Returns an accumulator tuple with the supplied empty-accumulators - as its value. Accumulator tuples consist of several accumulators that - work in parallel. Added items must be sequences whose number of elements - matches the number of sub-accumulators." - [empty-accumulators] - (acc-tuple (into [] empty-accumulators))) - -(defmethod combine ::tuple - [& vs] - (acc-tuple (vec (map combine vs)))) - -(defmethod add ::tuple - [v e] - (acc-tuple (vec (map add v e)))) diff --git a/src/clojure/contrib/accumulators/examples.clj b/src/clojure/contrib/accumulators/examples.clj deleted file mode 100644 index b9dcbee5..00000000 --- a/src/clojure/contrib/accumulators/examples.clj +++ /dev/null @@ -1,93 +0,0 @@ -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; -;; Accumulator application examples -;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(ns - #^{:author "Konrad Hinsen" - :skip-wiki true - :doc "Examples for using accumulators"} - clojure.contrib.accumulators.examples - (:use [clojure.contrib.accumulators - :only (combine add add-items - empty-vector empty-list empty-queue empty-set empty-map - empty-counter empty-counter-with-total - empty-sum empty-product empty-maximum empty-minimum - empty-min-max empty-mean-variance empty-string empty-tuple)])) - -; Vector accumulator: combine is concat, add is conj -(combine [:a :b] [:c :d] [:x :y]) -(add [:a :b] :c) -(add-items empty-vector [:a :b :a]) - -; List accumulator: combine is concat, add is conj -(combine '(:a :b) '(:c :d) '(:x :y)) -(add '(:a :b) :c) -(add-items empty-list [:a :b :a]) - -; Queue accumulator -(let [q1 (add-items empty-queue [:a :b :a]) - q2 (add-items empty-queue [:x :y])] - (combine q1 q2)) - -; Set accumulator: combine is union, add is conj -(combine #{:a :b} #{:c :d} #{:a :d}) -(add #{:a :b} :c) -(add-items empty-set [:a :b :a]) - -; Map accumulator: combine is merge, add is conj -(combine {:a 1} {:b 2 :c 3} {}) -(add {:a 1} [:b 2]) -(add-items empty-map [[:a 1] [:b 2] [:a 0]]) - -; Counter accumulator -(let [c1 (add-items empty-counter [:a :b :a]) - c2 (add-items empty-counter [:x :y])] - (combine c1 c2)) - -; Counter-with-total accumulator -(let [c1 (add-items empty-counter-with-total [:a :b :a]) - c2 (add-items empty-counter-with-total [:x :y])] - (combine c1 c2)) - -; Sum accumulator: combine is addition -(let [s1 (add-items empty-sum [1 2 3]) - s2 (add-items empty-sum [-1 -2 -3])] - (combine s1 s2)) - -; Product accumulator: combine is multiplication -(let [p1 (add-items empty-product [2 3]) - p2 (add-items empty-product [(/ 1 2)])] - (combine p1 p2)) - -; Maximum accumulator: combine is max -(let [m1 (add-items empty-maximum [2 3]) - m2 (add-items empty-maximum [(/ 1 2)])] - (combine m1 m2)) - -; Minimum accumulator: combine is min -(let [m1 (add-items empty-minimum [2 3]) - m2 (add-items empty-minimum [(/ 1 2)])] - (combine m1 m2)) - -; Min-max accumulator: combination of minimum and maximum -(let [m1 (add-items empty-min-max [2 3]) - m2 (add-items empty-min-max [(/ 1 2)])] - (combine m1 m2)) - -; Mean-variance accumulator: sample mean and sample variance -(let [m1 (add-items empty-mean-variance [2 4]) - m2 (add-items empty-mean-variance [6])] - (combine m1 m2)) - -; String accumulator: combine is concatenation -(combine "a" "b" "c" "def") -(add "a" (char 44)) -(add-items empty-string [(char 55) (char 56) (char 57)]) - -; Accumulator tuples permit to update several accumulators in parallel -(let [pair (empty-tuple [empty-vector empty-string])] - (add-items pair [[1 "a"] [2 "b"]])) diff --git a/src/clojure/contrib/agent_utils.clj b/src/clojure/contrib/agent_utils.clj deleted file mode 100644 index 0ab845d5..00000000 --- a/src/clojure/contrib/agent_utils.clj +++ /dev/null @@ -1,35 +0,0 @@ -; Copyright (c) Christophe Grand, November 2008. All rights reserved. - -; The use and distribution terms for this software are covered by the -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) -; which can be found in the file epl-v10.html at the root of this -; distribution. -; By using this software in any fashion, you are agreeing to be bound by -; the terms of this license. -; You must not remove this notice, or any other, from this software. - -;; misc agent utilities - -;; note to other contrib members: feel free to add to this lib - -(ns - #^{:author "Christophe Grande", - :doc "Miscellaneous agent utilities - (note to other contrib members: feel free to add to this lib)", -} - clojure.contrib.agent-utils) - -(defmacro capture-and-send - "Capture the current value of the specified vars and rebind - them on the agent thread before executing the action. - - Example: - (capture-and-send [*out*] a f b c)" - - [vars agent action & args] - (let [locals (map #(gensym (name %)) vars)] - `(let [~@(interleave locals vars) - action# (fn [& args#] - (binding [~@(interleave vars locals)] - (apply ~action args#)))] - (send ~agent action# ~@args)))) diff --git a/src/clojure/contrib/apply_macro.clj b/src/clojure/contrib/apply_macro.clj deleted file mode 100644 index 19a926d3..00000000 --- a/src/clojure/contrib/apply_macro.clj +++ /dev/null @@ -1,43 +0,0 @@ -;;; apply_macro.clj: make macros behave like functions - -;; by Stuart Sierra, http://stuartsierra.com/ -;; January 28, 2009 - -;; Copyright (c) Stuart Sierra, 2009. All rights reserved. The use -;; and distribution terms for this software are covered by the Eclipse -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) -;; which can be found in the file epl-v10.html at the root of this -;; distribution. By using this software in any fashion, you are -;; agreeing to be bound by the terms of this license. You must not -;; remove this notice, or any other, from this software. - - -;; Don't use this. I mean it. It's evil. How evil? You can't -;; handle it, that's how evil it is. That's right. I did it so you -;; don't have to, ok? Look but don't touch. Use this lib and you'll -;; go blind. - - -(ns clojure.contrib.apply-macro) - -;; Copied from clojure.core/spread, which is private. -(defn- spread - "Flatten final argument list as in apply." - [arglist] - (cond - (nil? arglist) nil - (nil? (rest arglist)) (seq (first arglist)) - :else (cons (first arglist) (spread (rest arglist))))) - -(defmacro apply-macro - "This is evil. Don't ever use it. It makes a macro behave like a - function. Seriously, how messed up is that? - - Evaluates all args, then uses them as arguments to the macro as with - apply. - - (def things [true true false]) - (apply-macro and things) - ;; Expands to: (and true true false)" - [macro & args] - (cons macro (spread (map eval args)))) diff --git a/src/clojure/contrib/base64.clj b/src/clojure/contrib/base64.clj deleted file mode 100644 index 5e1e3310..00000000 --- a/src/clojure/contrib/base64.clj +++ /dev/null @@ -1,99 +0,0 @@ -;;; base64.clj: Experimental Base-64 encoding and (later) decoding - -;; by Stuart Sierra, http://stuartsierra.com/ -;; August 19, 2009 - -;; Copyright (c) Stuart Sierra, 2009. All rights reserved. The use -;; and distribution terms for this software are covered by the Eclipse -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) -;; which can be found in the file epl-v10.html at the root of this -;; distribution. By using this software in any fashion, you are -;; agreeing to be bound by the terms of this license. You must not -;; remove this notice, or any other, from this software. - - -(ns #^{:doc "Base-64 encoding and (maybe later) decoding. - - This is mainly here as an example. It is much slower than the - Apache Commons Codec implementation or sun.misc.BASE64Encoder." - :author "Stuart Sierra"} - clojure.contrib.base64 - (:import (java.io InputStream Writer ByteArrayInputStream - StringWriter))) - -(def *base64-alphabet* - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=") - -(defn encode - "Encodes bytes of input, writing Base 64 text on output. alphabet - is a 65-character String containing the 64 characters to use in the - encoding; the 65th character is the pad character. line-length is - the maximum number of characters per line, nil for no line breaks." - [#^InputStream input #^Writer output #^String alphabet line-length] - (let [buffer (make-array Byte/TYPE 3)] - (loop [line 0] - (let [len (.read input buffer)] - (when (pos? len) - ;; Pre-boxing the bytes as Integers is more efficient for - ;; Clojure's bit operations. - (let [b0 (Integer/valueOf (int (aget buffer 0))) - b1 (Integer/valueOf (int (aget buffer 1))) - b2 (Integer/valueOf (int (aget buffer 2)))] - (cond (= len 3) - (let [s0 (bit-and 0x3F (bit-shift-right b0 2)) - s1 (bit-and 0x3F - (bit-or (bit-shift-left b0 4) - (bit-shift-right b1 4))) - s2 (bit-and 0x3F - (bit-or (bit-shift-left b1 2) - (bit-shift-right b2 6))) - s3 (bit-and 0x3F b2)] - (.append output (.charAt alphabet s0)) - (.append output (.charAt alphabet s1)) - (.append output (.charAt alphabet s2)) - (.append output (.charAt alphabet s3))) - - (= len 2) - (let [s0 (bit-and 0x3F (bit-shift-right b0 2)) - s1 (bit-and 0x3F - (bit-or (bit-shift-left b0 4) - (bit-shift-right b1 4))) - s2 (bit-and 0x3F (bit-shift-left b1 2))] - (.append output (.charAt alphabet s0)) - (.append output (.charAt alphabet s1)) - (.append output (.charAt alphabet s2)) - (.append output (.charAt alphabet 64))) - - (= len 1) - (let [s0 (bit-and 0x3F (bit-shift-right b0 2)) - s1 (bit-and 0x3F (bit-shift-left b0 4))] - (.append output (.charAt alphabet s0)) - (.append output (.charAt alphabet s1)) - (.append output (.charAt alphabet 64)) - (.append output (.charAt alphabet 64))))) - (if (and line-length (> (+ line 4) line-length)) - (do (.append output \newline) - (recur 0)) - (recur (+ line 4)))))))) - -(defn encode-str - "Encodes String in base 64; returns a String. If not specified, - encoding is UTF-8 and line-length is nil." - ([s] (encode-str s "UTF-8" nil)) - ([#^String s #^String encoding line-length] - (let [output (StringWriter.)] - (encode (ByteArrayInputStream. (.getBytes s encoding)) - output *base64-alphabet* line-length) - (.toString output)))) - - -;;; tests - -;; (deftest t-encode-str -;; (is (= (encode-str "") "")) -;; (is (= (encode-str "f") "Zg==")) -;; (is (= (encode-str "fo") "Zm8=")) -;; (is (= (encode-str "foo") "Zm9v")) -;; (is (= (encode-str "foob") "Zm9vYg==")) -;; (is (= (encode-str "fooba") "Zm9vYmE=")) -;; (is (= (encode-str "foobar") "Zm9vYmFy"))) diff --git a/src/clojure/contrib/classpath.clj b/src/clojure/contrib/classpath.clj deleted file mode 100644 index a5a1a6d3..00000000 --- a/src/clojure/contrib/classpath.clj +++ /dev/null @@ -1,39 +0,0 @@ -;;; classpath.clj: utilities for working with the Java class path - -;; by Stuart Sierra, http://stuartsierra.com/ -;; April 19, 2009 - -;; Copyright (c) Stuart Sierra, 2009. All rights reserved. The use -;; and distribution terms for this software are covered by the Eclipse -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) -;; which can be found in the file epl-v10.html at the root of this -;; distribution. By using this software in any fashion, you are -;; agreeing to be bound by the terms of this license. You must not -;; remove this notice, or any other, from this software. - - -(ns - #^{:author "Stuart Sierra", - :doc "Utilities for dealing with the JVM's classpath"} - clojure.contrib.classpath - (:require [clojure.contrib.jar :as jar]) - (:import (java.io File) - (java.util.jar JarFile))) - -(defn classpath - "Returns a sequence of File objects of the elements on CLASSPATH." - [] - (map #(File. %) - (.split (System/getProperty "java.class.path") - (System/getProperty "path.separator")))) - -(defn classpath-directories - "Returns a sequence of File objects for the directories on classpath." - [] - (filter #(.isDirectory %) (classpath))) - -(defn classpath-jarfiles - "Returns a sequence of JarFile objects for the JAR files on classpath." - [] - (map #(JarFile. %) (filter jar/jar-file? (classpath)))) - diff --git a/src/clojure/contrib/combinatorics.clj b/src/clojure/contrib/combinatorics.clj deleted file mode 100644 index ca8c8ba2..00000000 --- a/src/clojure/contrib/combinatorics.clj +++ /dev/null @@ -1,164 +0,0 @@ -;;; combinatorics.clj: efficient, functional algorithms for generating lazy -;;; sequences for common combinatorial functions. - -;; by Mark Engelberg (mark.engelberg@gmail.com) -;; January 27, 2009 - -(comment -" -(combinations items n) - A lazy sequence of all the unique -ways of taking n different elements from items. -Example: (combinations [1 2 3] 2) -> ((1 2) (1 3) (2 3)) - -(subsets items) - A lazy sequence of all the subsets of -items (but generalized to all sequences, not just sets). -Example: (subsets [1 2 3]) -> (() (1) (2) (3) (1 2) (1 3) (2 3) (1 2 3)) - -(cartesian-product & seqs) - Takes any number of sequences -as arguments, and returns a lazy sequence of all the ways -to take one item from each seq. -Example: (cartesian-product [1 2] [3 4]) -> ((1 3) (1 4) (2 3) (2 4)) -(cartesian-product seq1 seq2 seq3 ...) behaves like but is -faster than a nested for loop, such as: -(for [i1 seq1 i2 seq2 i3 seq3 ...] (list i1 i2 i3 ...)) - -(selections items n) - A lazy sequence of all the ways to -take n (possibly the same) items from the sequence of items. -Example: (selections [1 2] 3) -> ((1 1 1) (1 1 2) (1 2 1) (1 2 2) (2 1 1) (2 1 2) (2 2 1) (2 2 2)) - -(permutations items) - A lazy sequence of all the permutations -of items. -Example: (permutations [1 2 3]) -> ((1 2 3) (1 3 2) (2 1 3) (2 3 1) (3 1 2) (3 2 1)) - -(lex-permutations items) - A lazy sequence of all distinct -permutations in lexicographic order -(this function returns the permutations as -vectors). Only works on sequences of comparable -items. (Note that the result will be quite different from -permutations when the sequence contains duplicate items.) -Example: (lex-permutations [1 1 2]) -> ([1 1 2] [1 2 1] [2 1 1]) - -About permutations vs. lex-permutations: -lex-permutations is faster than permutations, but only works -on sequences of numbers. They operate differently -on sequences with duplicate items (lex-permutations will only -give you back distinct permutations). lex-permutations always -returns the permutations sorted lexicographically whereas -permutations will be in an order where the input sequence -comes first. In general, I recommend using the regular -permutations function unless you have a specific -need for lex-permutations. - -About this code: -These combinatorial functions can be written in an elegant way using recursion. However, when dealing with combinations and permutations, you're usually generating large numbers of things, and speed counts. My objective was to write the fastest possible code I could, restricting myself to Clojure's functional, persistent data structures (rather than using Java's arrays) so that this code could be safely leveraged within Clojure's transactional concurrency system. - -I also restricted myself to algorithms that return results in a standard order. For example, there are faster ways to generate cartesian-product, but I don't know of a faster way to generate the results in the standard nested-for-loop order. - -Most of these algorithms are derived from algorithms found in Knuth's wonderful Art of Computer Programming books (specifically, the volume 4 fascicles), which present fast, iterative solutions to these common combinatorial problems. Unfortunately, these iterative versions are somewhat inscrutable. If you want to better understand these algorithms, the Knuth books are the place to start. - -On my own computer, I use versions of all these algorithms that return sequences built with an uncached variation of lazy-seq. Not only does this boost performance, but it's easier to use these rather large sequences more safely (from a memory consumption standpoint). If some form of uncached sequences makes it into Clojure, I will update this accordingly. -" -) - - -(ns - #^{:author "Mark Engelberg", - :doc "Efficient, functional algorithms for generating lazy -sequences for common combinatorial functions. (See the source code -for a longer description.)"} - clojure.contrib.combinatorics) - -(defn- index-combinations - [n cnt] - (lazy-seq - (let [c (vec (cons nil (for [j (range 1 (inc n))] (+ j cnt (- (inc n)))))), - iter-comb - (fn iter-comb [c j] - (if (> j n) nil - (let [c (assoc c j (dec (c j)))] - (if (< (c j) j) [c (inc j)] - (loop [c c, j j] - (if (= j 1) [c j] - (recur (assoc c (dec j) (dec (c j))) (dec j)))))))), - step - (fn step [c j] - (cons (rseq (subvec c 1 (inc n))) - (lazy-seq (let [next-step (iter-comb c j)] - (when next-step (step (next-step 0) (next-step 1)))))))] - (step c 1)))) - -(defn combinations - "All the unique ways of taking n different elements from items" - [items n] - (let [v-items (vec (reverse items))] - (if (zero? n) (list ()) - (let [cnt (count items)] - (cond (> n cnt) nil - (= n cnt) (list (seq items)) - :else - (map #(map v-items %) (index-combinations n cnt))))))) - -(defn subsets - "All the subsets of items" - [items] - (mapcat (fn [n] (combinations items n)) - (range (inc (count items))))) - -(defn cartesian-product - "All the ways to take one item from each sequence" - [& seqs] - (let [v-original-seqs (vec seqs) - step - (fn step [v-seqs] - (let [increment - (fn [v-seqs] - (loop [i (dec (count v-seqs)), v-seqs v-seqs] - (if (= i -1) nil - (if-let [rst (next (v-seqs i))] - (assoc v-seqs i rst) - (recur (dec i) (assoc v-seqs i (v-original-seqs i)))))))] - (when v-seqs - (cons (map first v-seqs) - (lazy-seq (step (increment v-seqs)))))))] - (when (every? first seqs) - (lazy-seq (step v-original-seqs))))) - - -(defn selections - "All the ways of taking n (possibly the same) elements from the sequence of items" - [items n] - (apply cartesian-product (take n (repeat items)))) - - -(defn- iter-perm [v] - (let [len (count v), - j (loop [i (- len 2)] - (cond (= i -1) nil - (< (v i) (v (inc i))) i - :else (recur (dec i))))] - (when j - (let [vj (v j), - l (loop [i (dec len)] - (if (< vj (v i)) i (recur (dec i))))] - (loop [v (assoc v j (v l) l vj), k (inc j), l (dec len)] - (if (< k l) - (recur (assoc v k (v l) l (v k)) (inc k) (dec l)) - v)))))) - -(defn- vec-lex-permutations [v] - (when v (cons v (lazy-seq (vec-lex-permutations (iter-perm v)))))) - -(defn lex-permutations - "Fast lexicographic permutation generator for a sequence of numbers" - [c] - (lazy-seq - (let [vec-sorted (vec (sort c))] - (if (zero? (count vec-sorted)) - (list []) - (vec-lex-permutations vec-sorted))))) - -(defn permutations - "All the permutations of items, lexicographic by index" - [items] - (let [v (vec items)] - (map #(map v %) (lex-permutations (range (count v)))))) diff --git a/src/clojure/contrib/command_line.clj b/src/clojure/contrib/command_line.clj deleted file mode 100644 index 466dd7a7..00000000 --- a/src/clojure/contrib/command_line.clj +++ /dev/null @@ -1,122 +0,0 @@ -; Copyright (c) Chris Houser, Nov-Dec 2008. All rights reserved. -; The use and distribution terms for this software are covered by the -; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) -; which can be found in the file epl-v10.html at the root of this distribution. -; By using this software in any fashion, you are agreeing to be bound by -; the terms of this license. -; You must not remove this notice, or any other, from this software. - -; Process command-line arguments according to a given cmdspec - -(ns - #^{:author "Chris Houser", - :doc "Process command-line arguments according to a given cmdspec"} - clojure.contrib.command-line - (:require (clojure.contrib [seq-utils :as su])) - (:use (clojure.contrib [str-utils :only (str-join)]))) - -(defn make-map [args cmdspec] - (let [{spec true [rest-sym] false} (su/group-by vector? cmdspec) - rest-str (str rest-sym) - key-data (into {} (for [[syms [_ default]] (map #(split-with symbol? %) - (conj spec '[help? h?])) - sym syms] - [(re-find #"^.*[^?]" (str sym)) - {:sym (str (first syms)) :default default}])) - defaults (into {} (for [[_ {:keys [default sym]}] key-data - :when default] - [sym default]))] - (loop [[argkey & [argval :as r]] args - cmdmap (assoc defaults :cmdspec cmdspec rest-str [])] - (if argkey - (let [[_ & [keybase]] (re-find #"^--?(.*)" argkey)] - (cond - (= keybase nil) (recur r (update-in cmdmap [rest-str] conj argkey)) - (= keybase "") (update-in cmdmap [rest-str] #(apply conj % r)) - :else (if-let [found (key-data keybase)] - (if (= \? (last (:sym found))) - (recur r (assoc cmdmap (:sym found) true)) - (recur (next r) (assoc cmdmap (:sym found) - (if (or (nil? r) (= \- (ffirst r))) - (:default found) - (first r))))) - (throw (Exception. (str "Unknown option " argkey)))))) - cmdmap)))) - -(defn- align - "Align strings given as vectors of columns, with first vector - specifying right or left alignment (:r or :l) for each column." - [spec & rows] - (let [maxes (vec (for [n (range (count (first rows)))] - (apply max (map (comp count #(nth % n)) rows)))) - fmt (str-join " " - (for [n (range (count maxes))] - (str "%" - (when-not (zero? (maxes n)) - (str (when (= (spec n) :l) "-") (maxes n))) - "s")))] - (str-join "\n" - (for [row rows] - (apply format fmt row))))) - -(defn- rmv-q - "Remove ?" - [#^String s] - (if (.endsWith s "?") - (.substring s 0 (dec (count s))) - s)) - -(defn print-help [desc cmdmap] - (println desc) - (println "Options") - (println - (apply align [:l :l :l] - (for [spec (:cmdspec cmdmap) :when (vector? spec)] - (let [[argnames [text default]] (split-with symbol? spec) - [_ opt q] (re-find #"^(.*[^?])(\??)$" - (str (first argnames))) - argnames (map (comp rmv-q str) argnames) - argnames - (str-join ", " - (for [arg argnames] - (if (= 1 (count arg)) - (str "-" arg) - (str "--" arg))))] - [(str " " argnames (when (= "" q) " ") " ") - text - (if-not default - "" - (str " [default " default "]"))]))))) - -(defmacro with-command-line - "Bind locals to command-line args." - [args desc cmdspec & body] - (let [locals (vec (for [spec cmdspec] - (if (vector? spec) - (first spec) - spec)))] - `(let [{:strs ~locals :as cmdmap#} (make-map ~args '~cmdspec)] - (if (cmdmap# "help?") - (print-help ~desc cmdmap#) - (do ~@body))))) - -(comment - -; example of usage: - -(with-command-line *command-line-args* - "tojs -- Compile ClojureScript to JavaScript" - [[simple? s? "Runs some simple built-in tests"] - [serve "Starts a repl server on the given port" 8081] - [mkboot? "Generates a boot.js file"] - [verbose? v? "Includes extra fn names and comments in js"] - filenames] - (binding [*debug-fn-names* verbose? *debug-comments* verbose?] - (cond - simple? (simple-tests) - serve (start-server (Integer/parseInt serve)) - mkboot? (mkboot) - :else (doseq [filename filenames] - (filetojs filename))))) - -) diff --git a/src/clojure/contrib/complex_numbers.clj b/src/clojure/contrib/complex_numbers.clj deleted file mode 100644 index 01f90b9c..00000000 --- a/src/clojure/contrib/complex_numbers.clj +++ /dev/null @@ -1,293 +0,0 @@ -;; Complex numbers - -;; by Konrad Hinsen -;; last updated May 4, 2009 - -;; Copyright (c) Konrad Hinsen, 2009. All rights reserved. The use -;; and distribution terms for this software are covered by the Eclipse -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) -;; which can be found in the file epl-v10.html at the root of this -;; distribution. By using this software in any fashion, you are -;; agreeing to be bound by the terms of this license. You must not -;; remove this notice, or any other, from this software. - -(ns - #^{:author "Konrad Hinsen" - :doc "Complex numbers - NOTE: This library is in evolution. Most math functions are - not implemented yet."} - clojure.contrib.complex-numbers - (:refer-clojure :exclude (deftype)) - (:use [clojure.contrib.types :only (deftype)] - [clojure.contrib.generic :only (root-type)]) - (:require [clojure.contrib.generic.arithmetic :as ga] - [clojure.contrib.generic.comparison :as gc] - [clojure.contrib.generic.math-functions :as gm])) - -; -; Complex numbers are represented as struct maps. The real and imaginary -; parts can be of any type for which arithmetic and maths functions -; are defined. -; -(defstruct complex-struct :real :imag) - -; -; The general complex number type -; -(deftype ::complex complex - (fn [real imag] (struct complex-struct real imag)) - (fn [c] (vals c))) - -(derive ::complex root-type) - -; -; A specialized subtype for pure imaginary numbers. Introducing this type -; reduces the number of operations by eliminating additions with and -; multiplications by zero. -; -(deftype ::pure-imaginary imaginary - (fn [imag] (struct complex-struct 0 imag)) - (fn [c] (list (:imag c)))) - -(derive ::pure-imaginary ::complex) - -; -; Extraction of real and imaginary parts -; -(def real (accessor complex-struct :real)) -(def imag (accessor complex-struct :imag)) - -; -; Equality and zero test -; -(defmethod gc/zero? ::complex - [x] - (let [[rx ix] (vals x)] - (and (zero? rx) (zero? ix)))) - -(defmethod gc/= [::complex ::complex] - [x y] - (let [[rx ix] (vals x) - [ry iy] (vals y)] - (and (gc/= rx ry) (gc/= ix iy)))) - -(defmethod gc/= [::pure-imaginary ::pure-imaginary] - [x y] - (gc/= (imag x) (imag y))) - -(defmethod gc/= [::complex ::pure-imaginary] - [x y] - (let [[rx ix] (vals x)] - (and (gc/zero? rx) (gc/= ix (imag y))))) - -(defmethod gc/= [::pure-imaginary ::complex] - [x y] - (let [[ry iy] (vals y)] - (and (gc/zero? ry) (gc/= (imag x) iy)))) - -(defmethod gc/= [::complex root-type] - [x y] - (let [[rx ix] (vals x)] - (and (gc/zero? ix) (gc/= rx y)))) - -(defmethod gc/= [root-type ::complex] - [x y] - (let [[ry iy] (vals y)] - (and (gc/zero? iy) (gc/= x ry)))) - -(defmethod gc/= [::pure-imaginary root-type] - [x y] - (and (gc/zero? (imag x)) (gc/zero? y))) - -(defmethod gc/= [root-type ::pure-imaginary] - [x y] - (and (gc/zero? x) (gc/zero? (imag y)))) - -; -; Addition -; -(defmethod ga/+ [::complex ::complex] - [x y] - (let [[rx ix] (vals x) - [ry iy] (vals y)] - (complex (ga/+ rx ry) (ga/+ ix iy)))) - -(defmethod ga/+ [::pure-imaginary ::pure-imaginary] - [x y] - (imaginary (ga/+ (imag x) (imag y)))) - -(defmethod ga/+ [::complex ::pure-imaginary] - [x y] - (let [[rx ix] (vals x)] - (complex rx (ga/+ ix (imag y))))) - -(defmethod ga/+ [::pure-imaginary ::complex] - [x y] - (let [[ry iy] (vals y)] - (complex ry (ga/+ (imag x) iy)))) - -(defmethod ga/+ [::complex root-type] - [x y] - (let [[rx ix] (vals x)] - (complex (ga/+ rx y) ix))) - -(defmethod ga/+ [root-type ::complex] - [x y] - (let [[ry iy] (vals y)] - (complex (ga/+ x ry) iy))) - -(defmethod ga/+ [::pure-imaginary root-type] - [x y] - (complex y (imag x))) - -(defmethod ga/+ [root-type ::pure-imaginary] - [x y] - (complex x (imag y))) - -; -; Negation -; -(defmethod ga/- ::complex - [x] - (let [[rx ix] (vals x)] - (complex (ga/- rx) (ga/- ix)))) - -(defmethod ga/- ::pure-imaginary - [x] - (imaginary (ga/- (imag x)))) - -; -; Subtraction is automatically supplied by ga/-, optimized implementations -; can be added later... -; - -; -; Multiplication -; -(defmethod ga/* [::complex ::complex] - [x y] - (let [[rx ix] (vals x) - [ry iy] (vals y)] - (complex (ga/- (ga/* rx ry) (ga/* ix iy)) - (ga/+ (ga/* rx iy) (ga/* ix ry))))) - -(defmethod ga/* [::pure-imaginary ::pure-imaginary] - [x y] - (ga/- (ga/* (imag x) (imag y)))) - -(defmethod ga/* [::complex ::pure-imaginary] - [x y] - (let [[rx ix] (vals x) - iy (imag y)] - (complex (ga/- (ga/* ix iy)) - (ga/* rx iy)))) - -(defmethod ga/* [::pure-imaginary ::complex] - [x y] - (let [ix (imag x) - [ry iy] (vals y)] - (complex (ga/- (ga/* ix iy)) - (ga/* ix ry)))) - -(defmethod ga/* [::complex root-type] - [x y] - (let [[rx ix] (vals x)] - (complex (ga/* rx y) (ga/* ix y)))) - -(defmethod ga/* [root-type ::complex] - [x y] - (let [[ry iy] (vals y)] - (complex (ga/* x ry) (ga/* x iy)))) - -(defmethod ga/* [::pure-imaginary root-type] - [x y] - (imaginary (ga/* (imag x) y))) - -(defmethod ga/* [root-type ::pure-imaginary] - [x y] - (imaginary (ga/* x (imag y)))) - -; -; Inversion -; -(ga/defmethod* ga / ::complex - [x] - (let [[rx ix] (vals x) - den ((ga/qsym ga /) (ga/+ (ga/* rx rx) (ga/* ix ix)))] - (complex (ga/* rx den) (ga/- (ga/* ix den))))) - -(ga/defmethod* ga / ::pure-imaginary - [x] - (imaginary (ga/- ((ga/qsym ga /) (imag x))))) - -; -; Division is automatically supplied by ga//, optimized implementations -; can be added later... -; - -; -; Conjugation -; -(defmethod gm/conjugate ::complex - [x] - (let [[r i] (vals x)] - (complex r (ga/- i)))) - -(defmethod gm/conjugate ::pure-imaginary - [x] - (imaginary (ga/- (imag x)))) - -; -; Absolute value -; -(defmethod gm/abs ::complex - [x] - (let [[r i] (vals x)] - (gm/sqrt (ga/+ (ga/* r r) (ga/* i i))))) - -(defmethod gm/abs ::pure-imaginary - [x] - (gm/abs (imag x))) - -; -; Square root -; -(let [one-half (/ 1 2) - one-eighth (/ 1 8)] - (defmethod gm/sqrt ::complex - [x] - (let [[r i] (vals x)] - (if (and (gc/zero? r) (gc/zero? i)) - 0 - (let [; The basic formula would say - ; abs (gm/sqrt (ga/+ (ga/* r r) (ga/* i i))) - ; p (gm/sqrt (ga/* one-half (ga/+ abs r))) - ; but the slightly more complicated one below - ; avoids overflow for large r or i. - ar (gm/abs r) - ai (gm/abs i) - r8 (ga/* one-eighth ar) - i8 (ga/* one-eighth ai) - abs (gm/sqrt (ga/+ (ga/* r8 r8) (ga/* i8 i8))) - p (ga/* 2 (gm/sqrt (ga/+ abs r8))) - q ((ga/qsym ga /) ai (ga/* 2 p)) - s (gm/sgn i)] - (if (gc/< r 0) - (complex q (ga/* s p)) - (complex p (ga/* s q)))))))) - -; -; Exponential function -; -(defmethod gm/exp ::complex - [x] - (let [[r i] (vals x) - exp-r (gm/exp r) - cos-i (gm/cos i) - sin-i (gm/sin i)] - (complex (ga/* exp-r cos-i) (ga/* exp-r sin-i)))) - -(defmethod gm/exp ::pure-imaginary - [x] - (let [i (imag x)] - (complex (gm/cos i) (gm/sin i)))) diff --git a/src/clojure/contrib/cond.clj b/src/clojure/contrib/cond.clj deleted file mode 100644 index 0ae8ca06..00000000 --- a/src/clojure/contrib/cond.clj +++ /dev/null @@ -1,34 +0,0 @@ -;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and -;; distribution terms for this software are covered by the Eclipse Public -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can -;; be found in the file epl-v10.html at the root of this distribution. By -;; using this software in any fashion, you are agreeing to be bound by the -;; terms of this license. You must not remove this notice, or any other, -;; from this software. -;; -;; File: cond.clj -;; -;; scgilardi (gmail) -;; 2 October 2008 - -(ns #^{:author "Stephen C. Gilardi" - :doc "Extensions to the basic cond function."} - clojure.contrib.cond) - -(defmacro cond-let - "Takes a binding-form and a set of test/expr pairs. Evaluates each test - one at a time. If a test returns logical true, cond-let evaluates and - returns expr with binding-form bound to the value of test and doesn't - evaluate any of the other tests or exprs. To provide a default value - either provide a literal that evaluates to logical true and is - binding-compatible with binding-form, or use :else as the test and don't - refer to any parts of binding-form in the expr. (cond-let binding-form) - returns nil." - [bindings & clauses] - (let [binding (first bindings)] - (when-let [[test expr & more] clauses] - (if (= test :else) - expr - `(if-let [~binding ~test] - ~expr - (cond-let ~bindings ~@more)))))) diff --git a/src/clojure/contrib/condition.clj b/src/clojure/contrib/condition.clj deleted file mode 100644 index 98aa589a..00000000 --- a/src/clojure/contrib/condition.clj +++ /dev/null @@ -1,147 +0,0 @@ -;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and -;; distribution terms for this software are covered by the Eclipse Public -;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can -;; be found in the file epl-v10.html at the root of this distribution. By -;; using this software in any fashion, you are agreeing to be bound by the -;; terms of this license. You must not remove this notice, or any other, -;; from this software. -;; -;; condition.clj -;; -;; scgilardi (gmail) -;; Created 09 June 2009 - -(ns #^{:author "Stephen C. Gilardi" - :doc "Flexible raising and handling of conditions: - -Functions: - - raise: raises a condition - handler-case: dispatches raised conditions to appropriate handlers - print-stack-trace: prints abbreviated or full condition stack traces - -Data: - - A condition is a map containing values for these keys: - - - :type, a condition type specifier, typically a keyword - - :stack-trace, a stack trace to the site of the raise - - :message, a human-readable message (optional) - - :cause, a wrapped exception or condition (optional) - - other keys given as arguments to raise (optional) - -Note: requires AOT compilation. - -Based on an idea from Chouser: -http://groups.google.com/group/clojure/browse_frm/thread/da1285c538f22bb5"} - clojure.contrib.condition - (:require clojure.contrib.condition.Condition) - (:import clojure.contrib.condition.Condition - clojure.lang.IPersistentMap) - (:use (clojure.contrib - [def :only (defvar)] - [seq-utils :only (separate)]))) - -(defvar *condition* - "While a handler is running, bound to the condition being handled") - -(defvar *selector* - "While a handler is running, bound to the selector returned by the - handler-case dispatch-fn for *condition*") - -(defvar *condition-object* - "While a handler is running, bound to the Condition object whose metadata - is the condition") - -(defvar *full-stack-traces* false - "Bind to true to include clojure.{core,lang,main} frames in stack - traces") - -(defmacro raise - "Raises a condition. With no arguments, re-raises the current condition. - With one argument (a map), raises the argument. With two or more - arguments, raises a map with keys and values from the arguments." - ([] - `(throw *condition-object*)) - ([m] - `(throw (Condition. ~m))) - ([key val & keyvals] - `(raise (hash-map ~key ~val ~@keyvals)))) - -(defmacro handler-case - "Executes body in a context where raised conditions can be handled. - - d