├── .gitignore ├── build.xml ├── clojure.iml ├── doc └── clojure │ └── pprint │ ├── CommonLispFormat.markdown │ └── PrettyPrinting.markdown ├── epl-v10.html ├── pom-template.xml ├── readme.txt ├── src ├── clj │ └── clojure │ │ ├── core.clj │ │ ├── core │ │ └── protocols.clj │ │ ├── core_deftype.clj │ │ ├── core_print.clj │ │ ├── core_proxy.clj │ │ ├── genclass.clj │ │ ├── gvec.clj │ │ ├── inspector.clj │ │ ├── java │ │ ├── browse.clj │ │ ├── browse_ui.clj │ │ ├── io.clj │ │ ├── javadoc.clj │ │ └── shell.clj │ │ ├── main.clj │ │ ├── parallel.clj │ │ ├── pprint.clj │ │ ├── pprint │ │ ├── cl_format.clj │ │ ├── column_writer.clj │ │ ├── dispatch.clj │ │ ├── pprint_base.clj │ │ ├── pretty_writer.clj │ │ └── utilities.clj │ │ ├── repl.clj │ │ ├── set.clj │ │ ├── stacktrace.clj │ │ ├── string.clj │ │ ├── template.clj │ │ ├── test.clj │ │ ├── test │ │ ├── junit.clj │ │ └── tap.clj │ │ ├── version.properties │ │ ├── walk.clj │ │ ├── xml.clj │ │ └── zip.clj └── jvm │ └── clojure │ ├── asm │ ├── AnnotationVisitor.java │ ├── AnnotationWriter.java │ ├── Attribute.java │ ├── ByteVector.java │ ├── ClassAdapter.java │ ├── ClassReader.java │ ├── ClassVisitor.java │ ├── ClassWriter.java │ ├── Edge.java │ ├── FieldVisitor.java │ ├── FieldWriter.java │ ├── Frame.java │ ├── Handler.java │ ├── Item.java │ ├── Label.java │ ├── MethodAdapter.java │ ├── MethodVisitor.java │ ├── MethodWriter.java │ ├── Opcodes.java │ ├── Type.java │ ├── commons │ │ ├── AdviceAdapter.java │ │ ├── AnalyzerAdapter.java │ │ ├── CodeSizeEvaluator.java │ │ ├── EmptyVisitor.java │ │ ├── GeneratorAdapter.java │ │ ├── LocalVariablesSorter.java │ │ ├── Method.java │ │ ├── SerialVersionUIDAdder.java │ │ ├── StaticInitMerger.java │ │ ├── TableSwitchGenerator.java │ │ └── package.html │ └── package.html │ ├── lang │ ├── AFn.java │ ├── AFunction.java │ ├── AMapEntry.java │ ├── APersistentMap.java │ ├── APersistentSet.java │ ├── APersistentVector.java │ ├── ARef.java │ ├── AReference.java │ ├── ASeq.java │ ├── ATransientMap.java │ ├── ATransientSet.java │ ├── Agent.java │ ├── ArrayChunk.java │ ├── ArraySeq.java │ ├── Associative.java │ ├── Atom.java │ ├── Binding.java │ ├── Box.java │ ├── ChunkBuffer.java │ ├── ChunkedCons.java │ ├── Compile.java │ ├── Compiler.java │ ├── Cons.java │ ├── Counted.java │ ├── Delay.java │ ├── DynamicClassLoader.java │ ├── EnumerationSeq.java │ ├── Fn.java │ ├── IChunk.java │ ├── IChunkedSeq.java │ ├── IDeref.java │ ├── IEditableCollection.java │ ├── IFn.java │ ├── IKeywordLookup.java │ ├── ILookup.java │ ├── ILookupHost.java │ ├── ILookupSite.java │ ├── ILookupThunk.java │ ├── IMapEntry.java │ ├── IMeta.java │ ├── IObj.java │ ├── IPersistentCollection.java │ ├── IPersistentList.java │ ├── IPersistentMap.java │ ├── IPersistentSet.java │ ├── IPersistentStack.java │ ├── IPersistentVector.java │ ├── IProxy.java │ ├── IReduce.java │ ├── IRef.java │ ├── IReference.java │ ├── ISeq.java │ ├── ITransientAssociative.java │ ├── ITransientCollection.java │ ├── ITransientMap.java │ ├── ITransientSet.java │ ├── ITransientVector.java │ ├── Indexed.java │ ├── IndexedSeq.java │ ├── IteratorSeq.java │ ├── Keyword.java │ ├── KeywordLookupSite.java │ ├── LazilyPersistentVector.java │ ├── LazySeq.java │ ├── LineNumberingPushbackReader.java │ ├── LispReader.java │ ├── LockingTransaction.java │ ├── MapEntry.java │ ├── MethodImplCache.java │ ├── MultiFn.java │ ├── Named.java │ ├── Namespace.java │ ├── Numbers.java │ ├── Obj.java │ ├── PersistentArrayMap.java │ ├── PersistentHashMap.java │ ├── PersistentHashSet.java │ ├── PersistentList.java │ ├── PersistentQueue.java │ ├── PersistentStructMap.java │ ├── PersistentTreeMap.java │ ├── PersistentTreeSet.java │ ├── PersistentVector.java │ ├── ProxyHandler.java │ ├── RT.java │ ├── Range.java │ ├── Ratio.java │ ├── Ref.java │ ├── Reflector.java │ ├── Repl.java │ ├── RestFn.java │ ├── Reversible.java │ ├── Script.java │ ├── SeqEnumeration.java │ ├── SeqIterator.java │ ├── Seqable.java │ ├── Sequential.java │ ├── Settable.java │ ├── Sorted.java │ ├── StringSeq.java │ ├── Symbol.java │ ├── TransactionalHashMap.java │ ├── Util.java │ ├── Var.java │ └── XMLHandler.java │ └── main.java └── test └── clojure ├── test_clojure.clj └── test_clojure ├── agents.clj ├── annotations.clj ├── annotations ├── java_5.clj └── java_6_and_later.clj ├── atoms.clj ├── clojure_set.clj ├── clojure_xml.clj ├── clojure_zip.clj ├── compilation.clj ├── control.clj ├── data_structures.clj ├── def.clj ├── evaluation.clj ├── for.clj ├── genclass.clj ├── genclass └── examples.clj ├── helpers.clj ├── java ├── io.clj ├── javadoc.clj └── shell.clj ├── java_interop.clj ├── logic.clj ├── macros.clj ├── main.clj ├── metadata.clj ├── multimethods.clj ├── ns_libs.clj ├── numbers.clj ├── other_functions.clj ├── parallel.clj ├── pprint.clj ├── pprint ├── test_cl_format.clj ├── test_helper.clj └── test_pretty.clj ├── predicates.clj ├── printer.clj ├── protocols.clj ├── protocols ├── examples.clj └── more_examples.clj ├── reader.clj ├── refs.clj ├── repl.clj ├── repl └── example.clj ├── rt.clj ├── sequences.clj ├── serialization.clj ├── special.clj ├── string.clj ├── test.clj ├── test_fixtures.clj ├── test_utils.clj ├── transients.clj ├── vars.clj └── vectors.clj /.gitignore: -------------------------------------------------------------------------------- 1 | test-classes/* 2 | classes/* 3 | *jar 4 | pom.xml 5 | clojure.iws 6 | clojure.ipr 7 | nbproject/private/ 8 | *.zip 9 | dist 10 | -------------------------------------------------------------------------------- /clojure.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /pom-template.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 4.0.0 7 | org.clojure 8 | clojure 9 | clojure 10 | @clojure-version@ 11 | http://clojure.org/ 12 | 13 | Clojure core environment and runtime library. 14 | 15 | 16 | 17 | Eclipse Public License 1.0 18 | http://opensource.org/licenses/eclipse-1.0.php 19 | repo 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | ## Clojure has moved to: [https://github.com/clojure/clojure] 2 | 3 | * Clojure 4 | * Copyright (c) Rich Hickey. All rights reserved. 5 | * The use and distribution terms for this software are covered by the 6 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 7 | * which can be found in the file epl-v10.html at the root of this distribution. 8 | * By using this software in any fashion, you are agreeing to be bound by 9 | * the terms of this license. 10 | * You must not remove this notice, or any other, from this software. 11 | 12 | Docs: http://clojure.org 13 | Feedback: http://groups.google.com/group/clojure 14 | 15 | To Run: java -cp clojure.jar clojure.main 16 | To Build: ant 17 | 18 | -------------------------------------------------------------------------- 19 | This program uses the ASM bytecode engineering library which is distributed 20 | with the following notice: 21 | 22 | Copyright (c) 2000-2005 INRIA, France Telecom 23 | All rights reserved. 24 | 25 | Redistribution and use in source and binary forms, with or without 26 | modification, are permitted provided that the following conditions 27 | are met: 28 | 29 | 1. Redistributions of source code must retain the above copyright 30 | notice, this list of conditions and the following disclaimer. 31 | 32 | 2. Redistributions in binary form must reproduce the above copyright 33 | notice, this list of conditions and the following disclaimer in the 34 | documentation and/or other materials provided with the distribution. 35 | 36 | 3. Neither the name of the copyright holders nor the names of its 37 | contributors may be used to endorse or promote products derived from 38 | this software without specific prior written permission. 39 | 40 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 41 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 44 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 45 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 46 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 47 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 48 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 49 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 50 | THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /src/clj/clojure/core/protocols.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.core.protocols) 10 | 11 | (defprotocol InternalReduce 12 | "Protocol for concrete seq types that can reduce themselves 13 | faster than first/next recursion. Called by clojure.core/reduce." 14 | (internal-reduce [seq f start])) 15 | 16 | (extend-protocol InternalReduce 17 | nil 18 | (internal-reduce 19 | [s f val] 20 | val) 21 | 22 | ;; handles vectors and ranges 23 | clojure.lang.IChunkedSeq 24 | (internal-reduce 25 | [s f val] 26 | (if-let [s (seq s)] 27 | (if (chunked-seq? s) 28 | (recur (chunk-next s) 29 | f 30 | (.reduce (chunk-first s) f val)) 31 | (internal-reduce s f val)) 32 | val)) 33 | 34 | clojure.lang.StringSeq 35 | (internal-reduce 36 | [str-seq f val] 37 | (let [s (.s str-seq)] 38 | (loop [i (.i str-seq) 39 | val val] 40 | (if (< i (.length s)) 41 | (recur (inc i) (f val (.charAt s i))) 42 | val)))) 43 | 44 | clojure.lang.ArraySeq 45 | (internal-reduce 46 | [a-seq f val] 47 | (let [^objects arr (.array a-seq)] 48 | (loop [i (.index a-seq) 49 | val val] 50 | (if (< i (alength arr)) 51 | (recur (inc i) (f val (aget arr i))) 52 | val)))) 53 | 54 | java.lang.Object 55 | (internal-reduce 56 | [s f val] 57 | (loop [cls (class s) 58 | s s 59 | f f 60 | val val] 61 | (if-let [s (seq s)] 62 | ;; roll over to faster implementation if underlying seq changes type 63 | (if (identical? (class s) cls) 64 | (recur cls (next s) f (f val (first s))) 65 | (internal-reduce s f val)) 66 | val)))) 67 | 68 | (def arr-impl 69 | '(internal-reduce 70 | [a-seq f val] 71 | (let [arr (.array a-seq)] 72 | (loop [i (.index a-seq) 73 | val val] 74 | (if (< i (alength arr)) 75 | (recur (inc i) (f val (aget arr i))) 76 | val))))) 77 | 78 | (defn- emit-array-impls* 79 | [syms] 80 | (apply 81 | concat 82 | (map 83 | (fn [s] 84 | [(symbol (str "clojure.lang.ArraySeq$ArraySeq_" s)) 85 | arr-impl]) 86 | syms))) 87 | 88 | (defmacro emit-array-impls 89 | [& syms] 90 | `(extend-protocol InternalReduce 91 | ~@(emit-array-impls* syms))) 92 | 93 | (emit-array-impls int long float double byte char boolean) 94 | 95 | -------------------------------------------------------------------------------- /src/clj/clojure/java/browse.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | (ns 10 | ^{:author "Christophe Grand", 11 | :doc "Start a web browser from Clojure"} 12 | clojure.java.browse 13 | (:require [clojure.java.shell :as sh]) 14 | (:import (java.net URI))) 15 | 16 | (defn- macosx? [] 17 | (-> "os.name" System/getProperty .toLowerCase 18 | (.startsWith "mac os x"))) 19 | 20 | (def *open-url-script* (when (macosx?) "/usr/bin/open")) 21 | 22 | (defn- open-url-in-browser 23 | "Opens url (a string) in the default system web browser. May not 24 | work on all platforms. Returns url on success, nil if not 25 | supported." 26 | [url] 27 | (try 28 | (when (clojure.lang.Reflector/invokeStaticMethod "java.awt.Desktop" 29 | "isDesktopSupported" (to-array nil)) 30 | (-> (clojure.lang.Reflector/invokeStaticMethod "java.awt.Desktop" 31 | "getDesktop" (to-array nil)) 32 | (.browse (URI. url))) 33 | url) 34 | (catch ClassNotFoundException e 35 | nil))) 36 | 37 | (defn- open-url-in-swing 38 | "Opens url (a string) in a Swing window." 39 | [url] 40 | ; the implementation of this function resides in another namespace to be loaded "on demand" 41 | ; this fixes a bug on mac os x where the process turns into a GUI app 42 | ; see http://code.google.com/p/clojure-contrib/issues/detail?id=32 43 | (require 'clojure.java.browse-ui) 44 | ((find-var 'clojure.java.browse-ui/open-url-in-swing) url)) 45 | 46 | (defn browse-url 47 | "Open url in a browser" 48 | {:added "1.2"} 49 | [url] 50 | (or (open-url-in-browser url) 51 | (when *open-url-script* (sh/sh *open-url-script* (str url)) true) 52 | (open-url-in-swing url))) 53 | -------------------------------------------------------------------------------- /src/clj/clojure/java/browse_ui.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | (ns 10 | ^{:author "Christophe Grand", 11 | :doc "Helper namespace for clojure.java.browse. 12 | Prevents console apps from becoming GUI unnecessarily."} 13 | clojure.java.browse-ui) 14 | 15 | (defn- open-url-in-swing 16 | [url] 17 | (let [htmlpane (javax.swing.JEditorPane. url)] 18 | (.setEditable htmlpane false) 19 | (.addHyperlinkListener htmlpane 20 | (proxy [javax.swing.event.HyperlinkListener] [] 21 | (hyperlinkUpdate [#^javax.swing.event.HyperlinkEvent e] 22 | (when (= (.getEventType e) (. javax.swing.event.HyperlinkEvent$EventType ACTIVATED)) 23 | (if (instance? javax.swing.text.html.HTMLFrameHyperlinkEvent e) 24 | (-> htmlpane .getDocument (.processHTMLFrameHyperlinkEvent e)) 25 | (.setPage htmlpane (.getURL e))))))) 26 | (doto (javax.swing.JFrame.) 27 | (.setContentPane (javax.swing.JScrollPane. htmlpane)) 28 | (.setBounds 32 32 700 900) 29 | (.show)))) 30 | 31 | -------------------------------------------------------------------------------- /src/clj/clojure/java/javadoc.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | (ns 9 | ^{:author "Christophe Grand, Stuart Sierra", 10 | :doc "A repl helper to quickly open javadocs."} 11 | clojure.java.javadoc 12 | (:use [clojure.java.browse :only (browse-url)] ) 13 | (:import 14 | (java.io File))) 15 | 16 | (def *feeling-lucky-url* "http://www.google.com/search?btnI=I%27m%20Feeling%20Lucky&q=allinurl:") 17 | (def *feeling-lucky* true) 18 | 19 | (def *local-javadocs* (ref (list))) 20 | 21 | (def *core-java-api* 22 | (if (= "1.5" (System/getProperty "java.specification.version")) 23 | "http://java.sun.com/j2se/1.5.0/docs/api/" 24 | "http://java.sun.com/javase/6/docs/api/")) 25 | 26 | (def *remote-javadocs* 27 | (ref (sorted-map 28 | "java." *core-java-api* 29 | "javax." *core-java-api* 30 | "org.ietf.jgss." *core-java-api* 31 | "org.omg." *core-java-api* 32 | "org.w3c.dom." *core-java-api* 33 | "org.xml.sax." *core-java-api* 34 | "org.apache.commons.codec." "http://commons.apache.org/codec/api-release/" 35 | "org.apache.commons.io." "http://commons.apache.org/io/api-release/" 36 | "org.apache.commons.lang." "http://commons.apache.org/lang/api-release/"))) 37 | 38 | (defn add-local-javadoc 39 | "Adds to the list of local Javadoc paths." 40 | {:added "1.2"} 41 | [path] 42 | (dosync (commute *local-javadocs* conj path))) 43 | 44 | (defn add-remote-javadoc 45 | "Adds to the list of remote Javadoc URLs. package-prefix is the 46 | beginning of the package name that has docs at this URL." 47 | {:added "1.2"} 48 | [package-prefix url] 49 | (dosync (commute *remote-javadocs* assoc package-prefix url))) 50 | 51 | (defn- javadoc-url 52 | "Searches for a URL for the given class name. Tries 53 | *local-javadocs* first, then *remote-javadocs*. Returns a string." 54 | {:tag String, 55 | :added "1.2"} 56 | [^String classname] 57 | (let [file-path (.replace classname \. File/separatorChar) 58 | url-path (.replace classname \. \/)] 59 | (if-let [file ^File (first 60 | (filter #(.exists ^File %) 61 | (map #(File. (str %) (str file-path ".html")) 62 | @*local-javadocs*)))] 63 | (-> file .toURI str) 64 | ;; If no local file, try remote URLs: 65 | (or (some (fn [[prefix url]] 66 | (when (.startsWith classname prefix) 67 | (str url url-path ".html"))) 68 | @*remote-javadocs*) 69 | ;; if *feeling-lucky* try a web search 70 | (when *feeling-lucky* (str *feeling-lucky-url* url-path ".html")))))) 71 | 72 | (defn javadoc 73 | "Opens a browser window displaying the javadoc for the argument. 74 | Tries *local-javadocs* first, then *remote-javadocs*." 75 | {:added "1.2"} 76 | [class-or-object] 77 | (let [^Class c (if (instance? Class class-or-object) 78 | class-or-object 79 | (class class-or-object))] 80 | (if-let [url (javadoc-url (.getName c))] 81 | (browse-url url) 82 | (println "Could not find Javadoc for" c)))) 83 | -------------------------------------------------------------------------------- /src/clj/clojure/pprint.clj: -------------------------------------------------------------------------------- 1 | ;;; pprint.clj -- Pretty printer and Common Lisp compatible format function (cl-format) for Clojure 2 | 3 | ; Copyright (c) Rich Hickey. All rights reserved. 4 | ; The use and distribution terms for this software are covered by the 5 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 6 | ; which can be found in the file epl-v10.html at the root of this distribution. 7 | ; By using this software in any fashion, you are agreeing to be bound by 8 | ; the terms of this license. 9 | ; You must not remove this notice, or any other, from this software. 10 | 11 | ;; Author: Tom Faulhaber 12 | ;; April 3, 2009 13 | 14 | (ns 15 | ^{:author "Tom Faulhaber", 16 | :doc "A Pretty Printer for Clojure 17 | 18 | clojure.pprint implements a flexible system for printing structured data 19 | in a pleasing, easy-to-understand format. Basic use of the pretty printer is 20 | simple, just call pprint instead of println. More advanced users can use 21 | the building blocks provided to create custom output formats. 22 | 23 | Out of the box, pprint supports a simple structured format for basic data 24 | and a specialized format for Clojure source code. More advanced formats, 25 | including formats that don't look like Clojure data at all like XML and 26 | JSON, can be rendered by creating custom dispatch functions. 27 | 28 | In addition to the pprint function, this module contains cl-format, a text 29 | formatting function which is fully compatible with the format function in 30 | Common Lisp. Because pretty printing directives are directly integrated with 31 | cl-format, it supports very concise custom dispatch. It also provides 32 | a more powerful alternative to Clojure's standard format function. 33 | 34 | See documentation for pprint and cl-format for more information or 35 | complete documentation on the the clojure web site on github.", 36 | :added "1.2"} 37 | clojure.pprint 38 | (:refer-clojure :exclude (deftype))) 39 | 40 | 41 | (load "pprint/utilities") 42 | (load "pprint/column_writer") 43 | (load "pprint/pretty_writer") 44 | (load "pprint/pprint_base") 45 | (load "pprint/cl_format") 46 | (load "pprint/dispatch") 47 | 48 | nil 49 | -------------------------------------------------------------------------------- /src/clj/clojure/pprint/column_writer.clj: -------------------------------------------------------------------------------- 1 | ;;; column_writer.clj -- part of the pretty printer for Clojure 2 | 3 | 4 | ; Copyright (c) Rich Hickey. All rights reserved. 5 | ; The use and distribution terms for this software are covered by the 6 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 7 | ; which can be found in the file epl-v10.html at the root of this distribution. 8 | ; By using this software in any fashion, you are agreeing to be bound by 9 | ; the terms of this license. 10 | ; You must not remove this notice, or any other, from this software. 11 | 12 | ;; Author: Tom Faulhaber 13 | ;; April 3, 2009 14 | ;; Revised to use proxy instead of gen-class April 2010 15 | 16 | ;; This module implements a column-aware wrapper around an instance of java.io.Writer 17 | 18 | (in-ns 'clojure.pprint) 19 | 20 | (import [clojure.lang IDeref] 21 | [java.io Writer]) 22 | 23 | (def ^{:private true} *default-page-width* 72) 24 | 25 | (defn- get-field [^Writer this sym] 26 | (sym @@this)) 27 | 28 | (defn- set-field [^Writer this sym new-val] 29 | (alter @this assoc sym new-val)) 30 | 31 | (defn- get-column [this] 32 | (get-field this :cur)) 33 | 34 | (defn- get-line [this] 35 | (get-field this :line)) 36 | 37 | (defn- get-max-column [this] 38 | (get-field this :max)) 39 | 40 | (defn- set-max-column [this new-max] 41 | (dosync (set-field this :max new-max)) 42 | nil) 43 | 44 | (defn- get-writer [this] 45 | (get-field this :base)) 46 | 47 | (defn- c-write-char [^Writer this ^Integer c] 48 | (dosync (if (= c (int \newline)) 49 | (do 50 | (set-field this :cur 0) 51 | (set-field this :line (inc (get-field this :line)))) 52 | (set-field this :cur (inc (get-field this :cur))))) 53 | (.write ^Writer (get-field this :base) c)) 54 | 55 | (defn- column-writer 56 | ([writer] (column-writer writer *default-page-width*)) 57 | ([writer max-columns] 58 | (let [fields (ref {:max max-columns, :cur 0, :line 0 :base writer})] 59 | (proxy [Writer IDeref] [] 60 | (deref [] fields) 61 | (write 62 | ([^chars cbuf ^Integer off ^Integer len] 63 | (let [^Writer writer (get-field this :base)] 64 | (.write writer cbuf off len))) 65 | ([x] 66 | (condp = (class x) 67 | String 68 | (let [^String s x 69 | nl (.lastIndexOf s (int \newline))] 70 | (dosync (if (neg? nl) 71 | (set-field this :cur (+ (get-field this :cur) (count s))) 72 | (do 73 | (set-field this :cur (- (count s) nl 1)) 74 | (set-field this :line (+ (get-field this :line) 75 | (count (filter #(= % \newline) s))))))) 76 | (.write ^Writer (get-field this :base) s)) 77 | 78 | Integer 79 | (c-write-char this x)))))))) 80 | -------------------------------------------------------------------------------- /src/clj/clojure/repl.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Chris Houser, Dec 2008. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Common Public License 1.0 (http://opensource.org/licenses/cpl.php) 4 | ; which can be found in the file CPL.TXT at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ; Utilities meant to be used interactively at the REPL 10 | 11 | (ns 12 | #^{:author "Chris Houser, Christophe Grand, Stephen Gilardi, Michel Salim, Christophe Grande" 13 | :doc "Utilities meant to be used interactively at the REPL"} 14 | clojure.repl 15 | (:import (java.io LineNumberReader InputStreamReader PushbackReader) 16 | (clojure.lang RT Reflector))) 17 | 18 | ;; ---------------------------------------------------------------------- 19 | ;; Examine Clojure functions (Vars, really) 20 | 21 | (defn source-fn 22 | "Returns a string of the source code for the given symbol, if it can 23 | find it. This requires that the symbol resolve to a Var defined in 24 | a namespace for which the .clj is in the classpath. Returns nil if 25 | it can't find the source. For most REPL usage, 'source' is more 26 | convenient. 27 | 28 | Example: (source-fn 'filter)" 29 | [x] 30 | (when-let [v (resolve x)] 31 | (when-let [filepath (:file (meta v))] 32 | (when-let [strm (.getResourceAsStream (RT/baseLoader) filepath)] 33 | (with-open [rdr (LineNumberReader. (InputStreamReader. strm))] 34 | (dotimes [_ (dec (:line (meta v)))] (.readLine rdr)) 35 | (let [text (StringBuilder.) 36 | pbr (proxy [PushbackReader] [rdr] 37 | (read [] (let [i (proxy-super read)] 38 | (.append text (char i)) 39 | i)))] 40 | (read (PushbackReader. pbr)) 41 | (str text))))))) 42 | 43 | (defmacro source 44 | "Prints the source code for the given symbol, if it can find it. 45 | This requires that the symbol resolve to a Var defined in a 46 | namespace for which the .clj is in the classpath. 47 | 48 | Example: (source filter)" 49 | [n] 50 | `(println (or (source-fn '~n) (str "Source not found")))) 51 | 52 | (defn apropos 53 | "Given a regular expression or stringable thing, return a seq of 54 | all definitions in all currently-loaded namespaces that match the 55 | str-or-pattern." 56 | [str-or-pattern] 57 | (let [matches? (if (instance? java.util.regex.Pattern str-or-pattern) 58 | #(re-find str-or-pattern (str %)) 59 | #(.contains (str %) (str str-or-pattern)))] 60 | (mapcat (fn [ns] 61 | (filter matches? (keys (ns-publics ns)))) 62 | (all-ns)))) 63 | 64 | (defn dir-fn 65 | "Returns a sorted seq of symbols naming public vars in 66 | a namespace" 67 | [ns] 68 | (sort (map first (ns-publics (the-ns ns))))) 69 | 70 | (defmacro dir 71 | "Prints a sorted directory of public vars in a namespace" 72 | [nsname] 73 | `(doseq [v# (dir-fn '~nsname)] 74 | (println v#))) 75 | -------------------------------------------------------------------------------- /src/clj/clojure/stacktrace.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ;;; stacktrace.clj: print Clojure-centric stack traces 10 | 11 | ;; by Stuart Sierra 12 | ;; January 6, 2009 13 | 14 | (ns ^{:doc "Print stack traces oriented towards Clojure, not Java." 15 | :author "Stuart Sierra"} 16 | clojure.stacktrace) 17 | 18 | (defn root-cause 19 | "Returns the last 'cause' Throwable in a chain of Throwables." 20 | {:added "1.1"} 21 | [tr] 22 | (if-let [cause (.getCause tr)] 23 | (recur cause) 24 | tr)) 25 | 26 | (defn print-trace-element 27 | "Prints a Clojure-oriented view of one element in a stack trace." 28 | {:added "1.1"} 29 | [e] 30 | (let [class (.getClassName e) 31 | method (.getMethodName e)] 32 | (let [match (re-matches #"^([A-Za-z0-9_.-]+)\$(\w+)__\d+$" class)] 33 | (if (and match (= "invoke" method)) 34 | (apply printf "%s/%s" (rest match)) 35 | (printf "%s.%s" class method)))) 36 | (printf " (%s:%d)" (or (.getFileName e) "") (.getLineNumber e))) 37 | 38 | (defn print-throwable 39 | "Prints the class and message of a Throwable." 40 | {:added "1.1"} 41 | [tr] 42 | (printf "%s: %s" (.getName (class tr)) (.getMessage tr))) 43 | 44 | (defn print-stack-trace 45 | "Prints a Clojure-oriented stack trace of tr, a Throwable. 46 | Prints a maximum of n stack frames (default: unlimited). 47 | Does not print chained exceptions (causes)." 48 | {:added "1.1"} 49 | ([tr] (print-stack-trace tr nil)) 50 | ([tr n] 51 | (let [st (.getStackTrace tr)] 52 | (print-throwable tr) 53 | (newline) 54 | (print " at ") 55 | (print-trace-element (first st)) 56 | (newline) 57 | (doseq [e (if (nil? n) 58 | (rest st) 59 | (take (dec n) (rest st)))] 60 | (print " ") 61 | (print-trace-element e) 62 | (newline))))) 63 | 64 | (defn print-cause-trace 65 | "Like print-stack-trace but prints chained exceptions (causes)." 66 | {:added "1.1"} 67 | ([tr] (print-cause-trace tr nil)) 68 | ([tr n] 69 | (print-stack-trace tr n) 70 | (when-let [cause (.getCause tr)] 71 | (print "Caused by: " ) 72 | (recur cause n)))) 73 | 74 | (defn e 75 | "REPL utility. Prints a brief stack trace for the root cause of the 76 | most recent exception." 77 | {:added "1.1"} 78 | [] 79 | (print-stack-trace (root-cause *e) 8)) 80 | -------------------------------------------------------------------------------- /src/clj/clojure/template.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ;;; template.clj - anonymous functions that pre-evaluate sub-expressions 10 | 11 | ;; By Stuart Sierra 12 | ;; June 23, 2009 13 | 14 | ;; CHANGE LOG 15 | ;; 16 | ;; June 23, 2009: complete rewrite, eliminated _1,_2,... argument 17 | ;; syntax 18 | ;; 19 | ;; January 20, 2009: added "template?" and checks for valid template 20 | ;; expressions. 21 | ;; 22 | ;; December 15, 2008: first version 23 | 24 | 25 | (ns ^{:doc "Macros that expand to repeated copies of a template expression." 26 | :author "Stuart Sierra"} 27 | clojure.template 28 | (:require [clojure.walk :as walk])) 29 | 30 | (defn apply-template 31 | "For use in macros. argv is an argument list, as in defn. expr is 32 | a quoted expression using the symbols in argv. values is a sequence 33 | of values to be used for the arguments. 34 | 35 | apply-template will recursively replace argument symbols in expr 36 | with their corresponding values, returning a modified expr. 37 | 38 | Example: (apply-template '[x] '(+ x x) '[2]) 39 | ;=> (+ 2 2)" 40 | [argv expr values] 41 | (assert (vector? argv)) 42 | (assert (every? symbol? argv)) 43 | (walk/prewalk-replace (zipmap argv values) expr)) 44 | 45 | (defmacro do-template 46 | "Repeatedly copies expr (in a do block) for each group of arguments 47 | in values. values are automatically partitioned by the number of 48 | arguments in argv, an argument vector as in defn. 49 | 50 | Example: (macroexpand '(do-template [x y] (+ y x) 2 4 3 5)) 51 | ;=> (do (+ 4 2) (+ 5 3))" 52 | [argv expr & values] 53 | (let [c (count argv)] 54 | `(do ~@(map (fn [a] (apply-template argv expr a)) 55 | (partition c values))))) 56 | -------------------------------------------------------------------------------- /src/clj/clojure/test/tap.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ;;; test_is/tap.clj: Extension to test for TAP output 10 | 11 | ;; by Stuart Sierra 12 | ;; March 31, 2009 13 | 14 | ;; Inspired by ClojureCheck by Meikel Brandmeyer: 15 | ;; http://kotka.de/projects/clojure/clojurecheck.html 16 | 17 | 18 | ;; DOCUMENTATION 19 | ;; 20 | 21 | 22 | 23 | (ns ^{:doc "clojure.test extensions for the Test Anything Protocol (TAP) 24 | 25 | TAP is a simple text-based syntax for reporting test results. TAP 26 | was originally develped for Perl, and now has implementations in 27 | several languages. For more information on TAP, see 28 | http://testanything.org/ and 29 | http://search.cpan.org/~petdance/TAP-1.0.0/TAP.pm 30 | 31 | To use this library, wrap any calls to 32 | clojure.test/run-tests in the with-tap-output macro, 33 | like this: 34 | 35 | (use 'clojure.test) 36 | (use 'clojure.test.tap) 37 | 38 | (with-tap-output 39 | (run-tests 'my.cool.library))" 40 | :author "Stuart Sierra"} 41 | clojure.test.tap 42 | (:require [clojure.test :as t] 43 | [clojure.stacktrace :as stack])) 44 | 45 | (defn print-tap-plan 46 | "Prints a TAP plan line like '1..n'. n is the number of tests" 47 | {:added "1.1"} 48 | [n] 49 | (println (str "1.." n))) 50 | 51 | (defn print-tap-diagnostic 52 | "Prints a TAP diagnostic line. data is a (possibly multi-line) 53 | string." 54 | {:added "1.1"} 55 | [data] 56 | (doseq [line (.split ^String data "\n")] 57 | (println "#" line))) 58 | 59 | (defn print-tap-pass 60 | "Prints a TAP 'ok' line. msg is a string, with no line breaks" 61 | {:added "1.1"} 62 | [msg] 63 | (println "ok" msg)) 64 | 65 | (defn print-tap-fail 66 | "Prints a TAP 'not ok' line. msg is a string, with no line breaks" 67 | {:added "1.1"} 68 | [msg] 69 | (println "not ok" msg)) 70 | 71 | ;; This multimethod will override test/report 72 | (defmulti tap-report (fn [data] (:type data))) 73 | 74 | (defmethod tap-report :default [data] 75 | (t/with-test-out 76 | (print-tap-diagnostic (pr-str data)))) 77 | 78 | (defmethod tap-report :pass [data] 79 | (t/with-test-out 80 | (t/inc-report-counter :pass) 81 | (print-tap-pass (t/testing-vars-str)) 82 | (when (seq t/*testing-contexts*) 83 | (print-tap-diagnostic (t/testing-contexts-str))) 84 | (when (:message data) 85 | (print-tap-diagnostic (:message data))) 86 | (print-tap-diagnostic (str "expected:" (pr-str (:expected data)))) 87 | (print-tap-diagnostic (str " actual:" (pr-str (:actual data)))))) 88 | 89 | (defmethod tap-report :error [data] 90 | (t/with-test-out 91 | (t/inc-report-counter :error) 92 | (print-tap-fail (t/testing-vars-str)) 93 | (when (seq t/*testing-contexts*) 94 | (print-tap-diagnostic (t/testing-contexts-str))) 95 | (when (:message data) 96 | (print-tap-diagnostic (:message data))) 97 | (print-tap-diagnostic "expected:" (pr-str (:expected data))) 98 | (print-tap-diagnostic " actual: ") 99 | (print-tap-diagnostic 100 | (with-out-str 101 | (if (instance? Throwable (:actual data)) 102 | (stack/print-cause-trace (:actual data) t/*stack-trace-depth*) 103 | (prn (:actual data))))))) 104 | 105 | (defmethod tap-report :summary [data] 106 | (t/with-test-out 107 | (print-tap-plan (+ (:pass data) (:fail data) (:error data))))) 108 | 109 | 110 | (defmacro with-tap-output 111 | "Execute body with modified test reporting functions that produce 112 | TAP output" 113 | {:added "1.1"} 114 | [& body] 115 | `(binding [t/report tap-report] 116 | ~@body)) 117 | -------------------------------------------------------------------------------- /src/clj/clojure/version.properties: -------------------------------------------------------------------------------- 1 | clojure.version.major=1 2 | clojure.version.minor=2 3 | clojure.version.incremental=0 4 | clojure.version.qualifier=master 5 | clojure.version.interim=true 6 | -------------------------------------------------------------------------------- /src/jvm/clojure/asm/Edge.java: -------------------------------------------------------------------------------- 1 | /*** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2005 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package clojure.asm; 31 | 32 | /** 33 | * An edge in the control flow graph of a method body. See {@link Label Label}. 34 | * 35 | * @author Eric Bruneton 36 | */ 37 | class Edge{ 38 | 39 | /** 40 | * Denotes a normal control flow graph edge. 41 | */ 42 | final static int NORMAL = 0; 43 | 44 | /** 45 | * Denotes a control flow graph edge corresponding to an exception handler. 46 | * More precisely any {@link Edge} whose {@link #info} is strictly positive 47 | * corresponds to an exception handler. The actual value of {@link #info} is 48 | * the index, in the {@link ClassWriter} type table, of the exception that 49 | * is catched. 50 | */ 51 | final static int EXCEPTION = 0x7FFFFFFF; 52 | 53 | /** 54 | * Information about this control flow graph edge. If 55 | * {@link ClassWriter#COMPUTE_MAXS} is used this field is the (relative) 56 | * stack size in the basic block from which this edge originates. This size 57 | * is equal to the stack size at the "jump" instruction to which this edge 58 | * corresponds, relatively to the stack size at the beginning of the 59 | * originating basic block. If {@link ClassWriter#COMPUTE_FRAMES} is used, 60 | * this field is the kind of this control flow graph edge (i.e. NORMAL or 61 | * EXCEPTION). 62 | */ 63 | int info; 64 | 65 | /** 66 | * The successor block of the basic block from which this edge originates. 67 | */ 68 | Label successor; 69 | 70 | /** 71 | * The next edge in the list of successors of the originating basic block. 72 | * See {@link Label#successors successors}. 73 | */ 74 | Edge next; 75 | } 76 | -------------------------------------------------------------------------------- /src/jvm/clojure/asm/FieldVisitor.java: -------------------------------------------------------------------------------- 1 | /*** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2005 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package clojure.asm; 31 | 32 | /** 33 | * A visitor to visit a Java field. The methods of this interface must be called 34 | * in the following order: ( visitAnnotation | 35 | * visitAttribute )* visitEnd. 36 | * 37 | * @author Eric Bruneton 38 | */ 39 | public interface FieldVisitor{ 40 | 41 | /** 42 | * Visits an annotation of the field. 43 | * 44 | * @param desc the class descriptor of the annotation class. 45 | * @param visible true if the annotation is visible at runtime. 46 | * @return a visitor to visit the annotation values, or null if 47 | * this visitor is not interested in visiting this annotation. 48 | */ 49 | AnnotationVisitor visitAnnotation(String desc, boolean visible); 50 | 51 | /** 52 | * Visits a non standard attribute of the field. 53 | * 54 | * @param attr an attribute. 55 | */ 56 | void visitAttribute(Attribute attr); 57 | 58 | /** 59 | * Visits the end of the field. This method, which is the last one to be 60 | * called, is used to inform the visitor that all the annotations and 61 | * attributes of the field have been visited. 62 | */ 63 | void visitEnd(); 64 | } 65 | -------------------------------------------------------------------------------- /src/jvm/clojure/asm/Handler.java: -------------------------------------------------------------------------------- 1 | /*** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2005 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package clojure.asm; 31 | 32 | /** 33 | * Information about an exception handler block. 34 | * 35 | * @author Eric Bruneton 36 | */ 37 | class Handler{ 38 | 39 | /** 40 | * Beginning of the exception handler's scope (inclusive). 41 | */ 42 | Label start; 43 | 44 | /** 45 | * End of the exception handler's scope (exclusive). 46 | */ 47 | Label end; 48 | 49 | /** 50 | * Beginning of the exception handler's code. 51 | */ 52 | Label handler; 53 | 54 | /** 55 | * Internal name of the type of exceptions handled by this handler, or 56 | * null to catch any exceptions. 57 | */ 58 | String desc; 59 | 60 | /** 61 | * Constant pool index of the internal name of the type of exceptions 62 | * handled by this handler, or 0 to catch any exceptions. 63 | */ 64 | int type; 65 | 66 | /** 67 | * Next exception handler block info. 68 | */ 69 | Handler next; 70 | } 71 | -------------------------------------------------------------------------------- /src/jvm/clojure/asm/commons/StaticInitMerger.java: -------------------------------------------------------------------------------- 1 | /*** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2005 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package clojure.asm.commons; 31 | 32 | import clojure.asm.ClassAdapter; 33 | import clojure.asm.ClassVisitor; 34 | import clojure.asm.MethodVisitor; 35 | import clojure.asm.Opcodes; 36 | 37 | /** 38 | * A {@link ClassAdapter} that merges clinit methods into a single one. 39 | * 40 | * @author Eric Bruneton 41 | */ 42 | public class StaticInitMerger extends ClassAdapter{ 43 | 44 | private String name; 45 | 46 | private MethodVisitor clinit; 47 | 48 | private String prefix; 49 | 50 | private int counter; 51 | 52 | public StaticInitMerger(final String prefix, final ClassVisitor cv){ 53 | super(cv); 54 | this.prefix = prefix; 55 | } 56 | 57 | public void visit( 58 | final int version, 59 | final int access, 60 | final String name, 61 | final String signature, 62 | final String superName, 63 | final String[] interfaces){ 64 | cv.visit(version, access, name, signature, superName, interfaces); 65 | this.name = name; 66 | } 67 | 68 | public MethodVisitor visitMethod( 69 | final int access, 70 | final String name, 71 | final String desc, 72 | final String signature, 73 | final String[] exceptions){ 74 | MethodVisitor mv; 75 | if(name.equals("")) 76 | { 77 | int a = Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC; 78 | String n = prefix + counter++; 79 | mv = cv.visitMethod(a, n, desc, signature, exceptions); 80 | 81 | if(clinit == null) 82 | { 83 | clinit = cv.visitMethod(a, name, desc, null, null); 84 | } 85 | clinit.visitMethodInsn(Opcodes.INVOKESTATIC, this.name, n, desc); 86 | } 87 | else 88 | { 89 | mv = cv.visitMethod(access, name, desc, signature, exceptions); 90 | } 91 | return mv; 92 | } 93 | 94 | public void visitEnd(){ 95 | if(clinit != null) 96 | { 97 | clinit.visitInsn(Opcodes.RETURN); 98 | clinit.visitMaxs(0, 0); 99 | } 100 | cv.visitEnd(); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/jvm/clojure/asm/commons/TableSwitchGenerator.java: -------------------------------------------------------------------------------- 1 | /*** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2005 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package clojure.asm.commons; 31 | 32 | import clojure.asm.Label; 33 | 34 | /** 35 | * A code generator for switch statements. 36 | * 37 | * @author Juozas Baliuka 38 | * @author Chris Nokleberg 39 | * @author Eric Bruneton 40 | */ 41 | public interface TableSwitchGenerator{ 42 | 43 | /** 44 | * Generates the code for a switch case. 45 | * 46 | * @param key the switch case key. 47 | * @param end a label that corresponds to the end of the switch statement. 48 | */ 49 | void generateCase(int key, Label end); 50 | 51 | /** 52 | * Generates the code for the default switch case. 53 | */ 54 | void generateDefault(); 55 | } 56 | -------------------------------------------------------------------------------- /src/jvm/clojure/asm/commons/package.html: -------------------------------------------------------------------------------- 1 | 2 | 31 | 32 | Provides some useful class and method adapters. The preferred way of using 33 | these adapters is by chaining them together and to custom adapters (instead of 34 | inheriting from them). Indeed this approach provides more combination 35 | possibilities than inheritance. For instance, suppose you want to implement an 36 | adapter MyAdapter than needs sorted local variables and intermediate stack map 37 | frame values taking into account the local variables sort. By using inheritance, 38 | this would require MyAdapter to extend AnalyzerAdapter, itself extending 39 | LocalVariablesSorter. But AnalyzerAdapter is not a subclass of 40 | LocalVariablesSorter, so this is not possible. On the contrary, by using 41 | delegation, you can make LocalVariablesSorter delegate to AnalyzerAdapter, 42 | itself delegating to MyAdapter. In this case AnalyzerAdapter computes 43 | intermediate frames based on the output of LocalVariablesSorter, and MyAdapter 44 | can add new locals by calling the newLocal method on LocalVariablesSorter, and 45 | can get the stack map frame state before each instruction by reading the locals 46 | and stack fields in AnalyzerAdapter (this requires references from MyAdapter 47 | back to LocalVariablesSorter and AnalyzerAdapter). 48 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/AFunction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Dec 16, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | import java.io.Serializable; 16 | import java.util.Comparator; 17 | 18 | public abstract class AFunction extends AFn implements IObj, Comparator, Fn, Serializable { 19 | 20 | public volatile MethodImplCache __methodImplCache; 21 | 22 | public int compare(Object o1, Object o2){ 23 | try 24 | { 25 | Object o = invoke(o1, o2); 26 | 27 | if(o instanceof Boolean) 28 | { 29 | if(RT.booleanCast(o)) 30 | return -1; 31 | return RT.booleanCast(invoke(o2,o1))? 1 : 0; 32 | } 33 | 34 | Number n = (Number) o; 35 | return n.intValue(); 36 | } 37 | catch(Exception e) 38 | { 39 | throw new RuntimeException(e); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/AMapEntry.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Mar 1, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | import java.io.StringWriter; 16 | 17 | public abstract class AMapEntry extends APersistentVector implements IMapEntry{ 18 | 19 | public Object nth(int i){ 20 | if(i == 0) 21 | return key(); 22 | else if(i == 1) 23 | return val(); 24 | else 25 | throw new IndexOutOfBoundsException(); 26 | } 27 | 28 | private IPersistentVector asVector(){ 29 | return LazilyPersistentVector.createOwning(key(), val()); 30 | } 31 | 32 | public IPersistentVector assocN(int i, Object val){ 33 | return asVector().assocN(i, val); 34 | } 35 | 36 | public int count(){ 37 | return 2; 38 | } 39 | 40 | public ISeq seq(){ 41 | return asVector().seq(); 42 | } 43 | 44 | public IPersistentVector cons(Object o){ 45 | return asVector().cons(o); 46 | } 47 | 48 | public IPersistentCollection empty(){ 49 | return null; 50 | } 51 | 52 | public IPersistentStack pop(){ 53 | return LazilyPersistentVector.createOwning(key()); 54 | } 55 | 56 | public Object setValue(Object value){ 57 | throw new UnsupportedOperationException(); 58 | } 59 | 60 | /* 61 | 62 | public boolean equals(Object obj){ 63 | return APersistentVector.doEquals(this, obj); 64 | } 65 | 66 | public int hashCode(){ 67 | //must match logic in APersistentVector 68 | return 31 * (31 + Util.hash(key())) + Util.hash(val()); 69 | // return Util.hashCombine(Util.hashCombine(0, Util.hash(key())), Util.hash(val())); 70 | } 71 | 72 | public String toString(){ 73 | StringWriter sw = new StringWriter(); 74 | try 75 | { 76 | RT.print(this, sw); 77 | } 78 | catch(Exception e) 79 | { 80 | //checked exceptions stink! 81 | throw new RuntimeException(e); 82 | } 83 | return sw.toString(); 84 | } 85 | 86 | public int length(){ 87 | return 2; 88 | } 89 | 90 | public Object nth(int i){ 91 | if(i == 0) 92 | return key(); 93 | else if(i == 1) 94 | return val(); 95 | else 96 | throw new IndexOutOfBoundsException(); 97 | } 98 | 99 | private IPersistentVector asVector(){ 100 | return LazilyPersistentVector.createOwning(key(), val()); 101 | } 102 | 103 | public IPersistentVector assocN(int i, Object val){ 104 | return asVector().assocN(i, val); 105 | } 106 | 107 | public int count(){ 108 | return 2; 109 | } 110 | 111 | public ISeq seq(){ 112 | return asVector().seq(); 113 | } 114 | 115 | public IPersistentVector cons(Object o){ 116 | return asVector().cons(o); 117 | } 118 | 119 | public boolean containsKey(Object key){ 120 | return asVector().containsKey(key); 121 | } 122 | 123 | public IMapEntry entryAt(Object key){ 124 | return asVector().entryAt(key); 125 | } 126 | 127 | public Associative assoc(Object key, Object val){ 128 | return asVector().assoc(key, val); 129 | } 130 | 131 | public Object valAt(Object key){ 132 | return asVector().valAt(key); 133 | } 134 | 135 | public Object valAt(Object key, Object notFound){ 136 | return asVector().valAt(key, notFound); 137 | } 138 | 139 | public Object peek(){ 140 | return val(); 141 | } 142 | 143 | 144 | public ISeq rseq() throws Exception{ 145 | return asVector().rseq(); 146 | } 147 | */ 148 | 149 | } 150 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/APersistentSet.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Mar 3, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | import java.io.Serializable; 16 | import java.util.Collection; 17 | import java.util.Iterator; 18 | import java.util.Set; 19 | 20 | public abstract class APersistentSet extends AFn implements IPersistentSet, Collection, Set, Serializable { 21 | int _hash = -1; 22 | final IPersistentMap impl; 23 | 24 | protected APersistentSet(IPersistentMap impl){ 25 | this.impl = impl; 26 | } 27 | 28 | public String toString(){ 29 | return RT.printString(this); 30 | } 31 | 32 | public boolean contains(Object key){ 33 | return impl.containsKey(key); 34 | } 35 | 36 | public Object get(Object key){ 37 | return impl.valAt(key); 38 | } 39 | 40 | public int count(){ 41 | return impl.count(); 42 | } 43 | 44 | public ISeq seq(){ 45 | return RT.keys(impl); 46 | } 47 | 48 | public Object invoke(Object arg1) throws Exception{ 49 | return get(arg1); 50 | } 51 | 52 | public boolean equals(Object obj){ 53 | if(this == obj) return true; 54 | if(!(obj instanceof Set)) 55 | return false; 56 | Set m = (Set) obj; 57 | 58 | if(m.size() != count() || m.hashCode() != hashCode()) 59 | return false; 60 | 61 | for(Object aM : m) 62 | { 63 | if(!contains(aM)) 64 | return false; 65 | } 66 | // for(ISeq s = seq(); s != null; s = s.rest()) 67 | // { 68 | // if(!m.contains(s.first())) 69 | // return false; 70 | // } 71 | 72 | return true; 73 | } 74 | 75 | public boolean equiv(Object o){ 76 | return equals(o); 77 | } 78 | 79 | public int hashCode(){ 80 | if(_hash == -1) 81 | { 82 | //int hash = count(); 83 | int hash = 0; 84 | for(ISeq s = seq(); s != null; s = s.next()) 85 | { 86 | Object e = s.first(); 87 | // hash = Util.hashCombine(hash, Util.hash(e)); 88 | hash += Util.hash(e); 89 | } 90 | this._hash = hash; 91 | } 92 | return _hash; 93 | } 94 | 95 | public Object[] toArray(){ 96 | return RT.seqToArray(seq()); 97 | } 98 | 99 | public boolean add(Object o){ 100 | throw new UnsupportedOperationException(); 101 | } 102 | 103 | public boolean remove(Object o){ 104 | throw new UnsupportedOperationException(); 105 | } 106 | 107 | public boolean addAll(Collection c){ 108 | throw new UnsupportedOperationException(); 109 | } 110 | 111 | public void clear(){ 112 | throw new UnsupportedOperationException(); 113 | } 114 | 115 | public boolean retainAll(Collection c){ 116 | throw new UnsupportedOperationException(); 117 | } 118 | 119 | public boolean removeAll(Collection c){ 120 | throw new UnsupportedOperationException(); 121 | } 122 | 123 | public boolean containsAll(Collection c){ 124 | for(Object o : c) 125 | { 126 | if(!contains(o)) 127 | return false; 128 | } 129 | return true; 130 | } 131 | 132 | public Object[] toArray(Object[] a){ 133 | if(a.length >= count()) 134 | { 135 | ISeq s = seq(); 136 | for(int i = 0; s != null; ++i, s = s.next()) 137 | { 138 | a[i] = s.first(); 139 | } 140 | if(a.length > count()) 141 | a[count()] = null; 142 | return a; 143 | } 144 | else 145 | return toArray(); 146 | } 147 | 148 | public int size(){ 149 | return count(); 150 | } 151 | 152 | public boolean isEmpty(){ 153 | return count() == 0; 154 | } 155 | 156 | public Iterator iterator(){ 157 | return new SeqIterator(seq()); 158 | } 159 | 160 | } 161 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ARef.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Jan 1, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | import java.util.Map; 16 | 17 | public abstract class ARef extends AReference implements IRef{ 18 | protected volatile IFn validator = null; 19 | private volatile IPersistentMap watches = PersistentHashMap.EMPTY; 20 | 21 | public ARef(){ 22 | super(); 23 | } 24 | 25 | public ARef(IPersistentMap meta){ 26 | super(meta); 27 | } 28 | 29 | void validate(IFn vf, Object val){ 30 | try 31 | { 32 | if(vf != null && !RT.booleanCast(vf.invoke(val))) 33 | throw new IllegalStateException("Invalid reference state"); 34 | } 35 | catch(RuntimeException re) 36 | { 37 | throw re; 38 | } 39 | catch(Exception e) 40 | { 41 | throw new IllegalStateException("Invalid reference state", e); 42 | } 43 | } 44 | 45 | void validate(Object val){ 46 | validate(validator, val); 47 | } 48 | 49 | public void setValidator(IFn vf){ 50 | try 51 | { 52 | validate(vf, deref()); 53 | } 54 | catch(Exception e) 55 | { 56 | throw new RuntimeException(e); 57 | } 58 | validator = vf; 59 | } 60 | 61 | public IFn getValidator(){ 62 | return validator; 63 | } 64 | 65 | public IPersistentMap getWatches(){ 66 | return watches; 67 | } 68 | 69 | synchronized public IRef addWatch(Object key, IFn callback){ 70 | watches = watches.assoc(key, callback); 71 | return this; 72 | } 73 | 74 | synchronized public IRef removeWatch(Object key){ 75 | try 76 | { 77 | watches = watches.without(key); 78 | } 79 | catch(Exception e) 80 | { 81 | throw new RuntimeException(e); 82 | } 83 | 84 | return this; 85 | } 86 | 87 | public void notifyWatches(Object oldval, Object newval){ 88 | IPersistentMap ws = watches; 89 | if(ws.count() > 0) 90 | { 91 | for(ISeq s = ws.seq(); s != null; s = s.next()) 92 | { 93 | Map.Entry e = (Map.Entry) s.first(); 94 | IFn fn = (IFn) e.getValue(); 95 | try 96 | { 97 | if(fn != null) 98 | fn.invoke(e.getKey(), this, oldval, newval); 99 | } 100 | catch(Exception e1) 101 | { 102 | throw new RuntimeException(e1); 103 | } 104 | } 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/AReference.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Dec 31, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | public class AReference implements IReference { 16 | private IPersistentMap _meta; 17 | 18 | public AReference() { 19 | this(null); 20 | } 21 | 22 | public AReference(IPersistentMap meta) { 23 | _meta = meta; 24 | } 25 | 26 | synchronized public IPersistentMap meta() { 27 | return _meta; 28 | } 29 | 30 | synchronized public IPersistentMap alterMeta(IFn alter, ISeq args) throws Exception { 31 | _meta = (IPersistentMap) alter.applyTo(new Cons(_meta, args)); 32 | return _meta; 33 | } 34 | 35 | synchronized public IPersistentMap resetMeta(IPersistentMap m) { 36 | _meta = m; 37 | return m; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ATransientMap.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | package clojure.lang; 12 | 13 | import java.util.Map; 14 | 15 | import clojure.lang.PersistentHashMap.INode; 16 | 17 | abstract class ATransientMap extends AFn implements ITransientMap { 18 | abstract void ensureEditable(); 19 | abstract ITransientMap doAssoc(Object key, Object val); 20 | abstract ITransientMap doWithout(Object key); 21 | abstract Object doValAt(Object key, Object notFound); 22 | abstract int doCount(); 23 | abstract IPersistentMap doPersistent(); 24 | 25 | public ITransientMap conj(Object o) { 26 | ensureEditable(); 27 | if(o instanceof Map.Entry) 28 | { 29 | Map.Entry e = (Map.Entry) o; 30 | 31 | return assoc(e.getKey(), e.getValue()); 32 | } 33 | else if(o instanceof IPersistentVector) 34 | { 35 | IPersistentVector v = (IPersistentVector) o; 36 | if(v.count() != 2) 37 | throw new IllegalArgumentException("Vector arg to map conj must be a pair"); 38 | return assoc(v.nth(0), v.nth(1)); 39 | } 40 | 41 | ITransientMap ret = this; 42 | for(ISeq es = RT.seq(o); es != null; es = es.next()) 43 | { 44 | Map.Entry e = (Map.Entry) es.first(); 45 | ret = ret.assoc(e.getKey(), e.getValue()); 46 | } 47 | return ret; 48 | } 49 | 50 | public final Object invoke(Object arg1) throws Exception{ 51 | return valAt(arg1); 52 | } 53 | 54 | public final Object invoke(Object arg1, Object notFound) throws Exception{ 55 | return valAt(arg1, notFound); 56 | } 57 | 58 | public final Object valAt(Object key) { 59 | return valAt(key, null); 60 | } 61 | 62 | public final ITransientMap assoc(Object key, Object val) { 63 | ensureEditable(); 64 | return doAssoc(key, val); 65 | } 66 | 67 | public final ITransientMap without(Object key) { 68 | ensureEditable(); 69 | return doWithout(key); 70 | } 71 | 72 | public final IPersistentMap persistent() { 73 | ensureEditable(); 74 | return doPersistent(); 75 | } 76 | 77 | public final Object valAt(Object key, Object notFound) { 78 | ensureEditable(); 79 | return doValAt(key, notFound); 80 | } 81 | 82 | public final int count() { 83 | ensureEditable(); 84 | return doCount(); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ATransientSet.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Mar 3, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | public abstract class ATransientSet extends AFn implements ITransientSet{ 16 | ITransientMap impl; 17 | 18 | ATransientSet(ITransientMap impl) { 19 | this.impl = impl; 20 | } 21 | 22 | public int count() { 23 | return impl.count(); 24 | } 25 | 26 | public ITransientSet conj(Object val) { 27 | ITransientMap m = impl.assoc(val, val); 28 | if (m != impl) this.impl = m; 29 | return this; 30 | } 31 | 32 | public boolean contains(Object key) { 33 | return this != impl.valAt(key, this); 34 | } 35 | 36 | public ITransientSet disjoin(Object key) throws Exception { 37 | ITransientMap m = impl.without(key); 38 | if (m != impl) this.impl = m; 39 | return this; 40 | } 41 | 42 | public Object get(Object key) { 43 | return impl.valAt(key); 44 | } 45 | 46 | public Object invoke(Object key, Object notFound) throws Exception { 47 | return impl.valAt(key, notFound); 48 | } 49 | 50 | public Object invoke(Object key) throws Exception { 51 | return impl.valAt(key); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ArrayChunk.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich May 24, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | import java.io.Serializable; 16 | 17 | public final class ArrayChunk implements IChunk, Serializable { 18 | 19 | final Object[] array; 20 | final int off; 21 | final int end; 22 | 23 | public ArrayChunk(Object[] array){ 24 | this(array, 0, array.length); 25 | } 26 | 27 | public ArrayChunk(Object[] array, int off){ 28 | this(array, off, array.length); 29 | } 30 | 31 | public ArrayChunk(Object[] array, int off, int end){ 32 | this.array = array; 33 | this.off = off; 34 | this.end = end; 35 | } 36 | 37 | public Object nth(int i){ 38 | return array[off + i]; 39 | } 40 | 41 | public Object nth(int i, Object notFound){ 42 | if(i >= 0 && i < count()) 43 | return nth(i); 44 | return notFound; 45 | } 46 | 47 | public int count(){ 48 | return end - off; 49 | } 50 | 51 | public IChunk dropFirst(){ 52 | if(off==end) 53 | throw new IllegalStateException("dropFirst of empty chunk"); 54 | return new ArrayChunk(array, off + 1, end); 55 | } 56 | 57 | public Object reduce(IFn f, Object start) throws Exception{ 58 | Object ret = f.invoke(start, array[off]); 59 | for(int x = off + 1; x < end; x++) 60 | ret = f.invoke(ret, array[x]); 61 | return ret; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Associative.java: -------------------------------------------------------------------------------- 1 | package clojure.lang; 2 | 3 | /** 4 | * Copyright (c) Rich Hickey. All rights reserved. 5 | * The use and distribution terms for this software are covered by the 6 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 7 | * which can be found in the file epl-v10.html at the root of this distribution. 8 | * By using this software in any fashion, you are agreeing to be bound by 9 | * the terms of this license. 10 | * You must not remove this notice, or any other, from this software. 11 | */ 12 | public interface Associative extends IPersistentCollection, ILookup{ 13 | boolean containsKey(Object key); 14 | 15 | IMapEntry entryAt(Object key); 16 | 17 | Associative assoc(Object key, Object val); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Atom.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Jan 1, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | import java.util.concurrent.atomic.AtomicReference; 16 | 17 | final public class Atom extends ARef{ 18 | final AtomicReference state; 19 | 20 | public Atom(Object state){ 21 | this.state = new AtomicReference(state); 22 | } 23 | 24 | public Atom(Object state, IPersistentMap meta){ 25 | super(meta); 26 | this.state = new AtomicReference(state); 27 | } 28 | 29 | public Object deref(){ 30 | return state.get(); 31 | } 32 | 33 | public Object swap(IFn f) throws Exception{ 34 | for(; ;) 35 | { 36 | Object v = deref(); 37 | Object newv = f.invoke(v); 38 | validate(newv); 39 | if(state.compareAndSet(v, newv)) 40 | { 41 | notifyWatches(v, newv); 42 | return newv; 43 | } 44 | } 45 | } 46 | 47 | public Object swap(IFn f, Object arg) throws Exception{ 48 | for(; ;) 49 | { 50 | Object v = deref(); 51 | Object newv = f.invoke(v, arg); 52 | validate(newv); 53 | if(state.compareAndSet(v, newv)) 54 | { 55 | notifyWatches(v, newv); 56 | return newv; 57 | } 58 | } 59 | } 60 | 61 | public Object swap(IFn f, Object arg1, Object arg2) throws Exception{ 62 | for(; ;) 63 | { 64 | Object v = deref(); 65 | Object newv = f.invoke(v, arg1, arg2); 66 | validate(newv); 67 | if(state.compareAndSet(v, newv)) 68 | { 69 | notifyWatches(v, newv); 70 | return newv; 71 | } 72 | } 73 | } 74 | 75 | public Object swap(IFn f, Object x, Object y, ISeq args) throws Exception{ 76 | for(; ;) 77 | { 78 | Object v = deref(); 79 | Object newv = f.applyTo(RT.listStar(v, x, y, args)); 80 | validate(newv); 81 | if(state.compareAndSet(v, newv)) 82 | { 83 | notifyWatches(v, newv); 84 | return newv; 85 | } 86 | } 87 | } 88 | 89 | public boolean compareAndSet(Object oldv, Object newv){ 90 | validate(newv); 91 | boolean ret = state.compareAndSet(oldv, newv); 92 | if(ret) 93 | notifyWatches(oldv, newv); 94 | return ret; 95 | } 96 | 97 | public Object reset(Object newval){ 98 | Object oldval = state.get(); 99 | validate(newval); 100 | state.set(newval); 101 | notifyWatches(oldval, newval); 102 | return newval; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Binding.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | package clojure.lang; 12 | 13 | public class Binding{ 14 | public T val; 15 | public final Binding rest; 16 | 17 | public Binding(T val){ 18 | this.val = val; 19 | this.rest = null; 20 | } 21 | 22 | public Binding(T val, Binding rest){ 23 | this.val = val; 24 | this.rest = rest; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Box.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Mar 27, 2006 8:40:19 PM */ 12 | 13 | package clojure.lang; 14 | 15 | public class Box{ 16 | 17 | public Object val; 18 | 19 | public Box(Object val){ 20 | this.val = val; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ChunkBuffer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich May 26, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | final public class ChunkBuffer implements Counted{ 16 | Object[] buffer; 17 | int end; 18 | 19 | public ChunkBuffer(int capacity){ 20 | buffer = new Object[capacity]; 21 | end = 0; 22 | } 23 | 24 | public void add(Object o){ 25 | buffer[end++] = o; 26 | } 27 | 28 | public IChunk chunk(){ 29 | ArrayChunk ret = new ArrayChunk(buffer, 0, end); 30 | buffer = null; 31 | return ret; 32 | } 33 | 34 | public int count(){ 35 | return end; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ChunkedCons.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich May 25, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | final public class ChunkedCons extends ASeq implements IChunkedSeq{ 16 | 17 | final IChunk chunk; 18 | final ISeq _more; 19 | 20 | ChunkedCons(IPersistentMap meta, IChunk chunk, ISeq more){ 21 | super(meta); 22 | this.chunk = chunk; 23 | this._more = more; 24 | } 25 | 26 | public ChunkedCons(IChunk chunk, ISeq more){ 27 | this(null,chunk, more); 28 | } 29 | 30 | public Obj withMeta(IPersistentMap meta){ 31 | if(meta != _meta) 32 | return new ChunkedCons(meta, chunk, _more); 33 | return this; 34 | } 35 | 36 | public Object first(){ 37 | return chunk.nth(0); 38 | } 39 | 40 | public ISeq next(){ 41 | if(chunk.count() > 1) 42 | return new ChunkedCons(chunk.dropFirst(), _more); 43 | return chunkedNext(); 44 | } 45 | 46 | public ISeq more(){ 47 | if(chunk.count() > 1) 48 | return new ChunkedCons(chunk.dropFirst(), _more); 49 | if(_more == null) 50 | return PersistentList.EMPTY; 51 | return _more; 52 | } 53 | 54 | public IChunk chunkedFirst(){ 55 | return chunk; 56 | } 57 | 58 | public ISeq chunkedNext(){ 59 | return chunkedMore().seq(); 60 | } 61 | 62 | public ISeq chunkedMore(){ 63 | if(_more == null) 64 | return PersistentList.EMPTY; 65 | return _more; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Compile.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | 12 | package clojure.lang; 13 | 14 | import java.io.OutputStreamWriter; 15 | import java.io.PrintWriter; 16 | import java.io.IOException; 17 | 18 | // Compiles libs and generates class files stored within the directory 19 | // named by the Java System property "clojure.compile.path". Arguments are 20 | // strings naming the libs to be compiled. The libs and compile-path must 21 | // all be within CLASSPATH. 22 | 23 | public class Compile{ 24 | 25 | private static final String PATH_PROP = "clojure.compile.path"; 26 | private static final String REFLECTION_WARNING_PROP = "clojure.compile.warn-on-reflection"; 27 | private static final Var compile_path = RT.var("clojure.core", "*compile-path*"); 28 | private static final Var compile = RT.var("clojure.core", "compile"); 29 | private static final Var warn_on_reflection = RT.var("clojure.core", "*warn-on-reflection*"); 30 | 31 | public static void main(String[] args) throws Exception{ 32 | 33 | OutputStreamWriter out = (OutputStreamWriter) RT.OUT.deref(); 34 | PrintWriter err = RT.errPrintWriter(); 35 | String path = System.getProperty(PATH_PROP); 36 | int count = args.length; 37 | 38 | if(path == null) 39 | { 40 | err.println("ERROR: Must set system property " + PATH_PROP + 41 | "\nto the location for compiled .class files." + 42 | "\nThis directory must also be on your CLASSPATH."); 43 | System.exit(1); 44 | } 45 | 46 | boolean warnOnReflection = System.getProperty(REFLECTION_WARNING_PROP, "false").equals("true"); 47 | 48 | try 49 | { 50 | Var.pushThreadBindings(RT.map(compile_path, path, warn_on_reflection, warnOnReflection)); 51 | 52 | for(String lib : args) 53 | { 54 | out.write("Compiling " + lib + " to " + path + "\n"); 55 | out.flush(); 56 | compile.invoke(Symbol.intern(lib)); 57 | } 58 | } 59 | finally 60 | { 61 | Var.popThreadBindings(); 62 | try 63 | { 64 | out.flush(); 65 | out.close(); 66 | } 67 | catch(IOException e) 68 | { 69 | e.printStackTrace(err); 70 | } 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Cons.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Mar 25, 2006 11:01:29 AM */ 12 | 13 | package clojure.lang; 14 | 15 | import java.io.Serializable; 16 | 17 | final public class Cons extends ASeq implements Serializable { 18 | 19 | private final Object _first; 20 | private final ISeq _more; 21 | 22 | public Cons(Object first, ISeq _more){ 23 | this._first = first; 24 | this._more = _more; 25 | } 26 | 27 | 28 | public Cons(IPersistentMap meta, Object _first, ISeq _more){ 29 | super(meta); 30 | this._first = _first; 31 | this._more = _more; 32 | } 33 | 34 | public Object first(){ 35 | return _first; 36 | } 37 | 38 | public ISeq next(){ 39 | return more().seq(); 40 | } 41 | 42 | public ISeq more(){ 43 | if(_more == null) 44 | return PersistentList.EMPTY; 45 | return _more; 46 | } 47 | 48 | public int count(){ 49 | return 1 + RT.count(_more); 50 | } 51 | 52 | public Cons withMeta(IPersistentMap meta){ 53 | return new Cons(meta, _first, _more); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Counted.java: -------------------------------------------------------------------------------- 1 | package clojure.lang; 2 | 3 | /** 4 | * Copyright (c) Rich Hickey. All rights reserved. 5 | * The use and distribution terms for this software are covered by the 6 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 7 | * which can be found in the file epl-v10.html at the root of this distribution. 8 | * By using this software in any fashion, you are agreeing to be bound by 9 | * the terms of this license. 10 | * You must not remove this notice, or any other, from this software. 11 | */ 12 | 13 | /* A class that implements Counted promises that it is a collection 14 | * that implement a constant-time count() */ 15 | 16 | public interface Counted { 17 | int count(); 18 | } 19 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Delay.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Jun 28, 2007 */ 12 | 13 | package clojure.lang; 14 | 15 | public class Delay implements IDeref{ 16 | Object val; 17 | IFn fn; 18 | 19 | public Delay(IFn fn){ 20 | this.fn = fn; 21 | this.val = null; 22 | } 23 | 24 | static public Object force(Object x) throws Exception{ 25 | return (x instanceof Delay) ? 26 | ((Delay) x).deref() 27 | : x; 28 | } 29 | 30 | synchronized public Object deref() throws Exception{ 31 | if(fn != null) 32 | { 33 | val = fn.invoke(); 34 | fn = null; 35 | } 36 | return val; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/DynamicClassLoader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Aug 21, 2007 */ 12 | 13 | package clojure.lang; 14 | 15 | import java.util.HashMap; 16 | import java.util.Map; 17 | import java.util.Arrays; 18 | import java.util.concurrent.ConcurrentHashMap; 19 | import java.net.URLClassLoader; 20 | import java.net.URL; 21 | import java.lang.ref.WeakReference; 22 | 23 | public class DynamicClassLoader extends URLClassLoader{ 24 | HashMap constantVals = new HashMap(); 25 | static ConcurrentHashMap,Object> >classCache = 26 | new ConcurrentHashMap,Object> >(); 27 | 28 | static final URL[] EMPTY_URLS = new URL[]{}; 29 | 30 | public DynamicClassLoader(){ 31 | //pseudo test in lieu of hasContextClassLoader() 32 | super(EMPTY_URLS,(Thread.currentThread().getContextClassLoader() == null || 33 | Thread.currentThread().getContextClassLoader() == ClassLoader.getSystemClassLoader())? 34 | Compiler.class.getClassLoader():Thread.currentThread().getContextClassLoader()); 35 | } 36 | 37 | public DynamicClassLoader(ClassLoader parent){ 38 | super(EMPTY_URLS,parent); 39 | } 40 | 41 | public Class defineClass(String name, byte[] bytes, Object srcForm){ 42 | // Map.Entry,Object> ce = classCache.get(name); 43 | // if(ce != null) 44 | // { 45 | // WeakReference cr = ce.getKey(); 46 | // Class c = cr.get(); 47 | // if((c != null) && srcForm.equals(ce.getValue())) 48 | // return c; 49 | // } 50 | Class c = defineClass(name, bytes, 0, bytes.length); 51 | classCache.put(name, new MapEntry(new WeakReference(c), null)); 52 | return c; 53 | } 54 | 55 | protected Class findClass(String name) throws ClassNotFoundException{ 56 | Map.Entry,Object> ce = classCache.get(name); 57 | if(ce != null) 58 | { 59 | WeakReference cr = ce.getKey(); 60 | Class c = cr.get(); 61 | if(c != null) 62 | return c; 63 | classCache.remove(name); 64 | } 65 | return super.findClass(name); 66 | } 67 | 68 | public void registerConstants(int id, Object[] val){ 69 | constantVals.put(id, val); 70 | } 71 | 72 | public Object[] getConstants(int id){ 73 | return constantVals.get(id); 74 | } 75 | 76 | public void addURL(URL url){ 77 | super.addURL(url); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/EnumerationSeq.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Mar 3, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | import java.io.IOException; 16 | import java.io.NotSerializableException; 17 | import java.util.Enumeration; 18 | 19 | public class EnumerationSeq extends ASeq{ 20 | final Enumeration iter; 21 | final State state; 22 | 23 | static class State{ 24 | volatile Object val; 25 | volatile Object _rest; 26 | } 27 | 28 | public static EnumerationSeq create(Enumeration iter){ 29 | if(iter.hasMoreElements()) 30 | return new EnumerationSeq(iter); 31 | return null; 32 | } 33 | 34 | EnumerationSeq(Enumeration iter){ 35 | this.iter = iter; 36 | state = new State(); 37 | this.state.val = state; 38 | this.state._rest = state; 39 | } 40 | 41 | EnumerationSeq(IPersistentMap meta, Enumeration iter, State state){ 42 | super(meta); 43 | this.iter = iter; 44 | this.state = state; 45 | } 46 | 47 | public Object first(){ 48 | if(state.val == state) 49 | synchronized(state) 50 | { 51 | if(state.val == state) 52 | state.val = iter.nextElement(); 53 | } 54 | return state.val; 55 | } 56 | 57 | public ISeq next(){ 58 | if(state._rest == state) 59 | synchronized(state) 60 | { 61 | if(state._rest == state) 62 | { 63 | first(); 64 | state._rest = create(iter); 65 | } 66 | } 67 | return (ISeq) state._rest; 68 | } 69 | 70 | public EnumerationSeq withMeta(IPersistentMap meta){ 71 | return new EnumerationSeq(meta, iter, state); 72 | } 73 | 74 | private void writeObject (java.io.ObjectOutputStream out) throws IOException { 75 | throw new NotSerializableException(getClass().getName()); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Fn.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Nov 25, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface Fn{ 16 | } 17 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IChunk.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Jun 18, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface IChunk extends Indexed{ 16 | 17 | IChunk dropFirst(); 18 | 19 | Object reduce(IFn f, Object start) throws Exception; 20 | } 21 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IChunkedSeq.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich May 24, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface IChunkedSeq extends ISeq{ 16 | 17 | IChunk chunkedFirst() throws Exception; 18 | 19 | ISeq chunkedNext() throws Exception; 20 | 21 | ISeq chunkedMore() throws Exception; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IDeref.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Feb 9, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface IDeref{ 16 | Object deref() throws Exception; 17 | } 18 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IEditableCollection.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Jul 17, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface IEditableCollection{ 16 | ITransientCollection asTransient(); 17 | } 18 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IKeywordLookup.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Oct 31, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface IKeywordLookup{ 16 | ILookupThunk getLookupThunk(Keyword k); 17 | } 18 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ILookup.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Aug 2, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface ILookup{ 16 | Object valAt(Object key); 17 | 18 | Object valAt(Object key, Object notFound); 19 | } 20 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ILookupHost.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Nov 2, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface ILookupHost{ 16 | 17 | void swapThunk(int n, ILookupThunk thunk); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ILookupSite.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Nov 2, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface ILookupSite{ 16 | 17 | Object fault(Object target, ILookupHost host); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ILookupThunk.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Nov 2, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface ILookupThunk{ 16 | 17 | Object get(Object target); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IMapEntry.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | */ 10 | 11 | package clojure.lang; 12 | 13 | import java.util.Map; 14 | 15 | public interface IMapEntry extends Map.Entry{ 16 | Object key(); 17 | 18 | Object val(); 19 | } 20 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IMeta.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Dec 31, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface IMeta { 16 | IPersistentMap meta(); 17 | } 18 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IObj.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | package clojure.lang; 12 | 13 | 14 | public interface IObj extends IMeta { 15 | 16 | public IObj withMeta(IPersistentMap meta); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IPersistentCollection.java: -------------------------------------------------------------------------------- 1 | package clojure.lang; 2 | 3 | /** 4 | * Copyright (c) Rich Hickey. All rights reserved. 5 | * The use and distribution terms for this software are covered by the 6 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 7 | * which can be found in the file epl-v10.html at the root of this distribution. 8 | * By using this software in any fashion, you are agreeing to be bound by 9 | * the terms of this license. 10 | * You must not remove this notice, or any other, from this software. 11 | */ 12 | 13 | 14 | public interface IPersistentCollection extends Seqable { 15 | 16 | int count(); 17 | 18 | IPersistentCollection cons(Object o); 19 | 20 | IPersistentCollection empty(); 21 | 22 | boolean equiv(Object o); 23 | } 24 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IPersistentList.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | */ 10 | 11 | package clojure.lang; 12 | 13 | 14 | public interface IPersistentList extends Sequential, IPersistentStack{ 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IPersistentMap.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | */ 10 | 11 | package clojure.lang; 12 | 13 | 14 | public interface IPersistentMap extends Iterable, Associative, Counted{ 15 | 16 | 17 | IPersistentMap assoc(Object key, Object val); 18 | 19 | IPersistentMap assocEx(Object key, Object val) throws Exception; 20 | 21 | IPersistentMap without(Object key) throws Exception; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IPersistentSet.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Mar 3, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface IPersistentSet extends IPersistentCollection, Counted{ 16 | public IPersistentSet disjoin(Object key) throws Exception; 17 | public boolean contains(Object key); 18 | public Object get(Object key); 19 | } 20 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IPersistentStack.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Sep 19, 2007 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface IPersistentStack extends IPersistentCollection{ 16 | Object peek(); 17 | 18 | IPersistentStack pop(); 19 | } 20 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IPersistentVector.java: -------------------------------------------------------------------------------- 1 | package clojure.lang; 2 | 3 | /** 4 | * Copyright (c) Rich Hickey. All rights reserved. 5 | * The use and distribution terms for this software are covered by the 6 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 7 | * which can be found in the file epl-v10.html at the root of this distribution. 8 | * By using this software in any fashion, you are agreeing to be bound by 9 | * the terms of this license. 10 | * You must not remove this notice, or any other, from this software. 11 | */ 12 | 13 | public interface IPersistentVector extends Associative, Sequential, IPersistentStack, Reversible, Indexed{ 14 | int length(); 15 | 16 | IPersistentVector assocN(int i, Object val); 17 | 18 | IPersistentVector cons(Object o); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IProxy.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Feb 27, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface IProxy{ 16 | 17 | public void __initClojureFnMappings(IPersistentMap m); 18 | public void __updateClojureFnMappings(IPersistentMap m); 19 | public IPersistentMap __getClojureFnMappings(); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IReduce.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Jun 11, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface IReduce{ 16 | Object reduce(IFn f) throws Exception; 17 | 18 | Object reduce(IFn f, Object start) throws Exception; 19 | } 20 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IRef.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Nov 18, 2007 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface IRef extends IDeref{ 16 | 17 | void setValidator(IFn vf); 18 | 19 | IFn getValidator(); 20 | 21 | IPersistentMap getWatches(); 22 | 23 | IRef addWatch(Object key, IFn callback); 24 | 25 | IRef removeWatch(Object key); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IReference.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Dec 31, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface IReference extends IMeta { 16 | IPersistentMap alterMeta(IFn alter, ISeq args) throws Exception; 17 | IPersistentMap resetMeta(IPersistentMap m); 18 | } 19 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ISeq.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | */ 10 | 11 | package clojure.lang; 12 | 13 | /** 14 | * A persistent, functional, sequence interface 15 | *

16 | * ISeqs are immutable values, i.e. neither first(), nor rest() changes 17 | * or invalidates the ISeq 18 | */ 19 | public interface ISeq extends IPersistentCollection, Sequential{ 20 | 21 | Object first(); 22 | 23 | ISeq next(); 24 | 25 | ISeq more(); 26 | 27 | ISeq cons(Object o); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ITransientAssociative.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Jul 17, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface ITransientAssociative extends ITransientCollection, ILookup{ 16 | 17 | ITransientAssociative assoc(Object key, Object val); 18 | } 19 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ITransientCollection.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Jul 17, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface ITransientCollection{ 16 | 17 | ITransientCollection conj(Object val); 18 | 19 | IPersistentCollection persistent(); 20 | } 21 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ITransientMap.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Jul 17, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface ITransientMap extends ITransientAssociative, Counted{ 16 | 17 | ITransientMap assoc(Object key, Object val); 18 | 19 | ITransientMap without(Object key); 20 | 21 | IPersistentMap persistent(); 22 | } 23 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ITransientSet.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Mar 3, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface ITransientSet extends ITransientCollection, Counted{ 16 | public ITransientSet disjoin(Object key) throws Exception; 17 | public boolean contains(Object key); 18 | public Object get(Object key); 19 | } 20 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ITransientVector.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Jul 17, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface ITransientVector extends ITransientAssociative, Indexed{ 16 | 17 | ITransientVector assocN(int i, Object val); 18 | 19 | ITransientVector pop(); 20 | } 21 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Indexed.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich May 24, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface Indexed extends Counted{ 16 | Object nth(int i); 17 | 18 | Object nth(int i, Object notFound); 19 | } 20 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IndexedSeq.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | */ 10 | 11 | package clojure.lang; 12 | 13 | public interface IndexedSeq extends ISeq, Counted{ 14 | 15 | public int index(); 16 | } 17 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IteratorSeq.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | package clojure.lang; 12 | 13 | import java.io.IOException; 14 | import java.io.NotSerializableException; 15 | import java.util.Iterator; 16 | 17 | public class IteratorSeq extends ASeq{ 18 | final Iterator iter; 19 | final State state; 20 | 21 | static class State{ 22 | volatile Object val; 23 | volatile Object _rest; 24 | } 25 | 26 | public static IteratorSeq create(Iterator iter){ 27 | if(iter.hasNext()) 28 | return new IteratorSeq(iter); 29 | return null; 30 | } 31 | 32 | IteratorSeq(Iterator iter){ 33 | this.iter = iter; 34 | state = new State(); 35 | this.state.val = state; 36 | this.state._rest = state; 37 | } 38 | 39 | IteratorSeq(IPersistentMap meta, Iterator iter, State state){ 40 | super(meta); 41 | this.iter = iter; 42 | this.state = state; 43 | } 44 | 45 | public Object first(){ 46 | if(state.val == state) 47 | synchronized(state) 48 | { 49 | if(state.val == state) 50 | state.val = iter.next(); 51 | } 52 | return state.val; 53 | } 54 | 55 | public ISeq next(){ 56 | if(state._rest == state) 57 | synchronized(state) 58 | { 59 | if(state._rest == state) 60 | { 61 | first(); 62 | state._rest = create(iter); 63 | } 64 | } 65 | return (ISeq) state._rest; 66 | } 67 | 68 | public IteratorSeq withMeta(IPersistentMap meta){ 69 | return new IteratorSeq(meta, iter, state); 70 | } 71 | 72 | private void writeObject (java.io.ObjectOutputStream out) throws IOException { 73 | throw new NotSerializableException(getClass().getName()); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/KeywordLookupSite.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Nov 2, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public final class KeywordLookupSite implements ILookupSite, ILookupThunk{ 16 | 17 | final int n; 18 | final Keyword k; 19 | 20 | public KeywordLookupSite(int n, Keyword k){ 21 | this.n = n; 22 | this.k = k; 23 | } 24 | 25 | public Object fault(Object target, ILookupHost host){ 26 | if(target instanceof IKeywordLookup) 27 | { 28 | return install(target, host); 29 | } 30 | else if(target instanceof ILookup) 31 | { 32 | host.swapThunk(n,ilookupThunk(target.getClass())); 33 | return ((ILookup) target).valAt(k); 34 | } 35 | host.swapThunk(n,this); 36 | return RT.get(target, k); 37 | } 38 | 39 | public Object get(Object target){ 40 | if(target instanceof IKeywordLookup || target instanceof ILookup) 41 | return this; 42 | return RT.get(target,k); 43 | } 44 | 45 | private ILookupThunk ilookupThunk(final Class c){ 46 | return new ILookupThunk(){ 47 | public Object get(Object target){ 48 | if(target != null && target.getClass() == c) 49 | return ((ILookup) target).valAt(k); 50 | return this; 51 | } 52 | }; 53 | } 54 | 55 | private Object install(Object target, ILookupHost host){ 56 | ILookupThunk t = ((IKeywordLookup)target).getLookupThunk(k); 57 | if(t != null) 58 | { 59 | host.swapThunk(n,t); 60 | return t.get(target); 61 | } 62 | host.swapThunk(n,ilookupThunk(target.getClass())); 63 | return ((ILookup) target).valAt(k); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/LazilyPersistentVector.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich May 14, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | import java.util.Collection; 16 | 17 | public class LazilyPersistentVector{ 18 | 19 | 20 | static public IPersistentVector createOwning(Object... items){ 21 | if(items.length == 0) 22 | return PersistentVector.EMPTY; 23 | else if(items.length <= 32) 24 | return new PersistentVector(items.length, 5, PersistentVector.EMPTY_NODE,items); 25 | return PersistentVector.create(items); 26 | } 27 | 28 | static public IPersistentVector create(Collection coll){ 29 | if(!(coll instanceof ISeq) && coll.size() <= 32) 30 | return createOwning(coll.toArray()); 31 | return PersistentVector.create(RT.seq(coll)); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/LineNumberingPushbackReader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | */ 10 | 11 | package clojure.lang; 12 | 13 | import java.io.PushbackReader; 14 | import java.io.Reader; 15 | import java.io.LineNumberReader; 16 | import java.io.IOException; 17 | 18 | 19 | public class LineNumberingPushbackReader extends PushbackReader{ 20 | 21 | // This class is a PushbackReader that wraps a LineNumberReader. The code 22 | // here to handle line terminators only mentions '\n' because 23 | // LineNumberReader collapses all occurrences of CR, LF, and CRLF into a 24 | // single '\n'. 25 | 26 | private static final int newline = (int) '\n'; 27 | 28 | private boolean _atLineStart = true; 29 | private boolean _prev; 30 | 31 | public LineNumberingPushbackReader(Reader r){ 32 | super(new LineNumberReader(r)); 33 | } 34 | 35 | public int getLineNumber(){ 36 | return ((LineNumberReader) in).getLineNumber() + 1; 37 | } 38 | 39 | public int read() throws IOException{ 40 | int c = super.read(); 41 | _prev = _atLineStart; 42 | _atLineStart = (c == newline) || (c == -1); 43 | return c; 44 | } 45 | 46 | public void unread(int c) throws IOException{ 47 | super.unread(c); 48 | _atLineStart = _prev; 49 | } 50 | 51 | public String readLine() throws IOException{ 52 | int c = read(); 53 | String line; 54 | switch (c) { 55 | case -1: 56 | line = null; 57 | break; 58 | case newline: 59 | line = ""; 60 | break; 61 | default: 62 | String first = String.valueOf((char) c); 63 | String rest = ((LineNumberReader)in).readLine(); 64 | line = (rest == null) ? first : first + rest; 65 | _prev = false; 66 | _atLineStart = true; 67 | break; 68 | } 69 | return line; 70 | } 71 | 72 | public boolean atLineStart(){ 73 | return _atLineStart; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/MapEntry.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | package clojure.lang; 12 | 13 | import java.util.Iterator; 14 | 15 | public class MapEntry extends AMapEntry{ 16 | final Object _key; 17 | final Object _val; 18 | 19 | public MapEntry(Object key, Object val){ 20 | this._key = key; 21 | this._val = val; 22 | } 23 | 24 | public Object key(){ 25 | return _key; 26 | } 27 | 28 | public Object val(){ 29 | return _val; 30 | } 31 | 32 | public Object getKey(){ 33 | return key(); 34 | } 35 | 36 | public Object getValue(){ 37 | return val(); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/MethodImplCache.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Nov 8, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public final class MethodImplCache{ 16 | 17 | static public class Entry{ 18 | final public Class c; 19 | final public IFn fn; 20 | 21 | public Entry(Class c, IFn fn){ 22 | this.c = c; 23 | this.fn = fn; 24 | } 25 | } 26 | 27 | public final IPersistentMap protocol; 28 | public final Keyword methodk; 29 | public final int shift; 30 | public final int mask; 31 | public final Object[] table; //[class, entry. class, entry ...] 32 | 33 | volatile Entry mre = null; 34 | 35 | public MethodImplCache(IPersistentMap protocol, Keyword methodk){ 36 | this(protocol, methodk, 0, 0, RT.EMPTY_ARRAY); 37 | } 38 | 39 | public MethodImplCache(IPersistentMap protocol, Keyword methodk, int shift, int mask, Object[] table){ 40 | this.protocol = protocol; 41 | this.methodk = methodk; 42 | this.shift = shift; 43 | this.mask = mask; 44 | this.table = table; 45 | } 46 | 47 | public IFn fnFor(Class c){ 48 | Entry last = mre; 49 | if(last != null && last.c == c) 50 | return last.fn; 51 | return findFnFor(c); 52 | } 53 | 54 | IFn findFnFor(Class c){ 55 | int idx = ((Util.hash(c) >> shift) & mask) << 1; 56 | if(idx < table.length && table[idx] == c) 57 | { 58 | Entry e = ((Entry) table[idx + 1]); 59 | mre = e; 60 | return e != null ? e.fn : null; 61 | } 62 | return null; 63 | } 64 | 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Named.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Sep 20, 2007 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface Named{ 16 | String getNamespace(); 17 | 18 | String getName(); 19 | } 20 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Obj.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Mar 25, 2006 3:44:58 PM */ 12 | 13 | package clojure.lang; 14 | 15 | import java.io.Serializable; 16 | 17 | public abstract class Obj implements IObj, Serializable { 18 | 19 | final IPersistentMap _meta; 20 | 21 | public Obj(IPersistentMap meta){ 22 | this._meta = meta; 23 | } 24 | 25 | public Obj(){ 26 | _meta = null; 27 | } 28 | 29 | final public IPersistentMap meta(){ 30 | return _meta; 31 | } 32 | 33 | abstract public Obj withMeta(IPersistentMap meta); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/PersistentHashSet.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Mar 3, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | import java.util.List; 16 | 17 | public class PersistentHashSet extends APersistentSet implements IObj, IEditableCollection { 18 | 19 | static public final PersistentHashSet EMPTY = new PersistentHashSet(null, PersistentHashMap.EMPTY); 20 | 21 | final IPersistentMap _meta; 22 | 23 | public static PersistentHashSet create(Object... init){ 24 | PersistentHashSet ret = EMPTY; 25 | for(int i = 0; i < init.length; i++) 26 | { 27 | ret = (PersistentHashSet) ret.cons(init[i]); 28 | } 29 | return ret; 30 | } 31 | 32 | public static PersistentHashSet create(List init){ 33 | PersistentHashSet ret = EMPTY; 34 | for(Object key : init) 35 | { 36 | ret = (PersistentHashSet) ret.cons(key); 37 | } 38 | return ret; 39 | } 40 | 41 | static public PersistentHashSet create(ISeq items){ 42 | PersistentHashSet ret = EMPTY; 43 | for(; items != null; items = items.next()) 44 | { 45 | ret = (PersistentHashSet) ret.cons(items.first()); 46 | } 47 | return ret; 48 | } 49 | 50 | public static PersistentHashSet createWithCheck(Object... init){ 51 | PersistentHashSet ret = EMPTY; 52 | for(int i = 0; i < init.length; i++) 53 | { 54 | ret = (PersistentHashSet) ret.cons(init[i]); 55 | if(ret.count() != i + 1) 56 | throw new IllegalArgumentException("Duplicate key: " + init[i]); 57 | } 58 | return ret; 59 | } 60 | 61 | public static PersistentHashSet createWithCheck(List init){ 62 | PersistentHashSet ret = EMPTY; 63 | int i=0; 64 | for(Object key : init) 65 | { 66 | ret = (PersistentHashSet) ret.cons(key); 67 | if(ret.count() != i + 1) 68 | throw new IllegalArgumentException("Duplicate key: " + key); 69 | ++i; 70 | } 71 | return ret; 72 | } 73 | 74 | static public PersistentHashSet createWithCheck(ISeq items){ 75 | PersistentHashSet ret = EMPTY; 76 | for(int i=0; items != null; items = items.next(), ++i) 77 | { 78 | ret = (PersistentHashSet) ret.cons(items.first()); 79 | if(ret.count() != i + 1) 80 | throw new IllegalArgumentException("Duplicate key: " + items.first()); 81 | } 82 | return ret; 83 | } 84 | 85 | PersistentHashSet(IPersistentMap meta, IPersistentMap impl){ 86 | super(impl); 87 | this._meta = meta; 88 | } 89 | 90 | public IPersistentSet disjoin(Object key) throws Exception{ 91 | if(contains(key)) 92 | return new PersistentHashSet(meta(),impl.without(key)); 93 | return this; 94 | } 95 | 96 | public IPersistentSet cons(Object o){ 97 | if(contains(o)) 98 | return this; 99 | return new PersistentHashSet(meta(),impl.assoc(o,o)); 100 | } 101 | 102 | public IPersistentCollection empty(){ 103 | return EMPTY.withMeta(meta()); 104 | } 105 | 106 | public PersistentHashSet withMeta(IPersistentMap meta){ 107 | return new PersistentHashSet(meta, impl); 108 | } 109 | 110 | public ITransientCollection asTransient() { 111 | return new TransientHashSet(((PersistentHashMap) impl).asTransient()); 112 | } 113 | 114 | public IPersistentMap meta(){ 115 | return _meta; 116 | } 117 | 118 | static final class TransientHashSet extends ATransientSet { 119 | TransientHashSet(ITransientMap impl) { 120 | super(impl); 121 | } 122 | 123 | public IPersistentCollection persistent() { 124 | return new PersistentHashSet(null, impl.persistent()); 125 | } 126 | } 127 | 128 | } 129 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/PersistentTreeSet.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Mar 3, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | import java.util.Comparator; 16 | 17 | public class PersistentTreeSet extends APersistentSet implements IObj, Reversible, Sorted{ 18 | static public final PersistentTreeSet EMPTY = new PersistentTreeSet(null, PersistentTreeMap.EMPTY); 19 | final IPersistentMap _meta; 20 | 21 | 22 | static public PersistentTreeSet create(ISeq items){ 23 | PersistentTreeSet ret = EMPTY; 24 | for(; items != null; items = items.next()) 25 | { 26 | ret = (PersistentTreeSet) ret.cons(items.first()); 27 | } 28 | return ret; 29 | } 30 | 31 | static public PersistentTreeSet create(Comparator comp, ISeq items){ 32 | PersistentTreeSet ret = new PersistentTreeSet(null, new PersistentTreeMap(null, comp)); 33 | for(; items != null; items = items.next()) 34 | { 35 | ret = (PersistentTreeSet) ret.cons(items.first()); 36 | } 37 | return ret; 38 | } 39 | 40 | PersistentTreeSet(IPersistentMap meta, IPersistentMap impl){ 41 | super(impl); 42 | this._meta = meta; 43 | } 44 | 45 | public IPersistentSet disjoin(Object key) throws Exception{ 46 | if(contains(key)) 47 | return new PersistentTreeSet(meta(),impl.without(key)); 48 | return this; 49 | } 50 | 51 | public IPersistentSet cons(Object o){ 52 | if(contains(o)) 53 | return this; 54 | return new PersistentTreeSet(meta(),impl.assoc(o,o)); 55 | } 56 | 57 | public IPersistentCollection empty(){ 58 | return new PersistentTreeSet(meta(),(PersistentTreeMap)impl.empty()); 59 | } 60 | 61 | public ISeq rseq() throws Exception{ 62 | return APersistentMap.KeySeq.create(((Reversible) impl).rseq()); 63 | } 64 | 65 | public PersistentTreeSet withMeta(IPersistentMap meta){ 66 | return new PersistentTreeSet(meta, impl); 67 | } 68 | 69 | public Comparator comparator(){ 70 | return ((Sorted)impl).comparator(); 71 | } 72 | 73 | public Object entryKey(Object entry){ 74 | return entry; 75 | } 76 | 77 | public ISeq seq(boolean ascending){ 78 | PersistentTreeMap m = (PersistentTreeMap) impl; 79 | return RT.keys(m.seq(ascending)); 80 | } 81 | 82 | public ISeq seqFrom(Object key, boolean ascending){ 83 | PersistentTreeMap m = (PersistentTreeMap) impl; 84 | return RT.keys(m.seqFrom(key,ascending)); 85 | } 86 | 87 | public IPersistentMap meta(){ 88 | return _meta; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ProxyHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Oct 4, 2007 */ 12 | 13 | package clojure.lang; 14 | 15 | import java.lang.reflect.InvocationHandler; 16 | import java.lang.reflect.Method; 17 | 18 | public class ProxyHandler implements InvocationHandler{ 19 | //method-name-string->fn 20 | final IPersistentMap fns; 21 | 22 | 23 | public ProxyHandler(IPersistentMap fns){ 24 | this.fns = fns; 25 | } 26 | 27 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable{ 28 | Class rt = method.getReturnType(); 29 | IFn fn = (IFn) fns.valAt(method.getName()); 30 | if(fn == null) 31 | { 32 | if(rt == Void.TYPE) 33 | return null; 34 | else if(method.getName().equals("equals")) 35 | { 36 | return proxy == args[0]; 37 | } 38 | else if(method.getName().equals("hashCode")) 39 | { 40 | return System.identityHashCode(proxy); 41 | } 42 | else if(method.getName().equals("toString")) 43 | { 44 | return "Proxy: " + System.identityHashCode(proxy); 45 | } 46 | throw new UnsupportedOperationException(); 47 | } 48 | Object ret = fn.applyTo(ArraySeq.create(args)); 49 | if(rt == Void.TYPE) 50 | return null; 51 | else if(rt.isPrimitive()) 52 | { 53 | if(rt == Character.TYPE) 54 | return ret; 55 | else if(rt == Integer.TYPE) 56 | return ((Number) ret).intValue(); 57 | else if(rt == Long.TYPE) 58 | return ((Number) ret).longValue(); 59 | else if(rt == Float.TYPE) 60 | return ((Number) ret).floatValue(); 61 | else if(rt == Double.TYPE) 62 | return ((Number) ret).doubleValue(); 63 | else if(rt == Boolean.TYPE && !(ret instanceof Boolean)) 64 | return ret == null ? Boolean.FALSE : Boolean.TRUE; 65 | else if(rt == Byte.TYPE) 66 | return (byte) ((Number) ret).intValue(); 67 | else if(rt == Short.TYPE) 68 | return (short) ((Number) ret).intValue(); 69 | } 70 | return ret; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Range.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Apr 1, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | public class Range extends ASeq implements IReduce, Counted{ 16 | final int end; 17 | final int n; 18 | 19 | public Range(int start, int end){ 20 | this.end = end; 21 | this.n = start; 22 | } 23 | 24 | public Range(IPersistentMap meta, int start, int end){ 25 | super(meta); 26 | this.end = end; 27 | this.n = start; 28 | } 29 | 30 | public Obj withMeta(IPersistentMap meta){ 31 | if(meta == meta()) 32 | return this; 33 | return new Range(meta(), end, n); 34 | } 35 | 36 | public Object first(){ 37 | return n; 38 | } 39 | 40 | public ISeq next(){ 41 | if(n < end-1) 42 | return new Range(_meta, n + 1, end); 43 | return null; 44 | } 45 | 46 | public Object reduce(IFn f) throws Exception{ 47 | Object ret = n; 48 | for(int x = n+1;x < end;x++) 49 | ret = f.invoke(ret, x); 50 | return ret; 51 | } 52 | 53 | public Object reduce(IFn f, Object start) throws Exception{ 54 | Object ret = f.invoke(start,n); 55 | for(int x = n+1;x < end;x++) 56 | ret = f.invoke(ret, x); 57 | return ret; 58 | } 59 | 60 | public int count() { 61 | return end - n; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Ratio.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Mar 31, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | import java.math.BigInteger; 16 | import java.math.BigDecimal; 17 | import java.math.MathContext; 18 | 19 | public class Ratio extends Number implements Comparable{ 20 | final public BigInteger numerator; 21 | final public BigInteger denominator; 22 | 23 | public Ratio(BigInteger numerator, BigInteger denominator){ 24 | this.numerator = numerator; 25 | this.denominator = denominator; 26 | } 27 | 28 | public boolean equals(Object arg0){ 29 | return arg0 != null 30 | && arg0 instanceof Ratio 31 | && ((Ratio) arg0).numerator.equals(numerator) 32 | && ((Ratio) arg0).denominator.equals(denominator); 33 | } 34 | 35 | public int hashCode(){ 36 | return numerator.hashCode() ^ denominator.hashCode(); 37 | } 38 | 39 | public String toString(){ 40 | return numerator.toString() + "/" + denominator.toString(); 41 | } 42 | 43 | public int intValue(){ 44 | return (int) doubleValue(); 45 | } 46 | 47 | public long longValue(){ 48 | return bigIntegerValue().longValue(); 49 | } 50 | 51 | public float floatValue(){ 52 | return (float)doubleValue(); 53 | } 54 | 55 | public double doubleValue(){ 56 | return decimalValue(MathContext.DECIMAL64).doubleValue(); 57 | } 58 | 59 | public BigDecimal decimalValue(){ 60 | return decimalValue(MathContext.UNLIMITED); 61 | } 62 | 63 | public BigDecimal decimalValue(MathContext mc){ 64 | BigDecimal numerator = new BigDecimal(this.numerator); 65 | BigDecimal denominator = new BigDecimal(this.denominator); 66 | 67 | return numerator.divide(denominator, mc); 68 | } 69 | 70 | public BigInteger bigIntegerValue(){ 71 | return numerator.divide(denominator); 72 | } 73 | 74 | public int compareTo(Object o){ 75 | Number other = (Number)o; 76 | return Numbers.compare(this, other); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Repl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Oct 18, 2007 */ 12 | 13 | package clojure.lang; 14 | 15 | import clojure.main; 16 | 17 | public class Repl { 18 | 19 | public static void main(String[] args) throws Exception{ 20 | main.legacy_repl(args); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Reversible.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Jan 5, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface Reversible{ 16 | ISeq rseq() throws Exception; 17 | } 18 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Script.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Oct 18, 2007 */ 12 | 13 | package clojure.lang; 14 | 15 | import clojure.main; 16 | 17 | public class Script { 18 | 19 | public static void main(String[] args) throws Exception{ 20 | main.legacy_script(args); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/SeqEnumeration.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Mar 3, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | import java.util.Enumeration; 16 | 17 | public class SeqEnumeration implements Enumeration{ 18 | ISeq seq; 19 | 20 | public SeqEnumeration(ISeq seq){ 21 | this.seq = seq; 22 | } 23 | 24 | public boolean hasMoreElements(){ 25 | return seq != null; 26 | } 27 | 28 | public Object nextElement(){ 29 | Object ret = RT.first(seq); 30 | seq = RT.next(seq); 31 | return ret; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/SeqIterator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Jun 19, 2007 */ 12 | 13 | package clojure.lang; 14 | 15 | import java.util.Iterator; 16 | import java.util.NoSuchElementException; 17 | 18 | public class SeqIterator implements Iterator{ 19 | 20 | ISeq seq; 21 | 22 | public SeqIterator(ISeq seq){ 23 | this.seq = seq; 24 | } 25 | 26 | public boolean hasNext(){ 27 | return seq != null; 28 | } 29 | 30 | public Object next() throws NoSuchElementException { 31 | if(seq == null) 32 | throw new NoSuchElementException(); 33 | Object ret = RT.first(seq); 34 | seq = RT.next(seq); 35 | return ret; 36 | } 37 | 38 | public void remove(){ 39 | throw new UnsupportedOperationException(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Seqable.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Jan 28, 2009 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface Seqable { 16 | ISeq seq(); 17 | } 18 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Sequential.java: -------------------------------------------------------------------------------- 1 | package clojure.lang; 2 | 3 | /** 4 | * Copyright (c) Rich Hickey. All rights reserved. 5 | * The use and distribution terms for this software are covered by the 6 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 7 | * which can be found in the file epl-v10.html at the root of this distribution. 8 | * By using this software in any fashion, you are agreeing to be bound by 9 | * the terms of this license. 10 | * You must not remove this notice, or any other, from this software. 11 | */ 12 | public interface Sequential { 13 | } 14 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Settable.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Dec 31, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface Settable { 16 | Object doSet(Object val) throws Exception; 17 | Object doReset(Object val) throws Exception; 18 | } 19 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Sorted.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Apr 15, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | import java.util.Comparator; 16 | 17 | public interface Sorted{ 18 | Comparator comparator(); 19 | 20 | Object entryKey(Object entry); 21 | 22 | ISeq seq(boolean ascending); 23 | 24 | ISeq seqFrom(Object key, boolean ascending); 25 | } 26 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/StringSeq.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Dec 6, 2007 */ 12 | 13 | package clojure.lang; 14 | 15 | public class StringSeq extends ASeq implements IndexedSeq{ 16 | public final CharSequence s; 17 | public final int i; 18 | 19 | static public StringSeq create(CharSequence s){ 20 | if(s.length() == 0) 21 | return null; 22 | return new StringSeq(null, s, 0); 23 | } 24 | 25 | StringSeq(IPersistentMap meta, CharSequence s, int i){ 26 | super(meta); 27 | this.s = s; 28 | this.i = i; 29 | } 30 | 31 | public Obj withMeta(IPersistentMap meta){ 32 | if(meta == meta()) 33 | return this; 34 | return new StringSeq(meta, s, i); 35 | } 36 | 37 | public Object first(){ 38 | return Character.valueOf(s.charAt(i)); 39 | } 40 | 41 | public ISeq next(){ 42 | if(i + 1 < s.length()) 43 | return new StringSeq(_meta, s, i + 1); 44 | return null; 45 | } 46 | 47 | public int index(){ 48 | return i; 49 | } 50 | 51 | public int count(){ 52 | return s.length() - i; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Symbol.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Mar 25, 2006 11:42:47 AM */ 12 | 13 | package clojure.lang; 14 | 15 | import java.io.Serializable; 16 | import java.io.ObjectStreamException; 17 | 18 | 19 | public class Symbol extends AFn implements IObj, Comparable, Named, Serializable{ 20 | //these must be interned strings! 21 | final String ns; 22 | final String name; 23 | final int hash; 24 | final IPersistentMap _meta; 25 | 26 | public String toString(){ 27 | if(ns != null) 28 | return ns + "/" + name; 29 | return name; 30 | } 31 | 32 | public String getNamespace(){ 33 | return ns; 34 | } 35 | 36 | public String getName(){ 37 | return name; 38 | } 39 | 40 | static public Symbol intern(String ns, String name){ 41 | return new Symbol(ns == null ? null : ns.intern(), name.intern()); 42 | } 43 | 44 | static public Symbol intern(String nsname){ 45 | int i = nsname.lastIndexOf('/'); 46 | if(i == -1 || nsname.equals("/")) 47 | return new Symbol(null, nsname.intern()); 48 | else 49 | return new Symbol(nsname.substring(0, i).intern(), nsname.substring(i + 1).intern()); 50 | } 51 | 52 | static public Symbol create(String name_interned){ 53 | return new Symbol(null, name_interned); 54 | } 55 | 56 | static public Symbol create(String ns_interned, String name_interned){ 57 | return new Symbol(ns_interned, name_interned); 58 | } 59 | 60 | private Symbol(String ns_interned, String name_interned){ 61 | this.name = name_interned; 62 | this.ns = ns_interned; 63 | this.hash = Util.hashCombine(name.hashCode(), Util.hash(ns)); 64 | this._meta = null; 65 | } 66 | 67 | public boolean equals(Object o){ 68 | if(this == o) 69 | return true; 70 | if(!(o instanceof Symbol)) 71 | return false; 72 | 73 | Symbol symbol = (Symbol) o; 74 | 75 | //identity compares intended, names are interned 76 | return name == symbol.name && ns == symbol.ns; 77 | } 78 | 79 | public int hashCode(){ 80 | return hash; 81 | } 82 | 83 | public IObj withMeta(IPersistentMap meta){ 84 | return new Symbol(meta, ns, name); 85 | } 86 | 87 | private Symbol(IPersistentMap meta, String ns, String name){ 88 | this.name = name; 89 | this.ns = ns; 90 | this._meta = meta; 91 | this.hash = Util.hashCombine(name.hashCode(), Util.hash(ns)); 92 | } 93 | 94 | public int compareTo(Object o){ 95 | Symbol s = (Symbol) o; 96 | if(this.equals(o)) 97 | return 0; 98 | if(this.ns == null && s.ns != null) 99 | return -1; 100 | if(this.ns != null) 101 | { 102 | if(s.ns == null) 103 | return 1; 104 | int nsc = this.ns.compareTo(s.ns); 105 | if(nsc != 0) 106 | return nsc; 107 | } 108 | return this.name.compareTo(s.name); 109 | } 110 | 111 | private Object readResolve() throws ObjectStreamException{ 112 | return intern(ns, name); 113 | } 114 | 115 | public Object invoke(Object obj) throws Exception{ 116 | return RT.get(obj, this); 117 | } 118 | 119 | public Object invoke(Object obj, Object notFound) throws Exception{ 120 | return RT.get(obj, this, notFound); 121 | } 122 | 123 | public IPersistentMap meta(){ 124 | return _meta; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Util.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Apr 19, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | import java.math.BigInteger; 16 | 17 | public class Util{ 18 | static public boolean equiv(Object k1, Object k2){ 19 | if(k1 == k2) 20 | return true; 21 | if(k1 != null) 22 | { 23 | if(k1 instanceof Number && k2 instanceof Number) 24 | return Numbers.equiv(k1, k2); 25 | else if(k1 instanceof IPersistentCollection && k2 instanceof IPersistentCollection) 26 | return ((IPersistentCollection)k1).equiv(k2); 27 | return k1.equals(k2); 28 | } 29 | return false; 30 | } 31 | 32 | static public boolean equals(Object k1, Object k2){ 33 | if(k1 == k2) 34 | return true; 35 | return k1 != null && k1.equals(k2); 36 | } 37 | 38 | static public boolean identical(Object k1, Object k2){ 39 | return k1 == k2; 40 | } 41 | 42 | static public Class classOf(Object x){ 43 | if(x != null) 44 | return x.getClass(); 45 | return null; 46 | } 47 | 48 | static public int compare(Object k1, Object k2){ 49 | if(k1 == k2) 50 | return 0; 51 | if(k1 != null) 52 | { 53 | if(k2 == null) 54 | return 1; 55 | if(k1 instanceof Number) 56 | return Numbers.compare((Number) k1, (Number) k2); 57 | return ((Comparable) k1).compareTo(k2); 58 | } 59 | return -1; 60 | } 61 | 62 | static public int hash(Object o){ 63 | if(o == null) 64 | return 0; 65 | return o.hashCode(); 66 | } 67 | 68 | static public int hashCombine(int seed, int hash){ 69 | //a la boost 70 | seed ^= hash + 0x9e3779b9 + (seed << 6) + (seed >> 2); 71 | return seed; 72 | } 73 | 74 | static public boolean isPrimitive(Class c){ 75 | return c != null && c.isPrimitive() && !(c == Void.TYPE); 76 | } 77 | 78 | static public boolean isInteger(Object x){ 79 | return x instanceof Integer 80 | || x instanceof Long 81 | || x instanceof BigInteger; 82 | } 83 | 84 | static public Object ret1(Object ret, Object nil){ 85 | return ret; 86 | } 87 | 88 | static public ISeq ret1(ISeq ret, Object nil){ 89 | return ret; 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/XMLHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | /* rich Dec 17, 2007 */ 12 | 13 | package clojure.lang; 14 | 15 | import org.xml.sax.Attributes; 16 | import org.xml.sax.ContentHandler; 17 | import org.xml.sax.Locator; 18 | import org.xml.sax.SAXException; 19 | import org.xml.sax.helpers.DefaultHandler; 20 | 21 | public class XMLHandler extends DefaultHandler{ 22 | ContentHandler h; 23 | 24 | 25 | public XMLHandler(ContentHandler h){ 26 | this.h = h; 27 | } 28 | 29 | public void setDocumentLocator(Locator locator){ 30 | h.setDocumentLocator(locator); 31 | } 32 | 33 | public void startDocument() throws SAXException{ 34 | h.startDocument(); 35 | } 36 | 37 | public void endDocument() throws SAXException{ 38 | h.endDocument(); 39 | } 40 | 41 | public void startPrefixMapping(String prefix, String uri) throws SAXException{ 42 | h.startPrefixMapping(prefix, uri); 43 | } 44 | 45 | public void endPrefixMapping(String prefix) throws SAXException{ 46 | h.endPrefixMapping(prefix); 47 | } 48 | 49 | public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException{ 50 | h.startElement(uri, localName, qName, atts); 51 | } 52 | 53 | public void endElement(String uri, String localName, String qName) throws SAXException{ 54 | h.endElement(uri, localName, qName); 55 | } 56 | 57 | public void characters(char ch[], int start, int length) throws SAXException{ 58 | h.characters(ch, start, length); 59 | } 60 | 61 | public void ignorableWhitespace(char ch[], int start, int length) throws SAXException{ 62 | h.ignorableWhitespace(ch, start, length); 63 | } 64 | 65 | public void processingInstruction(String target, String data) throws SAXException{ 66 | h.processingInstruction(target, data); 67 | } 68 | 69 | public void skippedEntity(String name) throws SAXException{ 70 | h.skippedEntity(name); 71 | } 72 | 73 | /* 74 | public static void main(String[] args){ 75 | try 76 | { 77 | ContentHandler dummy = new DefaultHandler(); 78 | SAXParserFactory f = SAXParserFactory.newInstance(); 79 | //f.setNamespaceAware(true); 80 | SAXParser p = f.newSAXParser(); 81 | p.parse("http://arstechnica.com/journals.rssx",new XMLHandler(dummy)); 82 | } 83 | catch(Exception e) 84 | { 85 | e.printStackTrace(); 86 | } 87 | } 88 | //*/ 89 | } 90 | -------------------------------------------------------------------------------- /src/jvm/clojure/main.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Rich Hickey. All rights reserved. 3 | * The use and distribution terms for this software are covered by the 4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 5 | * which can be found in the file epl-v10.html at the root of this distribution. 6 | * By using this software in any fashion, you are agreeing to be bound by 7 | * the terms of this license. 8 | * You must not remove this notice, or any other, from this software. 9 | **/ 10 | 11 | package clojure; 12 | 13 | import clojure.lang.Symbol; 14 | import clojure.lang.Var; 15 | import clojure.lang.RT; 16 | 17 | public class main{ 18 | 19 | final static private Symbol CLOJURE_MAIN = Symbol.intern("clojure.main"); 20 | final static private Var REQUIRE = RT.var("clojure.core", "require"); 21 | final static private Var LEGACY_REPL = RT.var("clojure.main", "legacy-repl"); 22 | final static private Var LEGACY_SCRIPT = RT.var("clojure.main", "legacy-script"); 23 | final static private Var MAIN = RT.var("clojure.main", "main"); 24 | 25 | public static void legacy_repl(String[] args) throws Exception{ 26 | REQUIRE.invoke(CLOJURE_MAIN); 27 | LEGACY_REPL.invoke(RT.seq(args)); 28 | } 29 | 30 | public static void legacy_script(String[] args) throws Exception{ 31 | REQUIRE.invoke(CLOJURE_MAIN); 32 | LEGACY_SCRIPT.invoke(RT.seq(args)); 33 | } 34 | 35 | public static void main(String[] args) throws Exception{ 36 | REQUIRE.invoke(CLOJURE_MAIN); 37 | MAIN.applyTo(RT.seq(args)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /test/clojure/test_clojure.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | ; 9 | 10 | ;; clojure.test-clojure 11 | ;; 12 | ;; Tests for the facilities provided by Clojure 13 | ;; 14 | ;; scgilardi (gmail) 15 | ;; Created 22 October 2008 16 | 17 | (ns clojure.test-clojure 18 | (:require [clojure.test :as t]) 19 | (:gen-class)) 20 | 21 | (def test-names 22 | [:reader 23 | :printer 24 | :compilation 25 | :evaluation 26 | :special 27 | :macros 28 | :metadata 29 | :ns-libs 30 | :logic 31 | :predicates 32 | :control 33 | :data-structures 34 | :numbers 35 | :sequences 36 | :for 37 | :multimethods 38 | :other-functions 39 | :vars 40 | :refs 41 | :agents 42 | :atoms 43 | :parallel 44 | :java-interop 45 | :test 46 | :test-fixtures 47 | ;; libraries 48 | :clojure-set 49 | :clojure-xml 50 | :clojure-zip 51 | :protocols 52 | :genclass 53 | :main 54 | :vectors 55 | :annotations 56 | :pprint 57 | :serialization 58 | :rt 59 | :repl 60 | :java.io 61 | :string 62 | :java.javadoc 63 | :java.shell 64 | :transients 65 | :def 66 | ]) 67 | 68 | (def test-namespaces 69 | (map #(symbol (str "clojure.test-clojure." (name %))) 70 | test-names)) 71 | 72 | (defn run 73 | "Runs all defined tests" 74 | [] 75 | (println "Loading tests...") 76 | (apply require :reload-all test-namespaces) 77 | (apply t/run-tests test-namespaces)) 78 | 79 | (defn run-ant 80 | "Runs all defined tests, prints report to *err*, throw if failures. This works well for running in an ant java task." 81 | [] 82 | (let [rpt t/report] 83 | (binding [;; binding to *err* because, in ant, when the test target 84 | ;; runs after compile-clojure, *out* doesn't print anything 85 | *out* *err* 86 | t/*test-out* *err* 87 | t/report (fn report [m] 88 | (if (= :summary (:type m)) 89 | (do (rpt m) 90 | (if (or (pos? (:fail m)) (pos? (:error m))) 91 | (throw (new Exception (str (:fail m) " failures, " (:error m) " errors."))))) 92 | (rpt m)))] 93 | (run)))) 94 | 95 | (defn -main 96 | "Run all defined tests from the command line" 97 | [& args] 98 | (run) 99 | (System/exit 0)) 100 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/annotations.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ;; Authors: Stuart Halloway, Rich Hickey 10 | 11 | (ns clojure.test-clojure.annotations 12 | (:use clojure.test)) 13 | 14 | (defn vm-has-ws-annotations? 15 | "Does the vm have the ws annotations we use to test some 16 | annotation features. If not, fall back to Java 5 tests." 17 | [] 18 | (try 19 | (doseq [n ["javax.xml.ws.soap.Addressing" 20 | "javax.xml.ws.WebServiceRef" 21 | "javax.xml.ws.WebServiceRefs"]] 22 | (Class/forName n)) 23 | true 24 | (catch ClassNotFoundException e 25 | false))) 26 | 27 | (if (vm-has-ws-annotations?) 28 | (load "annotations/java_6_and_later") 29 | (load "annotations/java_5")) 30 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/annotations/java_5.clj: -------------------------------------------------------------------------------- 1 | ;; java 5 annotation tests 2 | (in-ns 'clojure.test-clojure.annotations) 3 | 4 | (import [java.lang.annotation Annotation Retention RetentionPolicy Target ElementType]) 5 | (definterface Foo (foo [])) 6 | 7 | (deftype #^{Deprecated true 8 | Retention RetentionPolicy/RUNTIME} 9 | Bar [#^int a 10 | #^{:tag int 11 | Deprecated true 12 | Retention RetentionPolicy/RUNTIME} b] 13 | Foo (#^{Deprecated true 14 | Retention RetentionPolicy/RUNTIME} 15 | foo [this] 42)) 16 | 17 | (defn annotation->map 18 | "Converts a Java annotation (which conceals data) 19 | into a map (which makes is usable). Not lazy. 20 | Works recursively. Returns non-annotations unscathed." 21 | [#^java.lang.annotation.Annotation o] 22 | (cond 23 | (instance? Annotation o) 24 | (let [type (.annotationType o) 25 | itfs (-> (into #{type} (supers type)) (disj java.lang.annotation.Annotation)) 26 | data-methods (into #{} (mapcat #(.getDeclaredMethods %) itfs))] 27 | (into 28 | {:annotationType (.annotationType o)} 29 | (map 30 | (fn [m] [(keyword (.getName m)) (annotation->map (.invoke m o nil))]) 31 | data-methods))) 32 | (or (sequential? o) (.isArray (class o))) 33 | (map annotation->map o) 34 | :else o)) 35 | 36 | (def expected-annotations 37 | #{{:annotationType java.lang.annotation.Retention, :value RetentionPolicy/RUNTIME} 38 | {:annotationType java.lang.Deprecated}}) 39 | 40 | (deftest test-annotations-on-type 41 | (is (= 42 | expected-annotations 43 | (into #{} (map annotation->map (.getAnnotations Bar)))))) 44 | 45 | (deftest test-annotations-on-field 46 | (is (= 47 | expected-annotations 48 | (into #{} (map annotation->map (.getAnnotations (.getField Bar "b"))))))) 49 | 50 | (deftest test-annotations-on-method 51 | (is (= 52 | expected-annotations 53 | (into #{} (map annotation->map (.getAnnotations (.getMethod Bar "foo" nil))))))) 54 | 55 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/annotations/java_6_and_later.clj: -------------------------------------------------------------------------------- 1 | ;; java 6 annotation tests 2 | (in-ns 'clojure.test-clojure.annotations) 3 | 4 | (import [java.lang.annotation Annotation Retention RetentionPolicy Target ElementType] 5 | [javax.xml.ws WebServiceRef WebServiceRefs]) 6 | (definterface Foo (foo [])) 7 | 8 | (deftype #^{Deprecated true 9 | Retention RetentionPolicy/RUNTIME 10 | javax.annotation.processing.SupportedOptions ["foo" "bar" "baz"] 11 | javax.xml.ws.soap.Addressing {:enabled false :required true} 12 | WebServiceRefs [(WebServiceRef {:name "fred" :type String}) 13 | (WebServiceRef {:name "ethel" :mappedName "lucy"})]} 14 | Bar [#^int a 15 | #^{:tag int 16 | Deprecated true 17 | Retention RetentionPolicy/RUNTIME 18 | javax.annotation.processing.SupportedOptions ["foo" "bar" "baz"] 19 | javax.xml.ws.soap.Addressing {:enabled false :required true} 20 | WebServiceRefs [(WebServiceRef {:name "fred" :type String}) 21 | (WebServiceRef {:name "ethel" :mappedName "lucy"})]} 22 | b] 23 | Foo (#^{Deprecated true 24 | Retention RetentionPolicy/RUNTIME 25 | javax.annotation.processing.SupportedOptions ["foo" "bar" "baz"] 26 | javax.xml.ws.soap.Addressing {:enabled false :required true} 27 | WebServiceRefs [(WebServiceRef {:name "fred" :type String}) 28 | (WebServiceRef {:name "ethel" :mappedName "lucy"})]} 29 | foo [this] 42)) 30 | 31 | (defn annotation->map 32 | "Converts a Java annotation (which conceals data) 33 | into a map (which makes is usable). Not lazy. 34 | Works recursively. Returns non-annotations unscathed." 35 | [#^java.lang.annotation.Annotation o] 36 | (cond 37 | (instance? Annotation o) 38 | (let [type (.annotationType o) 39 | itfs (-> (into #{type} (supers type)) (disj java.lang.annotation.Annotation)) 40 | data-methods (into #{} (mapcat #(.getDeclaredMethods %) itfs))] 41 | (into 42 | {:annotationType (.annotationType o)} 43 | (map 44 | (fn [m] [(keyword (.getName m)) (annotation->map (.invoke m o nil))]) 45 | data-methods))) 46 | (or (sequential? o) (.isArray (class o))) 47 | (map annotation->map o) 48 | :else o)) 49 | 50 | (def expected-annotations 51 | #{{:annotationType java.lang.annotation.Retention, :value RetentionPolicy/RUNTIME} 52 | {:annotationType javax.xml.ws.WebServiceRefs, 53 | :value [{:annotationType javax.xml.ws.WebServiceRef, :name "fred", :mappedName "", :type java.lang.String, :wsdlLocation "", :value java.lang.Object} 54 | {:annotationType javax.xml.ws.WebServiceRef, :name "ethel", :mappedName "lucy", :type java.lang.Object, :wsdlLocation "", :value java.lang.Object}]} 55 | {:annotationType javax.xml.ws.soap.Addressing, :enabled false, :required true} 56 | {:annotationType javax.annotation.processing.SupportedOptions, :value ["foo" "bar" "baz"]} 57 | {:annotationType java.lang.Deprecated}}) 58 | 59 | (deftest test-annotations-on-type 60 | (is (= 61 | expected-annotations 62 | (into #{} (map annotation->map (.getAnnotations Bar)))))) 63 | 64 | (deftest test-annotations-on-field 65 | (is (= 66 | expected-annotations 67 | (into #{} (map annotation->map (.getAnnotations (.getField Bar "b"))))))) 68 | 69 | (deftest test-annotations-on-method 70 | (is (= 71 | expected-annotations 72 | (into #{} (map annotation->map (.getAnnotations (.getMethod Bar "foo" nil))))))) 73 | 74 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/atoms.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ;;Author: Frantisek Sodomka 10 | 11 | (ns clojure.test-clojure.atoms 12 | (:use clojure.test)) 13 | 14 | ; http://clojure.org/atoms 15 | 16 | ; atom 17 | ; deref, @-reader-macro 18 | ; swap! reset! 19 | ; compare-and-set! 20 | 21 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/clojure_xml.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ;;Author: Frantisek Sodomka 10 | 11 | 12 | (ns clojure.test-clojure.clojure-xml 13 | (:use clojure.test) 14 | (:require [clojure.xml :as xml])) 15 | 16 | 17 | ; parse 18 | 19 | ; emit-element 20 | ; emit 21 | 22 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/clojure_zip.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ; Author: Frantisek Sodomka 10 | 11 | 12 | (ns clojure.test-clojure.clojure-zip 13 | (:use clojure.test) 14 | (:require [clojure.zip :as zip])) 15 | 16 | 17 | ; zipper 18 | ; 19 | ; seq-zip 20 | ; vector-zip 21 | ; xml-zip 22 | ; 23 | ; node 24 | ; branch? 25 | ; children 26 | ; make-node 27 | ; path 28 | ; lefts 29 | ; rights 30 | ; down 31 | ; up 32 | ; root 33 | ; right 34 | ; rightmost 35 | ; left 36 | ; leftmost 37 | ; 38 | ; insert-left 39 | ; insert-right 40 | ; replace 41 | ; edit 42 | ; insert-child 43 | ; append-child 44 | ; next 45 | ; prev 46 | ; end? 47 | ; remove 48 | 49 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/compilation.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ; Author: Frantisek Sodomka 10 | 11 | 12 | (ns clojure.test-clojure.compilation 13 | (:use clojure.test)) 14 | 15 | ; http://clojure.org/compilation 16 | 17 | ; compile 18 | ; gen-class, gen-interface 19 | 20 | 21 | (deftest test-compiler-metadata 22 | (let [m (meta #'when)] 23 | (are [x y] (= x y) 24 | (list? (:arglists m)) true 25 | (> (count (:arglists m)) 0) true 26 | 27 | (string? (:doc m)) true 28 | (> (.length (:doc m)) 0) true 29 | 30 | (string? (:file m)) true 31 | (> (.length (:file m)) 0) true 32 | 33 | (integer? (:line m)) true 34 | (> (:line m) 0) true 35 | 36 | (:macro m) true 37 | (:name m) 'when ))) 38 | 39 | (deftest test-embedded-constants 40 | (testing "Embedded constants" 41 | (is (eval `(= Boolean/TYPE ~Boolean/TYPE))) 42 | (is (eval `(= Byte/TYPE ~Byte/TYPE))) 43 | (is (eval `(= Character/TYPE ~Character/TYPE))) 44 | (is (eval `(= Double/TYPE ~Double/TYPE))) 45 | (is (eval `(= Float/TYPE ~Float/TYPE))) 46 | (is (eval `(= Integer/TYPE ~Integer/TYPE))) 47 | (is (eval `(= Long/TYPE ~Long/TYPE))) 48 | (is (eval `(= Short/TYPE ~Short/TYPE))))) 49 | 50 | (deftest test-compiler-resolution 51 | (testing "resolve nonexistent class create should return nil (assembla #262)" 52 | (is (nil? (resolve 'NonExistentClass.))))) 53 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/def.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.test-clojure.def 10 | (:use clojure.test clojure.test-clojure.helpers 11 | clojure.test-clojure.protocols)) 12 | 13 | (deftest defn-error-messages 14 | (testing "bad arglist forms" 15 | (is (fails-with-cause? IllegalArgumentException '#"Parameter declaration arg1 should be a vector" 16 | (eval-in-temp-ns (defn foo (arg1 arg2))))))) 17 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/genclass.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | (ns ^{:doc "Tests for clojure.core/gen-class" 10 | :author "Stuart Halloway, Daniel Solano Gómez"} 11 | clojure.test-clojure.genclass 12 | (:use clojure.test) 13 | (:import [clojure.test_clojure.genclass.examples ExampleClass 14 | ExampleAnnotationClass] 15 | [java.lang.annotation ElementType 16 | Retention 17 | RetentionPolicy 18 | Target])) 19 | 20 | ;; pull this up to a suite-wide helper if you find other tests need it! 21 | (defn get-field 22 | "Access to private or protected field. field-name is a symbol or 23 | keyword." 24 | ([klass field-name] 25 | (get-field klass field-name nil)) 26 | ([klass field-name inst] 27 | (-> klass (.getDeclaredField (name field-name)) 28 | (doto (.setAccessible true)) 29 | (.get inst)))) 30 | 31 | (deftest arg-support 32 | (let [example (ExampleClass.) 33 | o (Object.)] 34 | (is (= "foo with o, o" (.foo example o o))) 35 | (is (= "foo with o, i" (.foo example o (int 1)))) 36 | (is (thrown? java.lang.UnsupportedOperationException (.foo example o))))) 37 | 38 | (deftest name-munging 39 | (testing "mapping from Java fields to Clojure vars" 40 | (is (= #'clojure.test-clojure.genclass.examples/-foo-Object-int 41 | (get-field ExampleClass 'foo_Object_int__var))) 42 | (is (= #'clojure.test-clojure.genclass.examples/-toString 43 | (get-field ExampleClass 'toString__var))))) 44 | 45 | (deftest test-annotations 46 | (let [annot-class ExampleAnnotationClass 47 | foo-method (.getDeclaredMethod annot-class "foo" (into-array [String]))] 48 | (testing "Class annotations:" 49 | (is (= 2 (count (.getDeclaredAnnotations annot-class)))) 50 | (testing "@Deprecated" 51 | (let [deprecated (.getAnnotation annot-class Deprecated)] 52 | (is deprecated))) 53 | (testing "@Target([])" 54 | (let [resource (.getAnnotation annot-class Target)] 55 | (is (= 0 (count (.value resource))))))) 56 | (testing "Method annotations:" 57 | (testing "@Deprecated void foo(String):" 58 | (is (= 1 (count (.getDeclaredAnnotations foo-method)))) 59 | (is (.getAnnotation foo-method Deprecated)))) 60 | (testing "Parameter annotations:" 61 | (let [param-annots (.getParameterAnnotations foo-method)] 62 | (is (= 1 (alength param-annots))) 63 | (let [first-param-annots (aget param-annots 0)] 64 | (is (= 2 (alength first-param-annots))) 65 | (testing "void foo(@Retention(…) String)" 66 | (let [retention (aget first-param-annots 0)] 67 | (is (instance? Retention retention)) 68 | (= RetentionPolicy/SOURCE (.value retention)))) 69 | (testing "void foo(@Target(…) String)" 70 | (let [target (aget first-param-annots 1)] 71 | (is (instance? Target target)) 72 | (is (= [ElementType/TYPE ElementType/PARAMETER] (seq (.value target))))))))))) 73 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/genclass/examples.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | (ns ^{:doc "Test classes that are AOT-compile for the tests in 10 | clojure.test-clojure.genclass." 11 | :author "Stuart Halloway, Daniel Solano Gómez"} 12 | clojure.test-clojure.genclass.examples) 13 | 14 | (definterface ExampleInterface 15 | (foo [a]) 16 | (foo [a b]) 17 | (foo [a #^int b])) 18 | 19 | (gen-class :name clojure.test_clojure.genclass.examples.ExampleClass 20 | :implements [clojure.test_clojure.genclass.examples.ExampleInterface]) 21 | 22 | ;; -foo-Object unimplemented to test missing fn case 23 | 24 | (defn -foo-Object-Object 25 | [_ o1 o2] 26 | "foo with o, o") 27 | 28 | (defn -foo-Object-int 29 | [_ o i] 30 | "foo with o, i") 31 | 32 | (gen-class :name ^{Deprecated {} 33 | SuppressWarnings ["Warning1"] ; discarded 34 | java.lang.annotation.Target []} 35 | clojure.test_clojure.genclass.examples.ExampleAnnotationClass 36 | :prefix "annot-" 37 | :methods [[^{Deprecated {} 38 | Override {}} ;discarded 39 | foo [^{java.lang.annotation.Retention java.lang.annotation.RetentionPolicy/SOURCE 40 | java.lang.annotation.Target [java.lang.annotation.ElementType/TYPE 41 | java.lang.annotation.ElementType/PARAMETER]} 42 | String] void]]) 43 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/helpers.clj: -------------------------------------------------------------------------------- 1 | ; The use and distribution terms for this software are covered by the 2 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 3 | ; which can be found in the file epl-v10.html at the root of this distribution. 4 | ; By using this software in any fashion, you are agreeing to be bound by 5 | ; the terms of this license. 6 | ; You must not remove this notice, or any other, from this software. 7 | 8 | ; Author: Stuart Halloway 9 | 10 | (ns clojure.test-clojure.helpers 11 | (:use clojure.test)) 12 | 13 | (defn temp-ns 14 | "Create and return a temporary ns, using clojure.core + uses" 15 | [& uses] 16 | (binding [*ns* *ns*] 17 | (in-ns (gensym)) 18 | (apply clojure.core/use 'clojure.core uses) 19 | *ns*)) 20 | 21 | (defmacro eval-in-temp-ns [& forms] 22 | `(binding [*ns* *ns*] 23 | (in-ns (gensym)) 24 | (clojure.core/use 'clojure.core) 25 | (eval 26 | '(do ~@forms)))) 27 | 28 | (defn causes 29 | [^Throwable throwable] 30 | (loop [causes [] 31 | t throwable] 32 | (if t (recur (conj causes t) (.getCause t)) causes))) 33 | 34 | ;; this is how I wish clojure.test/thrown? worked... 35 | ;; Does body throw expected exception, anywhere in the .getCause chain? 36 | (defmethod assert-expr 'fails-with-cause? 37 | [msg [_ exception-class msg-re & body :as form]] 38 | `(try 39 | ~@body 40 | (report {:type :fail, :message ~msg, :expected '~form, :actual nil}) 41 | (catch Throwable t# 42 | (if (some (fn [cause#] 43 | (and 44 | (= ~exception-class (class cause#)) 45 | (re-find ~msg-re (.getMessage cause#)))) 46 | (causes t#)) 47 | (report {:type :pass, :message ~msg, 48 | :expected '~form, :actual t#}) 49 | (report {:type :fail, :message ~msg, 50 | :expected '~form, :actual t#}))))) 51 | 52 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/java/javadoc.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.test-clojure.java.javadoc 10 | (:use clojure.test 11 | [clojure.java.javadoc :as j]) 12 | (:import (java.io File))) 13 | 14 | (deftest javadoc-url-test 15 | (testing "for a core api" 16 | (binding [*feeling-lucky* false] 17 | (are [x y] (= x (#'j/javadoc-url y)) 18 | nil "foo.Bar" 19 | (str *core-java-api* "java/lang/String.html") "java.lang.String"))) 20 | (testing "for a remote javadoc" 21 | (binding [*remote-javadocs* (ref (sorted-map "java." "http://example.com/"))] 22 | (is (= "http://example.com/java/lang/Number.html" (#'j/javadoc-url "java.lang.Number")))))) 23 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/java/shell.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | (ns clojure.test-clojure.java.shell 10 | (:use clojure.test 11 | [clojure.java.shell :as sh]) 12 | (:import (java.io File))) 13 | 14 | (deftest test-parse-args 15 | (are [x y] (= x y) 16 | [[] {:out "UTF-8" :dir nil :env nil}] (#'sh/parse-args []) 17 | [["ls"] {:out "UTF-8" :dir nil :env nil}] (#'sh/parse-args ["ls"]) 18 | [["ls" "-l"] {:out "UTF-8" :dir nil :env nil}] (#'sh/parse-args ["ls" "-l"]) 19 | [["ls"] {:out "ISO-8859-1" :dir nil :env nil}] (#'sh/parse-args ["ls" :out "ISO-8859-1"]))) 20 | 21 | (deftest test-with-sh-dir 22 | (are [x y] (= x y) 23 | nil *sh-dir* 24 | "foo" (with-sh-dir "foo" *sh-dir*))) 25 | 26 | (deftest test-with-sh-env 27 | (are [x y] (= x y) 28 | nil *sh-env* 29 | {:KEY "VAL"} (with-sh-env {:KEY "VAL"} *sh-env*))) 30 | 31 | (deftest test-as-env-string 32 | (are [x y] (= x y) 33 | nil (#'sh/as-env-string nil) 34 | ["FOO=BAR"] (seq (#'sh/as-env-string {"FOO" "BAR"})) 35 | ["FOO_SYMBOL=BAR"] (seq (#'sh/as-env-string {'FOO_SYMBOL "BAR"})) 36 | ["FOO_KEYWORD=BAR"] (seq (#'sh/as-env-string {:FOO_KEYWORD "BAR"})))) 37 | 38 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/macros.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ; Author: Frantisek Sodomka 10 | 11 | (ns clojure.test-clojure.macros 12 | (:use clojure.test)) 13 | 14 | ; http://clojure.org/macros 15 | 16 | ; -> 17 | ; defmacro definline macroexpand-1 macroexpand 18 | 19 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/main.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ; Author: Stuart Halloway 10 | 11 | 12 | (ns clojure.test-clojure.main 13 | (:use clojure.test) 14 | (:require [clojure.main :as main])) 15 | 16 | (deftest eval-opt 17 | (testing "evals and prints forms" 18 | (is (= "2\n4\n" (with-out-str (#'clojure.main/eval-opt "(+ 1 1) (+ 2 2)"))))) 19 | 20 | (testing "skips printing nils" 21 | (is (= ":a\n:c\n" (with-out-str (#'clojure.main/eval-opt ":a nil :c"))))) 22 | 23 | (testing "does not block access to *in* (#299)" 24 | (with-in-str "(+ 1 1)" 25 | (is (= "(+ 1 1)\n" (with-out-str (#'clojure.main/eval-opt "(read)"))))))) 26 | 27 | (defmacro with-err-str 28 | "Evaluates exprs in a context in which *err* is bound to a fresh 29 | StringWriter. Returns the string created by any nested printing 30 | calls." 31 | [& body] 32 | `(let [s# (new java.io.StringWriter) 33 | p# (new java.io.PrintWriter s#)] 34 | (binding [*err* p#] 35 | ~@body 36 | (str s#)))) 37 | 38 | (defn run-repl-and-return-err 39 | "Run repl, swallowing stdout and returing stderr." 40 | [in-str] 41 | (with-err-str 42 | (with-out-str 43 | (with-in-str in-str 44 | (main/repl))))) 45 | 46 | (deftest repl-exception-safety 47 | (testing "catches and prints exception on bad equals" 48 | (is (= "java.lang.NullPointerException\n" 49 | (run-repl-and-return-err 50 | "(proxy [Object] [] (equals [o] (.toString nil)))"))))) 51 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/metadata.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ; Authors: Stuart Halloway, Frantisek Sodomka 10 | 11 | (ns clojure.test-clojure.metadata 12 | (:use clojure.test 13 | [clojure.test-clojure.helpers :only (eval-in-temp-ns)])) 14 | 15 | (def public-namespaces 16 | '[clojure.core 17 | clojure.pprint 18 | clojure.inspector 19 | clojure.set 20 | clojure.stacktrace 21 | clojure.test 22 | clojure.walk 23 | clojure.xml 24 | clojure.zip 25 | clojure.java.io 26 | clojure.java.browse 27 | clojure.java.javadoc 28 | clojure.java.shell 29 | clojure.string]) 30 | 31 | (doseq [ns public-namespaces] 32 | (require ns)) 33 | 34 | (def public-vars 35 | (mapcat #(vals (ns-publics %)) public-namespaces)) 36 | 37 | (def public-vars-with-docstrings 38 | (filter (comp :doc meta) public-vars)) 39 | 40 | (deftest public-vars-with-docstrings-have-added 41 | (is (= [] (remove (comp :added meta) public-vars-with-docstrings)))) 42 | 43 | (deftest interaction-of-def-with-metadata 44 | (testing "initial def sets metadata" 45 | (let [v (eval-in-temp-ns 46 | (def ^{:a 1} foo 0) 47 | #'foo)] 48 | (is (= 1 (-> v meta :a))))) 49 | (testing "subsequent declare doesn't overwrite metadata" 50 | (let [v (eval-in-temp-ns 51 | (def ^{:b 2} bar 0) 52 | (declare bar) 53 | #'bar)] 54 | (is (= 2 (-> v meta :b)))) 55 | (testing "when compiled" 56 | (let [v (eval-in-temp-ns 57 | (def ^{:c 3} bar 0) 58 | (defn declare-bar [] 59 | (declare bar)) 60 | (declare-bar) 61 | #'bar)] 62 | (is (= 3 (-> v meta :c)))))) 63 | (testing "subsequent def with init-expr *does* overwrite metadata" 64 | (let [v (eval-in-temp-ns 65 | (def ^{:d 4} quux 0) 66 | (def quux 1) 67 | #'quux)] 68 | (is (nil? (-> v meta :d)))) 69 | (testing "when compiled" 70 | (let [v (eval-in-temp-ns 71 | (def ^{:e 5} quux 0) 72 | (defn def-quux [] 73 | (def quux 1)) 74 | (def-quux) 75 | #'quux)] 76 | (is (nil? (-> v meta :e))))))) 77 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/multimethods.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ; Author: Frantisek Sodomka 10 | 11 | (ns clojure.test-clojure.multimethods 12 | (:use clojure.test)) 13 | 14 | ; http://clojure.org/multimethods 15 | 16 | ; defmulti 17 | ; defmethod 18 | ; remove-method 19 | ; prefer-method 20 | ; methods 21 | ; prefers 22 | 23 | ; derive, [underive] 24 | ; isa? 25 | ; parents, ancestors, descendants 26 | ; make-hierarchy 27 | 28 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/ns_libs.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ; Authors: Frantisek Sodomka, Stuart Halloway 10 | 11 | (ns clojure.test-clojure.ns-libs 12 | (:use clojure.test)) 13 | 14 | ; http://clojure.org/namespaces 15 | 16 | ; in-ns ns create-ns 17 | ; alias import intern refer 18 | ; all-ns find-ns 19 | ; ns-name ns-aliases ns-imports ns-interns ns-map ns-publics ns-refers 20 | ; resolve ns-resolve namespace 21 | ; ns-unalias ns-unmap remove-ns 22 | 23 | 24 | ; http://clojure.org/libs 25 | 26 | ; require use 27 | ; loaded-libs 28 | 29 | (deftest test-require 30 | (is (thrown? Exception (require :foo))) 31 | (is (thrown? Exception (require)))) 32 | 33 | (deftest test-use 34 | (is (thrown? Exception (use :foo))) 35 | (is (thrown? Exception (use)))) 36 | 37 | (deftest reimporting-deftypes 38 | (let [inst1 (binding [*ns* *ns*] 39 | (eval '(do (ns exporter) 40 | (defrecord ReimportMe [a]) 41 | (ns importer) 42 | (import exporter.ReimportMe) 43 | (ReimportMe. 1)))) 44 | inst2 (binding [*ns* *ns*] 45 | (eval '(do (ns exporter) 46 | (defrecord ReimportMe [a b]) 47 | (ns importer) 48 | (import exporter.ReimportMe) 49 | (ReimportMe. 1 2))))] 50 | (testing "you can reimport a changed class and see the changes" 51 | (is (= [:a] (keys inst1))) 52 | (is (= [:a :b] (keys inst2)))) 53 | (testing "you cannot import same local name from a different namespace" 54 | (is (thrown? clojure.lang.Compiler$CompilerException 55 | #"ReimportMe already refers to: class exporter.ReimportMe in namespace: importer" 56 | (binding [*ns* *ns*] 57 | (eval '(do (ns exporter-2) 58 | (defrecord ReimportMe [a b]) 59 | (ns importer) 60 | (import exporter-2.ReimportMe) 61 | (ReimportMe. 1 2))))))))) 62 | 63 | (deftest naming-types 64 | (testing "you cannot use a name already referred from another namespace" 65 | (is (thrown? IllegalStateException 66 | #"String already refers to: class java.lang.String" 67 | (definterface String))) 68 | (is (thrown? IllegalStateException 69 | #"StringBuffer already refers to: class java.lang.StringBuffer" 70 | (deftype StringBuffer []))) 71 | (is (thrown? IllegalStateException 72 | #"Integer already refers to: class java.lang.Integer" 73 | (defrecord Integer []))))) 74 | 75 | (deftest refer-error-messages 76 | (let [temp-ns (gensym)] 77 | (binding [*ns* *ns*] 78 | (in-ns temp-ns) 79 | (eval '(def ^{:private true} hidden-var))) 80 | (testing "referring to something that does not exist" 81 | (is (thrown-with-msg? IllegalAccessError #"nonexistent-var does not exist" 82 | (refer temp-ns :only '(nonexistent-var))))) 83 | (testing "referring to something non-public" 84 | (is (thrown-with-msg? IllegalAccessError #"hidden-var is not public" 85 | (refer temp-ns :only '(hidden-var))))))) 86 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/other_functions.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ; Author: Frantisek Sodomka 10 | 11 | 12 | (ns clojure.test-clojure.other-functions 13 | (:use clojure.test)) 14 | 15 | ; http://clojure.org/other_functions 16 | 17 | ; [= not= (tests in data_structures.clj and elsewhere)] 18 | 19 | 20 | (deftest test-identity 21 | ; exactly 1 argument needed 22 | (is (thrown? IllegalArgumentException (identity))) 23 | (is (thrown? IllegalArgumentException (identity 1 2))) 24 | 25 | (are [x] (= (identity x) x) 26 | nil 27 | false true 28 | 0 42 29 | 0.0 3.14 30 | 2/3 31 | 0M 1M 32 | \c 33 | "" "abc" 34 | 'sym 35 | :kw 36 | () '(1 2) 37 | [] [1 2] 38 | {} {:a 1 :b 2} 39 | #{} #{1 2} ) 40 | 41 | ; evaluation 42 | (are [x y] (= (identity x) y) 43 | (+ 1 2) 3 44 | (> 5 0) true )) 45 | 46 | 47 | (deftest test-name 48 | (are [x y] (= x (name y)) 49 | "foo" :foo 50 | "bar" 'bar 51 | "quux" "quux")) 52 | 53 | (deftest test-fnil 54 | (let [f1 (fnil vector :a) 55 | f2 (fnil vector :a :b) 56 | f3 (fnil vector :a :b :c)] 57 | (are [result input] (= result [(apply f1 input) (apply f2 input) (apply f3 input)]) 58 | [[1 2 3 4] [1 2 3 4] [1 2 3 4]] [1 2 3 4] 59 | [[:a 2 3 4] [:a 2 3 4] [:a 2 3 4]] [nil 2 3 4] 60 | [[:a nil 3 4] [:a :b 3 4] [:a :b 3 4]] [nil nil 3 4] 61 | [[:a nil nil 4] [:a :b nil 4] [:a :b :c 4]] [nil nil nil 4] 62 | [[:a nil nil nil] [:a :b nil nil] [:a :b :c nil]] [nil nil nil nil])) 63 | (are [x y] (= x y) 64 | ((fnil + 0) nil 42) 42 65 | ((fnil conj []) nil 42) [42] 66 | (reduce #(update-in %1 [%2] (fnil inc 0)) {} 67 | ["fun" "counting" "words" "fun"]) 68 | {"words" 1, "counting" 1, "fun" 2} 69 | (reduce #(update-in %1 [(first %2)] (fnil conj []) (second %2)) {} 70 | [[:a 1] [:a 2] [:b 3]]) 71 | {:b [3], :a [1 2]})) 72 | 73 | ; time assert comment doc 74 | 75 | ; partial 76 | ; comp 77 | ; complement 78 | ; constantly 79 | 80 | ; Printing 81 | ; pr prn print println newline 82 | ; pr-str prn-str print-str println-str [with-out-str (vars.clj)] 83 | 84 | ; Regex Support 85 | ; re-matcher re-find re-matches re-groups re-seq 86 | 87 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/parallel.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ; Author: Frantisek Sodomka 10 | 11 | 12 | (ns clojure.test-clojure.parallel 13 | (:use clojure.test)) 14 | 15 | ;; !! Tests for the parallel library will be in a separate file clojure_parallel.clj !! 16 | 17 | ; future-call 18 | ; future 19 | ; pmap 20 | ; pcalls 21 | ; pvalues 22 | 23 | 24 | ;; pmap 25 | ;; 26 | (deftest pmap-does-its-thing 27 | ;; regression fixed in r1218; was OutOfMemoryError 28 | (is (= '(1) (pmap inc [0])))) 29 | 30 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/pprint.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ;; Author: Tom Faulhaber 10 | 11 | (ns clojure.test-clojure.pprint 12 | (:refer-clojure :exclude [format]) 13 | (:use [clojure.test :only (deftest are run-tests)] 14 | clojure.test-clojure.pprint.test-helper 15 | clojure.pprint)) 16 | 17 | (load "pprint/test_cl_format") 18 | (load "pprint/test_pretty") 19 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/pprint/test_helper.clj: -------------------------------------------------------------------------------- 1 | ;;; test_helper.clj -- part of the pretty printer for Clojure 2 | 3 | ; Copyright (c) Rich Hickey. All rights reserved. 4 | ; The use and distribution terms for this software are covered by the 5 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 6 | ; which can be found in the file epl-v10.html at the root of this distribution. 7 | ; By using this software in any fashion, you are agreeing to be bound by 8 | ; the terms of this license. 9 | ; You must not remove this notice, or any other, from this software. 10 | 11 | ;; Author: Tom Faulhaber 12 | ;; April 3, 2009 13 | 14 | 15 | ;; This is just a macro to make my tests a little cleaner 16 | 17 | (ns clojure.test-clojure.pprint.test-helper 18 | (:use [clojure.test :only (deftest is)])) 19 | 20 | (defn- back-match [x y] (re-matches y x)) 21 | (defmacro simple-tests [name & test-pairs] 22 | `(deftest ~name 23 | ~@(for [[x y] (partition 2 test-pairs)] 24 | (if (instance? java.util.regex.Pattern y) 25 | `(is (#'clojure.test-clojure.pprint.test-helper/back-match ~x ~y)) 26 | `(is (= ~x ~y)))))) 27 | 28 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/predicates.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ; Author: Frantisek Sodomka 10 | 11 | ;; 12 | ;; Created 1/28/2009 13 | 14 | (ns clojure.test-clojure.predicates 15 | (:use clojure.test)) 16 | 17 | 18 | ;; *** Type predicates *** 19 | 20 | (def myvar 42) 21 | 22 | (def sample-data { 23 | :nil nil 24 | 25 | :bool-true true 26 | :bool-false false 27 | 28 | :byte (byte 7) 29 | :short (short 7) 30 | :int (int 7) 31 | :long (long 7) 32 | :bigint (bigint 7) 33 | :float (float 7) 34 | :double (double 7) 35 | :bigdec (bigdec 7) 36 | 37 | :ratio 2/3 38 | 39 | :character \a 40 | :symbol 'abc 41 | :keyword :kw 42 | 43 | :empty-string "" 44 | :empty-regex #"" 45 | :empty-list () 46 | :empty-lazy-seq (lazy-seq nil) 47 | :empty-vector [] 48 | :empty-map {} 49 | :empty-set #{} 50 | :empty-array (into-array []) 51 | 52 | :string "abc" 53 | :regex #"a*b" 54 | :list '(1 2 3) 55 | :lazy-seq (lazy-seq [1 2 3]) 56 | :vector [1 2 3] 57 | :map {:a 1 :b 2 :c 3} 58 | :set #{1 2 3} 59 | :array (into-array [1 2 3]) 60 | 61 | :fn (fn [x] (* 2 x)) 62 | 63 | :class java.util.Date 64 | :object (new java.util.Date) 65 | 66 | :var (var myvar) 67 | :delay (delay (+ 1 2)) 68 | }) 69 | 70 | 71 | (def type-preds { 72 | nil? [:nil] 73 | 74 | true? [:bool-true] 75 | false? [:bool-false] 76 | ; boolean? 77 | 78 | integer? [:byte :short :int :long :bigint] 79 | float? [:float :double] 80 | decimal? [:bigdec] 81 | ratio? [:ratio] 82 | rational? [:byte :short :int :long :bigint :ratio :bigdec] 83 | number? [:byte :short :int :long :bigint :ratio :bigdec :float :double] 84 | 85 | ; character? 86 | symbol? [:symbol] 87 | keyword? [:keyword] 88 | 89 | string? [:empty-string :string] 90 | ; regex? 91 | 92 | list? [:empty-list :list] 93 | vector? [:empty-vector :vector] 94 | map? [:empty-map :map] 95 | set? [:empty-set :set] 96 | 97 | coll? [:empty-list :list 98 | :empty-lazy-seq :lazy-seq 99 | :empty-vector :vector 100 | :empty-map :map 101 | :empty-set :set] 102 | 103 | seq? [:empty-list :list 104 | :empty-lazy-seq :lazy-seq] 105 | ; array? 106 | 107 | fn? [:fn] 108 | ifn? [:fn 109 | :empty-vector :vector :empty-map :map :empty-set :set 110 | :keyword :symbol :var] 111 | 112 | class? [:class] 113 | var? [:var] 114 | delay? [:delay] 115 | }) 116 | 117 | 118 | ;; Test all type predicates against all data types 119 | ;; 120 | (defn- get-fn-name [f] 121 | (str 122 | (apply str (nthnext (first (.split (str f) "_")) 123 | (count "clojure.core$"))) 124 | "?")) 125 | 126 | (deftest test-type-preds 127 | (doseq [tp type-preds] 128 | (doseq [dt sample-data] 129 | (if (some #(= % (first dt)) (second tp)) 130 | (is ((first tp) (second dt)) 131 | (pr-str (list (get-fn-name (first tp)) (second dt)))) 132 | (is (not ((first tp) (second dt))) 133 | (pr-str (list 'not (list (get-fn-name (first tp)) (second dt))))))))) 134 | 135 | 136 | ;; Additional tests: 137 | ;; http://groups.google.com/group/clojure/browse_thread/thread/537761a06edb4b06/bfd4f0705b746a38 138 | ;; 139 | (deftest test-string?-more 140 | (are [x] (not (string? x)) 141 | (new java.lang.StringBuilder "abc") 142 | (new java.lang.StringBuffer "xyz"))) 143 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/printer.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ; Author: Stephen C. Gilardi 10 | 11 | ;; clojure.test-clojure.printer 12 | ;; 13 | ;; scgilardi (gmail) 14 | ;; Created 29 October 2008 15 | 16 | (ns clojure.test-clojure.printer 17 | (:use clojure.test)) 18 | 19 | (deftest print-length-empty-seq 20 | (let [coll () val "()"] 21 | (is (= val (binding [*print-length* 0] (print-str coll)))) 22 | (is (= val (binding [*print-length* 1] (print-str coll)))))) 23 | 24 | (deftest print-length-seq 25 | (let [coll (range 5) 26 | length-val '((0 "(...)") 27 | (1 "(0 ...)") 28 | (2 "(0 1 ...)") 29 | (3 "(0 1 2 ...)") 30 | (4 "(0 1 2 3 ...)") 31 | (5 "(0 1 2 3 4)"))] 32 | (doseq [[length val] length-val] 33 | (binding [*print-length* length] 34 | (is (= val (print-str coll))))))) 35 | 36 | (deftest print-length-empty-vec 37 | (let [coll [] val "[]"] 38 | (is (= val (binding [*print-length* 0] (print-str coll)))) 39 | (is (= val (binding [*print-length* 1] (print-str coll)))))) 40 | 41 | (deftest print-length-vec 42 | (let [coll [0 1 2 3 4] 43 | length-val '((0 "[...]") 44 | (1 "[0 ...]") 45 | (2 "[0 1 ...]") 46 | (3 "[0 1 2 ...]") 47 | (4 "[0 1 2 3 ...]") 48 | (5 "[0 1 2 3 4]"))] 49 | (doseq [[length val] length-val] 50 | (binding [*print-length* length] 51 | (is (= val (print-str coll))))))) 52 | 53 | (deftest print-level-seq 54 | (let [coll '(0 (1 (2 (3 (4))))) 55 | level-val '((0 "#") 56 | (1 "(0 #)") 57 | (2 "(0 (1 #))") 58 | (3 "(0 (1 (2 #)))") 59 | (4 "(0 (1 (2 (3 #))))") 60 | (5 "(0 (1 (2 (3 (4)))))"))] 61 | (doseq [[level val] level-val] 62 | (binding [*print-level* level] 63 | (is (= val (print-str coll))))))) 64 | 65 | (deftest print-level-length-coll 66 | (let [coll '(if (member x y) (+ (first x) 3) (foo (a b c d "Baz"))) 67 | level-length-val 68 | '((0 1 "#") 69 | (1 1 "(if ...)") 70 | (1 2 "(if # ...)") 71 | (1 3 "(if # # ...)") 72 | (1 4 "(if # # #)") 73 | (2 1 "(if ...)") 74 | (2 2 "(if (member x ...) ...)") 75 | (2 3 "(if (member x y) (+ # 3) ...)") 76 | (3 2 "(if (member x ...) ...)") 77 | (3 3 "(if (member x y) (+ (first x) 3) ...)") 78 | (3 4 "(if (member x y) (+ (first x) 3) (foo (a b c d ...)))") 79 | (3 5 "(if (member x y) (+ (first x) 3) (foo (a b c d Baz)))"))] 80 | (doseq [[level length val] level-length-val] 81 | (binding [*print-level* level 82 | *print-length* length] 83 | (is (= val (print-str coll))))))) 84 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/protocols/examples.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.test-clojure.protocols.examples) 2 | 3 | (defprotocol ExampleProtocol 4 | "example protocol used by clojure tests" 5 | 6 | (foo [a] "method with one arg") 7 | (bar [a b] "method with two args") 8 | (^String baz [a] [a b] "method with multiple arities") 9 | (with-quux [a] "method name with a hyphen")) 10 | 11 | (definterface ExampleInterface 12 | (hinted [^int i]) 13 | (hinted [^String s])) 14 | 15 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/protocols/more_examples.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.test-clojure.protocols.more-examples) 2 | 3 | (defprotocol SimpleProtocol 4 | "example protocol used by clojure tests. Note that 5 | foo collides with examples/ExampleProtocol." 6 | 7 | (foo [a] "")) 8 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/refs.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ; Author: Frantisek Sodomka 10 | 11 | 12 | (ns clojure.test-clojure.refs 13 | (:use clojure.test)) 14 | 15 | ; http://clojure.org/refs 16 | 17 | ; ref 18 | ; deref, @-reader-macro 19 | ; dosync io! 20 | ; ensure ref-set alter commute 21 | ; set-validator get-validator 22 | 23 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/repl.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.test-clojure.repl 2 | (:use clojure.test 3 | clojure.repl 4 | clojure.test-clojure.repl.example)) 5 | 6 | (deftest test-source 7 | (is (= "(defn foo [])" (source-fn 'clojure.test-clojure.repl.example/foo))) 8 | (is (= "(defn foo [])\n" (with-out-str (source clojure.test-clojure.repl.example/foo)))) 9 | (is (nil? (source-fn 'non-existent-fn)))) 10 | 11 | (deftest test-dir 12 | (is (thrown? Exception (dir-fn 'non-existent-ns))) 13 | (is (= '[bar foo] (dir-fn 'clojure.test-clojure.repl.example))) 14 | (is (= "bar\nfoo\n" (with-out-str (dir clojure.test-clojure.repl.example))))) 15 | 16 | (deftest test-apropos 17 | (testing "with a regular expression" 18 | (is (= '[defmacro] (apropos #"^defmacro$"))) 19 | (is (some #{'defmacro} (apropos #"def.acr."))) 20 | (is (= [] (apropos #"nothing-has-this-name")))) 21 | 22 | (testing "with a string" 23 | (is (some #{'defmacro} (apropos "defmacro"))) 24 | (is (some #{'defmacro} (apropos "efmac"))) 25 | (is (= [] (apropos "nothing-has-this-name")))) 26 | 27 | (testing "with a symbol" 28 | (is (some #{'defmacro} (apropos 'defmacro))) 29 | (is (some #{'defmacro} (apropos 'efmac))) 30 | (is (= [] (apropos 'nothing-has-this-name))))) 31 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/repl/example.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.test-clojure.repl.example) 2 | 3 | ;; sample namespace for repl tests, don't add anything here 4 | (defn foo []) 5 | (defn bar []) 6 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/special.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ; Author: Frantisek Sodomka 10 | 11 | ;; 12 | ;; Test special forms, macros and metadata 13 | ;; 14 | 15 | (ns clojure.test-clojure.special 16 | (:use clojure.test)) 17 | 18 | ; http://clojure.org/special_forms 19 | 20 | ; let, letfn 21 | ; quote 22 | ; var 23 | ; fn 24 | 25 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/test_fixtures.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | ; 9 | ;;; test_fixtures.clj: unit tests for fixtures in test.clj 10 | 11 | ;; by Stuart Sierra 12 | ;; March 28, 2009 13 | 14 | (ns clojure.test-clojure.test-fixtures 15 | (:use clojure.test)) 16 | 17 | (declare *a* *b* *c* *d*) 18 | 19 | (def *n* 0) 20 | 21 | (defn fixture-a [f] 22 | (binding [*a* 3] (f))) 23 | 24 | (defn fixture-b [f] 25 | (binding [*b* 5] (f))) 26 | 27 | (defn fixture-c [f] 28 | (binding [*c* 7] (f))) 29 | 30 | (defn fixture-d [f] 31 | (binding [*d* 11] (f))) 32 | 33 | (defn inc-n-fixture [f] 34 | (binding [*n* (inc *n*)] (f))) 35 | 36 | (use-fixtures :once fixture-a fixture-b) 37 | 38 | (use-fixtures :each fixture-c fixture-d inc-n-fixture) 39 | (use-fixtures :each fixture-c fixture-d inc-n-fixture) 40 | 41 | (deftest can-use-once-fixtures 42 | (is (= 3 *a*)) 43 | (is (= 5 *b*))) 44 | 45 | (deftest can-use-each-fixtures 46 | (is (= 7 *c*)) 47 | (is (= 11 *d*))) 48 | 49 | (deftest use-fixtures-replaces 50 | (is (= *n* 1))) -------------------------------------------------------------------------------- /test/clojure/test_clojure/test_utils.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ; Author: Frantisek Sodomka 10 | 11 | 12 | (ns clojure.test-clojure.test-utils) 13 | 14 | (defn exception 15 | "Use this function to ensure that execution of a program doesn't 16 | reach certain point." 17 | [] 18 | (throw (new Exception "Exception which should never occur"))) 19 | 20 | 21 | ;; (defmacro all-are 22 | ;; "Test all-with-all. 23 | ;; (all-are (= _1 _2) 24 | ;; a b c) 25 | ;; => 26 | ;; (do 27 | ;; (is (= a b)) 28 | ;; (is (= a c)) 29 | ;; (is (= b c)))" 30 | ;; [expr & args] 31 | ;; (concat 32 | ;; (list 'clojure.contrib.template/do-template (list 'clojure.test/is expr)) 33 | ;; (apply concat (combinations args 2))))) 34 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/transients.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.test-clojure.transients 2 | (:use clojure.test)) 3 | 4 | (deftest popping-off 5 | (testing "across a node boundary" 6 | (are [n] 7 | (let [v (-> (range n) vec)] 8 | (= (subvec v 0 (- n 2)) (-> v transient pop! pop! persistent!))) 9 | 33 (+ 32 (inc (* 32 32))) (+ 32 (inc (* 32 32 32))))) 10 | (testing "off the end" 11 | (is (thrown-with-msg? IllegalStateException #"Can't pop empty vector" 12 | (-> [] transient pop!))))) 13 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/vars.clj: -------------------------------------------------------------------------------- 1 | ; Copyright (c) Rich Hickey. All rights reserved. 2 | ; The use and distribution terms for this software are covered by the 3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 4 | ; which can be found in the file epl-v10.html at the root of this distribution. 5 | ; By using this software in any fashion, you are agreeing to be bound by 6 | ; the terms of this license. 7 | ; You must not remove this notice, or any other, from this software. 8 | 9 | ; Author: Frantisek Sodomka, Stephen C. Gilardi 10 | 11 | 12 | (ns clojure.test-clojure.vars 13 | (:use clojure.test)) 14 | 15 | ; http://clojure.org/vars 16 | 17 | ; def 18 | ; defn defn- defonce 19 | 20 | ; declare intern binding find-var var 21 | 22 | (def a) 23 | (deftest test-binding 24 | (are [x y] (= x y) 25 | (eval `(binding [a 4] a)) 4 ; regression in Clojure SVN r1370 26 | )) 27 | 28 | ; with-local-vars var-get var-set alter-var-root [var? (predicates.clj)] 29 | ; with-in-str with-out-str 30 | ; with-open 31 | ; with-precision 32 | 33 | (deftest test-with-precision 34 | (are [x y] (= x y) 35 | (with-precision 4 (+ 3.5555555M 1)) 4.556M 36 | (with-precision 6 (+ 3.5555555M 1)) 4.55556M 37 | (with-precision 6 :rounding CEILING (+ 3.5555555M 1)) 4.55556M 38 | (with-precision 6 :rounding FLOOR (+ 3.5555555M 1)) 4.55555M 39 | (with-precision 6 :rounding HALF_UP (+ 3.5555555M 1)) 4.55556M 40 | (with-precision 6 :rounding HALF_DOWN (+ 3.5555555M 1)) 4.55556M 41 | (with-precision 6 :rounding HALF_EVEN (+ 3.5555555M 1)) 4.55556M 42 | (with-precision 6 :rounding UP (+ 3.5555555M 1)) 4.55556M 43 | (with-precision 6 :rounding DOWN (+ 3.5555555M 1)) 4.55555M 44 | (with-precision 6 :rounding UNNECESSARY (+ 3.5555M 1)) 4.5555M)) 45 | 46 | (deftest test-settable-math-context 47 | (is (= 48 | (clojure.main/with-bindings 49 | (set! *math-context* (java.math.MathContext. 8)) 50 | (+ 3.55555555555555M 1)) 51 | 4.5555556M))) 52 | 53 | ; set-validator get-validator 54 | 55 | ; doc find-doc test 56 | 57 | --------------------------------------------------------------------------------