Permalink
Browse files

add Revisions log and remove obsolete top level libs

  • Loading branch information...
scgilardi committed Aug 16, 2008
1 parent 818e0f3 commit 881815127c98c4c38d8f78a0fd3cd5e1ab72b1af
Showing with 7 additions and 1,724 deletions.
  1. +7 −0 Revisions
  2. +0 −74 def.clj
  3. +0 −120 duck-streams.clj
  4. +0 −47 enum.clj
  5. +0 −44 except.clj
  6. +0 −93 fcase.clj
  7. +0 −60 import-static.clj
  8. +0 −98 javalog.clj
  9. +0 −90 lazy-seqs.clj
  10. +0 −351 lib.clj
  11. +0 −32 memoize.clj
  12. +0 −88 ns-utils.clj
  13. +0 −108 pred.clj
  14. +0 −54 seq-utils.clj
  15. +0 −126 sql.clj
  16. +0 −44 str-utils.clj
  17. +0 −29 string.clj
  18. +0 −211 test-is.clj
  19. +0 −55 trace.clj
View
@@ -0,0 +1,7 @@
+2008-08-16 All namespace-directory-aware libs have been moved to
+src/clojure/contrib. Please udpate your clojure classpaths accordingly.
+
+2008-08-16 Revision 134 is the last to contain
+non-namespace-directory-aware libs at the top level of this repository. At
+the time of this writing, Clojure's SVN version is 1001.
+
View
74 def.clj
@@ -1,74 +0,0 @@
-;; Copyright (c) Stephen C. Gilardi. All rights reserved.
-;; The use and distribution terms for this software are covered by the
-;; Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
-;; which can be found in the file CPL.TXT 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: def.clj
-;;
-;; def.clj provides variants of def that make including doc strings and
-;; making private definitions more succinct.
-;;
-;; scgilardi (gmail)
-;; 17 May 2008
-
-(clojure/in-ns 'def)
-(clojure/refer 'clojure)
-
-(defmacro init-once
- "Initializes a var exactly once. The var must already exist."
- [var init]
- `(let [v# (resolve '~var)]
- (when-not (.isBound v#)
- (.bindRoot v# ~init))))
-
-(defmacro defvar
- "Defines a var with an optional intializer and doc string"
- ([name]
- (list `def name))
- ([name init]
- (list `def name init))
- ([name init doc]
- (list `def (with-meta name (assoc (meta name) :doc doc)) init)))
-
-(defmacro defunbound
- "Defines an unbound var with optional doc string"
- ([name]
- (list `def name))
- ([name doc]
- (list `def (with-meta name (assoc (meta name) :doc doc)))))
-
-(defmacro defmacro-
- "Same as defmacro but yields a private definition"
- [name & decls]
- (list* `defmacro (with-meta name (assoc (meta name) :private true)) decls))
-
-(defmacro defvar-
- "Same as defvar but yields a private definition"
- [name & decls]
- (list* `defvar (with-meta name (assoc (meta name) :private true)) decls))
-
-(defmacro defunbound-
- "Same as defunbound but yields a private definition"
- [name & decls]
- (list* `defunbound (with-meta name (assoc (meta name) :private true)) decls))
-
-(defmacro defstruct-
- "Same as defstruct but yields a private definition"
- [name & decls]
- (list* `defstruct (with-meta name (assoc (meta name) :private true)) decls))
-
-(defmacro defalias
- "Defines an alias for a var: a new var with the same value and metadata
- as another with the exception of :namespace, :name, :file, :line, and
- optionally :doc which are those of new var."
- ([name orig]
- `(let [v# (def ~name ~orig)]
- (. v# (setMeta (merge (meta #'~orig) (meta #'~name))))
- v#))
- ([name orig doc]
- `(let [v# (def ~name ~orig)]
- (. v# (setMeta (merge (meta #'~orig) (assoc (meta #'~name) :doc ~doc))))
- v#)))
View
@@ -1,120 +0,0 @@
-;;; duck-streams.clj -- duck-typed I/O streams for Clojure
-
-;; by Stuart Sierra <mail@stuartsierra.com>
-;; April 8, 2008
-
-;; Copyright (c) 2008 Stuart Sierra. All rights reserved. The use and
-;; distribution terms for this software are covered by the Common
-;; Public License 1.0 (http://www.opensource.org/licenses/cpl1.0.php)
-;; which can be found in the file CPL.TXT 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.
-
-
-;; This file defines "duck-typed" I/O utility functions for Clojure.
-;; The 'reader' and 'writer' functions will open and return an
-;; instance of java.io.BufferedReader and java.io.PrintWriter,
-;; respectively, for a variety of argument types -- filenames as
-;; strings, URLs, java.io.File's, etc. These functions are not very
-;; efficient, because they have to perform a number of 'instance?'
-;; checks, but they are convenient when you just want to open a file
-;; and don't want to deal with all the Java I/O classes.
-;;
-;; This file also defines two convenience functions, 'spit' (opposite
-;; of 'slurp') and 'write-lines' (opposite of 'line-seq').
-
-
-(clojure/in-ns 'duck-streams)
-(clojure/refer 'clojure)
-
-(import '(java.io Reader InputStream InputStreamReader FileReader
- BufferedReader File PrintWriter OutputStream
- OutputStreamWriter BufferedWriter Writer FileWriter)
- '(java.net URI URL MalformedURLException))
-
-(defmacro bufr
- {:private true}
- [reader]
- `(new java.io.BufferedReader ~reader))
-
-(defn reader
- "Attempts to coerce its argument into an open
- java.io.BufferedReader. Argument may be an instance of Reader,
- BufferedReader, InputStream, File, URI, URL, or String.
-
- If argument is a String, it tries to resolve it first as a URI, then
- as a local file name. URIs with a 'file' protocol are converted to
- local file names.
-
- Should be used inside with-open to ensure the Reader is properly
- closed."
- [x]
- (cond
- (instance? BufferedReader x) x
- (instance? Reader x) (bufr x)
- (instance? InputStream x) (bufr (new InputStreamReader x))
- (instance? File x) (bufr (new FileReader #^File x))
- (instance? URL x) (if (= (. #^URL x (getProtocol)) "file")
- (bufr (new FileReader (. #^URL x (getPath))))
- (bufr (new InputStreamReader (. #^URL x (openStream)))))
- (instance? URI x) (reader (. #^URI x (toURL)))
- (instance? String x) (try (let [url (new URL x)]
- (reader url))
- (catch MalformedURLException err
- (bufr (new FileReader #^String x))))
- :else (throw (new Exception (str "Cannot coerce " (class x)
- " into a Reader.")))))
-
-(defmacro bufw
- {:private true}
- [writer]
- `(new java.io.PrintWriter (new java.io.BufferedWriter ~writer)))
-
-(defn writer
- "Attempts to coerce its argument into an open java.io.PrintWriter
- wrapped around a java.io.BufferedWriter. Argument may be an
- instance of Writer, PrintWriter, BufferedWriter, OutputStream, File,
- URI, URL, or String.
-
- If argument is a String, it tries to resolve it first as a URI, then
- as a local file name. URIs with a 'file' protocol are converted to
- local file names.
-
- Should be used inside with-open to ensure the Writer is properly
- closed."
- [x]
- (cond
- (instance? PrintWriter x) x
- (instance? BufferedWriter x) (new PrintWriter #^BufferedWriter x)
- (instance? Writer x) (bufw x) ; includes FileWriter
- (instance? OutputStream x) (bufw (new OutputStreamWriter x))
- (instance? File x) (bufw (new FileWriter #^File x))
- (instance? URL x) (if (= (. #^URL x (getProtocol)) "file")
- (bufw (new FileWriter (. #^URL x (getPath))))
- (throw (new Exception (str "Cannot write to non-file URL <" x ">."))))
- (instance? URI x) (writer (. #^URI x (toURL)))
- (instance? String x) (try (let [url (new URL x)]
- (writer url))
- (catch MalformedURLException err
- (bufw (new FileWriter #^String x))))
- :else (throw (new Exception (str "Cannot coerce " (class x)
- " into a Writer.")))))
-
-(defn write-lines
- "Opposite of 'line-seq'. Writes lines (a seq) to writer (an open
- java.io.PrintWriter), separated by newlines."
- [#^PrintWriter writer lines]
- (let [line (first lines)]
- (when line
- (. writer (write (str line)))
- (. writer (println))
- (recur writer (rest lines)))))
-
-(defn spit
- "Opposite of 'slurp'. Writes 'contents' to the file named by
- 'filename'."
- [filename contents]
- (with-open w (#^PrintWriter writer filename)
- (. w (print contents))))
-
View
@@ -1,47 +0,0 @@
-;;; enum.clj -- Java enum classes in Clojure
-
-;; by Stuart Sierra, http://www.stuartsierra.com/
-;; May 29, 2008
-
-;; Copyright (c) 2008 Stuart Sierra. All rights reserved. The use and
-;; distribution terms for this software are covered by the Common
-;; Public License 1.0 (http://www.opensource.org/licenses/cpl1.0.php)
-;; which can be found in the file CPL.TXT 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.
-
-
-;; This file helps define Java Enums, introduced in Java 1.5. Use it
-;; when you need to define an enum to pass to a Java method.
-;;
-;; This file depends on genclass.clj in the Clojure distribution.
-
-
-(clojure/in-ns 'enum)
-(clojure/refer 'clojure)
-
-(defmacro defenum
- "Generates and loads a subclass of java.lang.Enum, then
- defs symbols as enumerated instances of that class.
-
- Example: (defenum my.package.MyEnum FOO BAR)
- ;; FOO and BAR are now instances of MyEnum
-
- Java equivalent: enum MyEnum { FOO, BAR };
-
- Caveats:
- 1. The generated class has no values() method.
- 2. The generated class returns false for Class.isEnum().
- 3. Enum.valueOf(Class, String) will not work.
- 4. Redefining an enum is allowed, but enumeration resets
- to zero."
- [class & symbols]
- ;; Can't load a class twice, so check first:
- (try (. Class (forName (str class)))
- (catch java.lang.ClassNotFoundException e
- (gen-and-load-class (str class) :extends java.lang.Enum)))
- (cons 'do
- (map (fn [sym val]
- `(def ~sym (new ~class ~(str sym) ~val)))
- symbols (iterate inc 0))))
View
@@ -1,44 +0,0 @@
-;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and
-;; distribution terms for this software are covered by the Common Public
-;; License 1.0 (http://opensource.org/licenses/cpl.php) which can be found
-;; in the file CPL.TXT 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.
-;;
-;; except.clj
-;;
-;; scgilardi (gmail)
-;; Created 07 July 2008
-
-(clojure/in-ns 'except)
-(clojure/refer 'clojure)
-
-(lib/use string)
-
-(defn throw-if
- "Throws an exception with a message if pred is true. Arguments are:
-
- pred class? format format-args*
-
- class is optional and defaults to Exception. If present, it must be a
- Class in the tree under Throwable with a constructor that takes a single
- String.
-
- format is a string as documented for java.util.Formatter.
-
- format-args are zero or more objects that correspond to the format
- specifiers in format."
- [pred & args]
- (if pred
- (let [class-present (instance? Class (first args))
- args (if class-present args (cons Exception args))
- [class fmt & fmt-args] args
- ctor (.getConstructor (identity class) (into-array [String]))
- message (apply format fmt fmt-args)
- exception (.newInstance ctor (into-array [message]))
- raw-trace (.getStackTrace exception)
- boring? #(not= (.getMethodName %) "doInvoke")
- trace (into-array (drop 2 (drop-while boring? raw-trace)))]
- (.setStackTrace exception trace)
- (throw exception))))
View
@@ -1,93 +0,0 @@
-;;; fcase.clj -- simple variants of "case" for Clojure
-
-;; by Stuart Sierra <mail@stuartsierra.com>
-;; April 7, 2008
-
-;; Copyright (c) 2008 Stuart Sierra. All rights reserved. The use and
-;; distribution terms for this software are covered by the Common
-;; Public License 1.0 (http://www.opensource.org/licenses/cpl1.0.php)
-;; which can be found in the file CPL.TXT 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.
-
-
-;; This file defines a generic "case" macro called "fcase" which takes
-;; the equality-testing function as an argument. It also defines a
-;; traditional "case" macro that tests using "=" and variants that
-;; test for regular expressions and class membership.
-
-
-(clojure/in-ns 'fcase)
-(clojure/refer 'clojure)
-
-
-(defmacro fcase
- "Generic switch/case macro. 'fcase' is short for 'function case'.
-
- The 'compare-fn' is a fn of two arguments.
-
- The 'test-expr-clauses' are value-expression pairs without
- surrounding parentheses, like in Clojure's 'cond'.
-
- The 'case-value' is evaluated once and cached. Then, 'compare-fn'
- is called once for each clause, with the clause's test value as its
- first argument and 'case-value' as its second argument. If
- 'compare-fn' returns logical true, the clause's expression is
- evaluated and returned. If 'compare-fn' returns false/nil, we go to
- the next test value.
-
- If 'test-expr-clauses' contains an odd number of items, the last
- item is the default expression evaluated if no case-value matches.
- If there is no default expression and no case-value matches, fcase
- returns nil.
-
- See specific forms of this macro in 'case' and 're-case'.
-
- The test expressions in 'fcase' are always evaluated linearly, in
- order. For a large number of case expressions it may be more
- efficient to use a hash lookup."
- [compare-fn case-value &
- test-expr-clauses]
- (let [test-val-sym (gensym "test_val")
- test-fn-sym (gensym "test_fn")
- cond-loop (fn this [clauses]
- (cond
- (>= (count clauses) 2)
- (list 'if (list test-fn-sym (first clauses) test-val-sym)
- (second clauses)
- (this (rest (rest clauses))))
- (= (count clauses) 1) (first clauses)))]
- (list 'let [test-val-sym case-value, test-fn-sym compare-fn]
- (cond-loop test-expr-clauses))))
-
-(defmacro case
- "Like cond, but test-value is compared against the value of each
- test expression with =. If they are equal, executes the \"body\"
- expression. Optional last expression is executed if none of the
- test expressions match."
- [test-value & clauses]
- `(fcase = ~test-value ~@clauses))
-
-(defmacro re-case
- "Like case, but the test expressions are regular expressions, tested
- with re-find."
- [test-value & clauses]
- `(fcase re-find ~test-value ~@clauses))
-
-(defmacro instance-case
- "Like case, but the test expressions are Java class names, tested with
- 'instance?'."
- [test-value & clauses]
- `(fcase instance? ~test-value ~@clauses))
-
-(defn- in-case-test [test-seq case-value]
- (some (fn [item] (= item case-value))
- test-seq))
-
-(defmacro in-case
- "Like case, but test expressions are sequences. The test expression
- is true if any item in the sequence is equal (tested with '=') to
- the test value."
- [test-value & clauses]
- `(fcase in-case-test ~test-value ~@clauses))
Oops, something went wrong.

0 comments on commit 8818151

Please sign in to comment.