Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Moved to Eclipse Public License - see epl-v10.html or

  • Loading branch information...
commit cad4fcf1afe7977b83c3ee2f40521eb38aa33e10 1 parent 0444198
Rich Hickey authored December 14, 2008

Showing 95 changed files with 444 additions and 1,617 deletions. Show diff stats Hide diff stats

  1. 94  CPL.TXT
  2. 1,033  clojure.markdown
  3. 261  epl-v10.html
  4. 6  readme.txt
  5. 4  src/clj/clojure/core.clj
  6. 4  src/clj/clojure/core_print.clj
  7. 4  src/clj/clojure/core_proxy.clj
  8. 4  src/clj/clojure/genclass.clj
  9. 4  src/clj/clojure/inspector.clj
  10. 4  src/clj/clojure/main.clj
  11. 4  src/clj/clojure/parallel.clj
  12. 307  src/clj/clojure/proxy.clj
  13. 4  src/clj/clojure/set.clj
  14. 4  src/clj/clojure/xml.clj
  15. 4  src/clj/clojure/zip.clj
  16. 4  src/jvm/clojure/lang/AFn.java
  17. 4  src/jvm/clojure/lang/AMapEntry.java
  18. 4  src/jvm/clojure/lang/APersistentMap.java
  19. 4  src/jvm/clojure/lang/APersistentSet.java
  20. 4  src/jvm/clojure/lang/APersistentVector.java
  21. 4  src/jvm/clojure/lang/ASeq.java
  22. 4  src/jvm/clojure/lang/Agent.java
  23. 4  src/jvm/clojure/lang/ArraySeq.java
  24. 4  src/jvm/clojure/lang/ArrayStream.java
  25. 4  src/jvm/clojure/lang/Associative.java
  26. 4  src/jvm/clojure/lang/Binding.java
  27. 4  src/jvm/clojure/lang/Box.java
  28. 4  src/jvm/clojure/lang/CachedSeq.java
  29. 4  src/jvm/clojure/lang/Compile.java
  30. 4  src/jvm/clojure/lang/Compiler.java
  31. 4  src/jvm/clojure/lang/Cons.java
  32. 4  src/jvm/clojure/lang/Delay.java
  33. 4  src/jvm/clojure/lang/DynamicClassLoader.java
  34. 4  src/jvm/clojure/lang/EnumerationSeq.java
  35. 4  src/jvm/clojure/lang/Fn.java
  36. 4  src/jvm/clojure/lang/FnSeq.java
  37. 4  src/jvm/clojure/lang/IFn.java
  38. 4  src/jvm/clojure/lang/IMapEntry.java
  39. 4  src/jvm/clojure/lang/IObj.java
  40. 4  src/jvm/clojure/lang/IPersistentCollection.java
  41. 4  src/jvm/clojure/lang/IPersistentList.java
  42. 4  src/jvm/clojure/lang/IPersistentMap.java
  43. 4  src/jvm/clojure/lang/IPersistentSet.java
  44. 4  src/jvm/clojure/lang/IPersistentStack.java
  45. 4  src/jvm/clojure/lang/IPersistentVector.java
  46. 4  src/jvm/clojure/lang/IProxy.java
  47. 4  src/jvm/clojure/lang/IReduce.java
  48. 4  src/jvm/clojure/lang/IRef.java
  49. 4  src/jvm/clojure/lang/ISeq.java
  50. 4  src/jvm/clojure/lang/IStream.java
  51. 4  src/jvm/clojure/lang/IndexedSeq.java
  52. 4  src/jvm/clojure/lang/IteratorSeq.java
  53. 4  src/jvm/clojure/lang/IteratorStream.java
  54. 4  src/jvm/clojure/lang/Keyword.java
  55. 4  src/jvm/clojure/lang/LazilyPersistentVector.java
  56. 4  src/jvm/clojure/lang/LazyCons.java
  57. 4  src/jvm/clojure/lang/LazySeq.java
  58. 4  src/jvm/clojure/lang/LineNumberingPushbackReader.java
  59. 4  src/jvm/clojure/lang/LispReader.java
  60. 4  src/jvm/clojure/lang/LockingTransaction.java
  61. 4  src/jvm/clojure/lang/MapEntry.java
  62. 4  src/jvm/clojure/lang/MultiFn.java
  63. 4  src/jvm/clojure/lang/Named.java
  64. 4  src/jvm/clojure/lang/Namespace.java
  65. 4  src/jvm/clojure/lang/Numbers.java
  66. 4  src/jvm/clojure/lang/Obj.java
  67. 4  src/jvm/clojure/lang/PersistentArrayMap.java
  68. 4  src/jvm/clojure/lang/PersistentHashSet.java
  69. 4  src/jvm/clojure/lang/PersistentList.java
  70. 4  src/jvm/clojure/lang/PersistentQueue.java
  71. 4  src/jvm/clojure/lang/PersistentStructMap.java
  72. 4  src/jvm/clojure/lang/PersistentTreeMap.java
  73. 4  src/jvm/clojure/lang/PersistentTreeSet.java
  74. 4  src/jvm/clojure/lang/ProxyHandler.java
  75. 4  src/jvm/clojure/lang/RT.java
  76. 4  src/jvm/clojure/lang/Range.java
  77. 4  src/jvm/clojure/lang/Ratio.java
  78. 4  src/jvm/clojure/lang/Ref.java
  79. 4  src/jvm/clojure/lang/Reflector.java
  80. 4  src/jvm/clojure/lang/Repl.java
  81. 4  src/jvm/clojure/lang/RestFn.java
  82. 4  src/jvm/clojure/lang/Reversible.java
  83. 4  src/jvm/clojure/lang/Script.java
  84. 4  src/jvm/clojure/lang/SeqEnumeration.java
  85. 4  src/jvm/clojure/lang/SeqIterator.java
  86. 4  src/jvm/clojure/lang/Sequential.java
  87. 4  src/jvm/clojure/lang/Sorted.java
  88. 4  src/jvm/clojure/lang/StreamSeq.java
  89. 4  src/jvm/clojure/lang/Streamable.java
  90. 4  src/jvm/clojure/lang/StringSeq.java
  91. 4  src/jvm/clojure/lang/Symbol.java
  92. 4  src/jvm/clojure/lang/TransactionalHashMap.java
  93. 4  src/jvm/clojure/lang/Util.java
  94. 4  src/jvm/clojure/lang/Var.java
  95. 4  src/jvm/clojure/lang/XMLHandler.java
94  CPL.TXT
... ...
@@ -1,94 +0,0 @@
1  
-Common Public License Version 1.0
2  
-
3  
-THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS COMMON PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
4  
-
5  
-
6  
-1. DEFINITIONS 
7  
-
8  
-"Contribution" means:
9  
-
10  
-a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and 
11  
-
12  
-b) in the case of each subsequent Contributor:
13  
-
14  
-i) changes to the Program, and
15  
-
16  
-ii) additions to the Program;
17  
-
18  
-where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program.
19  
-
20  
-"Contributor" means any person or entity that distributes the Program. 
21  
-
22  
-"Licensed Patents " mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program.
23  
-
24  
-"Program" means the Contributions distributed in accordance with this Agreement. 
25  
-
26  
-"Recipient" means anyone who receives the Program under this Agreement, including all Contributors. 
27  
-
28  
-
29  
-2. GRANT OF RIGHTS
30  
-
31  
-a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form.
32  
-
33  
-b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder.
34  
-
35  
-c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program.
36  
-
37  
-d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement.
38  
-
39  
-
40  
-3. REQUIREMENTS 
41  
-
42  
-A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that: 
43  
-
44  
-a) it complies with the terms and conditions of this Agreement; and
45  
-
46  
-b) its license agreement:
47  
-
48  
-i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose; 
49  
-
50  
-ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits; 
51  
-
52  
-iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and 
53  
-
54  
-iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange. 
55  
-
56  
-When the Program is made available in source code form:
57  
-
58  
-a) it must be made available under this Agreement; and
59  
-
60  
-b) a copy of this Agreement must be included with each copy of the Program. 
61  
-
62  
-Contributors may not remove or alter any copyright notices contained within the Program.
63  
-
64  
-Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution. 
65  
-
66  
-
67  
-4. COMMERCIAL DISTRIBUTION 
68  
-
69  
-Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense. 
70  
-
71  
-For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages. 
72  
-
73  
-
74  
-5. NO WARRANTY
75  
-
76  
-EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement, including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations. 
77  
-
78  
-
79  
-6. DISCLAIMER OF LIABILITY 
80  
-
81  
-EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 
82  
-
83  
-
84  
-7. GENERAL
85  
-
86  
-If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable. 
87  
-
88  
-If Recipient institutes patent litigation against a Contributor with respect to a patent applicable to software (including a cross-claim or counterclaim in a lawsuit), then any patent licenses granted by that Contributor to such Recipient under this Agreement shall terminate as of the date such litigation is filed. In addition, if Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed.
89  
-
90  
-All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive. 
91  
-
92  
-Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. IBM is the initial Agreement Steward. IBM may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved. 
93  
-
94  
-This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation.
1,033  clojure.markdown
Source Rendered
... ...
@@ -1,1033 +0,0 @@
1  
-<head>
2  
-	<title>Clojure</title> 
3  
-	<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1"/>
4  
-	<meta name="description" content="Clojure is a dynamic programming language for the JVM" />
5  
-	<meta name="keywords" content="Rich Hickey, Lisp, Java, software transactional memory, functional programming, persistent data structures"
6  
-   />
7  
-	<meta name="author" content="Rich Hickey" />
8  
-	<link rel="stylesheet" type="text/css" media="screen" href="clojure.css">
9  
-</head>
10  
-
11  
-#Clo*j*ure
12  
-## A Dynamic Programming Language for the JVM
13  
-Copyright (c) Rich Hickey. All rights reserved.
14  
-
15  
-The use and distribution terms for this software are covered by the [Common Public License 1.0][cpl], which can be found in the file CPL.TXT at the root of this distribution. By using this software in any fashion, you are agreeing to be bound by the terms of this license. You must not remove this notice, or any other, from this software.
16  
-
17  
-[cpl]:http://www.opensource.org/licenses/cpl1.0.php
18  
-
19  
-##Contents
20  
-###Introduction
21  
-Clojure is a dynamic programming language that targets the [Java Virtual Machine][jvm]. It is designed to be a general-purpose language, combining the approachability and interactive development of a scripting language with an efficient and robust infrastructure for multithreaded programming. Clojure is a compiled language - it compiles directly to JVM bytecode, yet remains completely dynamic. *Every* feature supported by Clojure is supported at runtime. Clojure provides easy access to the Java frameworks, with *optional* type hints and type inference, to ensure that calls to Java can avoid reflection. 
22  
-
23  
-Clojure is a dialect of Lisp, and shares with Lisp the code-as-data philosophy and a powerful macro system. Clojure is predominantly a [functional programming][fp] language, and features a rich set of immutable, [persistent data structures][pd]. When mutable state is needed, Clojure offers a [software transactional memory][stm] system that ensures clean, correct, multithreaded designs.
24  
-
25  
-I hope you find Clojure's combination of facilities elegant, powerful, practical and fun to use.
26  
-
27  
-
28  
-[jvm]:http://java.sun.com/docs/books/jvms/
29  
-[fp]: http://en.wikipedia.org/wiki/Functional_programming
30  
-[pd]: http://en.wikipedia.org/wiki/Persistent_data_structure
31  
-[stm]:http://en.wikipedia.org/wiki/Software_transactional_memory
32  
-
33  
-Rich Hickey
34  
-
35  
----
36  
-This documentation is continually being updated to reflect the current and new features of Clojure. Check back frequently for additions and corrections.
37  
-
38  
-###[Setup](#setup)
39  
-###[Quick Start](#quickstart)
40  
-###[Reader](#reader)
41  
-###[Evaluation](#evaluation)
42  
-###[Special Forms](#specialforms)
43  
-###[Macros](#macros)
44  
-###[Other Useful Functions](#other)
45  
-###[Data Structures](#datastructures)
46  
-###[Metadata](#metadata)
47  
-###[Sequences](#sequences)
48  
-###[Namespaces](#namespaces)
49  
-###[Vars and the Global Environment](#vars)
50  
-###[Refs and Transactions](#refs)
51  
-###[Differences with other Lisps](#lisp)			
52  
-
53  
-<h2 id="setup">Setup</h2>
54  
-
55  
-Clojure is [hosted on SourceForge][sf]. 
56  
-
57  
-Feedback and discussion should occur on the [Clojure Google Group][cgg].
58  
-
59  
-Clojure is delivered in a zip file containing a single .jar, `clojure.jar`, a readme, the CPL license and the source code in a `src` subdirectory. It uses the [ASM 3.0 bytecode library][asm], and the current alpha distribution includes it. [Java][jdk] 1.5 or greater is required.
60  
-
61  
-[asm]: http://asm.objectweb.org/
62  
-[jdk]: http://java.sun.com/javase/downloads/index.jsp
63  
-[sf]:  http://sourceforge.net/project/showfiles.php?group_id=137961
64  
-[cgg]: http://groups.google.com/group/clojure
65  
-
66  
-<h2 id="quickstart">Quick Start</h2>
67  
-In the directory in which you expanded `clojure.zip`, run:
68  
-
69  
-<pre><code>
70  
-java -cp clojure.jar clojure.lang.Compiler src/boot.clj
71  
-</code></pre>
72  
-
73  
-This will bring up a simple read-eval-print loop (REPL). Much of Clojure is defined in Clojure itself (in the `boot.clj` file included in the `src` directory of distribution), so the command-line argument is needed to load it.
74  
-
75  
-When boot.clj is loaded you will have the language as described herein fully available.
76  
-
77  
-Try:
78  
-
79  
-<pre><code>
80  
-user=> (+ 1 2 3)
81  
-6
82  
-user=> (. javax.swing.JOptionPane (showMessageDialog nil "Hello World"))	
83  
-</code></pre>
84  
-
85  
-<h2 id="reader">Reader</h2>
86  
-
87  
-Clojure is a [homoiconic][hicon] language, which is a fancy term describing the fact that Clojure programs are represented by Clojure data structures. This is a very important difference between Clojure (and Common Lisp) and most other programming languages - Clojure is defined in terms of the evaluation of a data structure and **not** in terms of the syntax of character streams/files. It is quite common, and easy, for Clojure programs to manipulate, transform and produce other Clojure programs.
88  
-
89  
-That said, most Clojure programs begin life as text files, and it is the task of the *reader* to parse the text and produce the data structure the compiler will see. This is not merely a phase of the compiler. The reader, and the Clojure data representations, have utility on their own in many of the same contexts one might use XML or JSON etc.
90  
-
91  
-One might say the reader has syntax defined in terms of characters, and the Clojure language has syntax defined in terms of symbols, lists, vectors, maps etc. The reader is represented by the function `read`, which reads the next form (not character) from a stream, and returns the object represented by that form.
92  
-
93  
-Since we have to start somewhere, we might as well start where evaluation starts, with the reader forms. This will inevitably entail talking about data structures whose descriptive details, and interpretation by the compiler, will follow.
94  
-
95  
-[hicon]:http://en.wikipedia.org/wiki/Homoiconicity
96  
-	
97  
-### Reader forms
98  
-* 	Symbols
99  
-
100  
-	Symbols begin with a non-numeric character and can contain alphanumeric characters and *, +, !, -, _, and ? (other characters will be allowed eventually, but not all macro characters have been determined). '/' has special meaning, it can be used once in the middle of a symbol to separate the [namespace](#namespaces) from the name, e.g. `my-namespace/foo`. '/' by itself names the division function. '.' has special meaning - it can be used one or more times in the middle of a symbol to designate a fully-qualified class name, e.g. `java.util.BitSet`. Symbols beginning with '.' are reserved by Clojure.
101  
-
102  
-* 	Literals
103  
-	* Strings - Enclosed in `"double quotes"`. Standard Java escape characters.
104  
-	* Numbers - as per Java, plus indefinitely long integers are supported, as well as ratios, e.g. `22/7`
105  
-	* Characters - preceded by a backslash: `\c`. 
106  
-	
107  
-		`\newline`, `\space` and `\tab` yield the corresponding characters.
108  
-	* `nil` - represents null and logical false
109  
-	* Keywords
110  
-
111  
-		Keywords are like symbols, except: 
112  
-		* They can and must begin with a colon, e.g. `:fred`.
113  
-		* They cannot contain '.' or name classes.
114  
-
115  
-*	Lists
116  
-
117  
-	Lists are zero or more forms enclosed in parentheses: 
118  
-		
119  
-	`(a b c)`
120  
-	
121  
-* 	Vectors
122  
-	
123  
-	Vectors are zero or more forms enclosed in square brackets:
124  
-	
125  
-	`[1 2 3]`
126  
-	
127  
-* 	Maps
128  
-
129  
-	Maps are zero or more key/value pairs enclosed in braces:
130  
-	
131  
-	`{:a 1 :b 2}`
132  
-	
133  
-	Commas are considered whitespace, and can be used to organize the pairs:
134  
-	
135  
-	`{:a 1, :b 2}`
136  
-	
137  
-	Keys and values can be any forms.
138  
-
139  
-### Macro characters
140  
-The behavior of the reader is driven by a combination of built-in constructs and an extension system called the read table. Entries in the read table provide mappings from certain characters, called macro characters, to specific reading behavior, called reader macros. Unless indicated otherwise, macro characters cannot be used in user symbols.
141  
-
142  
-*	Quote (')
143  
-
144  
-	`'form` => `(quote form)`
145  
-*	Character (\\)
146  
-
147  
-	As per above, yields a character literal.
148  
-	
149  
-*	Comment (;)
150  
-
151  
-	Single-line comment, causes the reader to ignore everything from the semicolon to the end-of-line.
152  
-	
153  
-*	Meta (^)
154  
-
155  
-	`^form` => `(meta form)`
156  
-*	Deref (@, @!)
157  
-
158  
-	`@form` => `(deref form)`
159  
-
160  
-	`@!form` => `(deref! form)`
161  
-	
162  
-*	Dispatch (#)
163  
-
164  
-	The dispatch macro causes the reader to use a reader macro from another table, indexed by the character following #:
165  
-
166  
-	*	Metadata (#^)
167  
-	
168  
-		Symbols, Lists, Vector and Maps can have metadata, which is a map associated with the object. The metadata reader macro first reads the metadata and attaches it to the next form read:
169  
-		
170  
-		`#^{:a 1 :b 2} [1 2 3]` yields the vector [1 2 3] with a metadata map of {:a 1 :b 2}.
171  
-		
172  
-		A shorthand version allows the metadata to be a simple symbol or keyword, in which case it is treated as a single entry map with a key of :clojure/tag and a value of the symbol provided, e.g.:
173  
-		
174  
-		`#^String x` is the same as `#^{:clojure/tag String} x`
175  
-		
176  
-		Such tags can be used to convey type information to the compiler. 
177  
-		
178  
-	*	Var-quote (#')
179  
-		
180  
-		`#'x` => `(the-var x)`
181  
-
182  
-*	Syntax-quote (\`, note, the "backquote" character), Unquote (~) and Unquote-splicing (~@)
183  
-
184  
-	For all forms other than Symbols, Lists, Vectors and Maps, \`x is the same as 'x. 
185  
-
186  
-	For Symbols, syntax-quote *resolves* the symbol in the current context, yielding a fully-qualified symbol (i.e. namespace/name or fully.qualified.Classname). If a symbol is non-namespace-qualified and ends with '#', it is resolved to a generated symbol with the same name to which '\_' and a unique id have been appended. e.g. `x#` will resolve to `x_123`. All references to that symbol within a syntax-quoted expression resolve to the same generated symbol.
187  
-
188  
-	For Lists/Vectors/Maps, syntax-quote establishes a template of the corresponding data structure. Within the template, unqualified forms behave as if recursively syntax-quoted, but forms can be exempted from such recursive quoting by qualifying them with unquote or unquote-splicing, in which case they will be treated as expressions and be replaced in the template by their value, or sequence of values, respectively.
189  
-
190  
-	For example:
191  
-<pre><code>
192  
-	
193  
-	user=> (def x 5)
194  
-	user=> (def lst '(a b c))
195  
-	user=> `(fred x ~x lst ~@lst 7 8 :nine)
196  
-
197  
-	(user/fred user/x 5 user/lst a b c 7 8 :nine)
198  
-		
199  
-</code></pre>	
200  
-
201  
-
202  
-The read table is currently not accessible to user programs.
203  
-
204  
-
205  
-
206  
-<h2 id="evaluation">Evaluation</h2>
207  
-Evaluation can occur in many contexts:
208  
-
209  
-*	Interactively, in the REPL
210  
-*	On a sequence of forms read from a stream, via `load` or `load-file`
211  
-*	Programmatically, via `eval`
212  
-
213  
-Clojure programs are composed of expressions. Every form not handled specially by a special form or macro is considered by the compiler to be an expression, which is evaluated to yield a value. There are no declarations or statements, although sometimes expressions may be evaluated for their side-effects and their values ignored.
214  
-
215  
-In all cases, evaluation is the same - a single object is considered by the compiler, evaluated, and its result returned. If an expression needs to be compiled, it will be. There is no separate compilation step, nor any need to worry that a function you have defined is being interpreted. *Clojure has no interpreter*.
216  
-
217  
-Strings, numbers, characters, `nil` and keywords evaluate to themselves.
218  
-
219  
-A Symbol is *resolved*:
220  
-
221  
-*	If it is namespace-qualified, the value is the value of the binding of the global var named by the symbol. It is an error if there is no global var named by the symbol.
222  
-*	Else, it is not namespace-qualified and the first of the following applies:
223  
- 	1. If it names a special form it is considered a special form, and must be utilized accordingly.
224  
-	2. A lookup is done in the \*imports\* map to see if there is a mapping from the symbol to a fully qualified class name. If so, the symbol is considered to name a Java class. Note that class names are not first-class objects and are only valid in certain special forms.
225  
-	3. If in a local scope (i.e. in a function definition), a lookup is done to see if it names a local binding (e.g. a function argument or let-bound name). If so, the value is the value of the local binding.
226  
-	4. A lookup is done in the \*refers\* map to see if there is a mapping from the symbol to a global var. If so, the value is the value of the binding of the global var referred-to by the symbol.
227  
-	5. A lookup is done to see if there is a global var with a namespace equal to the `*current-namespace*` and the same name as the symbol. If so, the value is the value of the binding of that global var.
228  
-	6. It is an error.
229  
-	
230  
-If a Symbol has metadata, it may be used by the compiler, but will not be part of the resulting value.
231  
-
232  
-Vectors and Maps yield vectors and (hash) maps whose contents are the *evaluated values* of the objects they contain. The same is true of metadata maps. If the vector or map has metadata, the *evaluated* metadata map will become the metadata of the resulting value.
233  
-
234  
-<pre><code>
235  
-user=> (def x 1)
236  
-user=> (def y 2)
237  
-user=> #^{:x x} [x y 3]
238  
-
239  
-#^{:x 1} [1 2 3]
240  
-</code></pre>	
241  
-
242  
-An empty list `()` evaluates to an empty list.
243  
-
244  
-Non-empty Lists are considered *calls* to either special forms, macros, or functions. A call has the form `(operator operands*)`. 
245  
-
246  
-Special forms are primitives built-in to Clojure that perform core operations. If the operator of a call is a symbol that resolves to the name of a special form, the call is to that special form. Each form discussed individually under [Special Forms](#specialforms).
247  
-
248  
-[Macros](#macros) are functions that manipulate forms, allowing for syntactic abstraction. If the operator of a call is a symbol that names a global var that is a macro function, that macro function is called and is passed the *unevaluated* operand forms. The return value of the macro is then evaluated in its place.
249  
-
250  
-If the operator is not a special form or macro, the call is considered a function call. Both the operator and the operands (if any) are evaluated, from left to right. The result of the evaluation of the operator is then cast to IFn (the interface representing Clojure functions), and invoke() is called on it, passing the evaluated arguments. The return value of invoke() is the value of the call expression. If the function call form has metadata, it may be used by the compiler, but will not be part of the resulting value.
251  
-
252  
-Note that special forms and macros might have other-than-normal evaluation of their arguments, as described in their entries under [Special Forms](#specialforms).
253  
-
254  
-The above describes the evaluation of a single form. `load` and `load-file` will sequentially evaluate the set of forms contained in the stream/file. Such sets of forms usually have side effects, often on the global environment, defining functions etc. The loading functions occur in a temporary context, in which `*current-namespace*` has a fresh binding. That means that, should any form have an effect on that var (e.g. `in-namespace), the effect will unwind at the completion of the load. 
255  
-
256  
-<h2 id="specialforms">Special Forms</h2>
257  
-
258  
----
259  
-### (*def* symbol init?)
260  
-Creates or locates a global var with the name of `symbol` and a namespace of the value of `*current-namespace*`. If `init` is supplied, it is evaluated, and the root binding of the var is set to the resulting value. If `init` is not supplied, the root binding of the var is unaffected. `def` always applies to the root binding, even if the var is thread-bound at the point where def is called. `def` yields the var itself *(not its value)*. Throws an exception if symbol is in the `*refers*` map.
261  
-
262  
----
263  
-### (*if* test then else?)
264  
-Evaluates `test`. If not nil, evaluates and yields `then`, otherwise, evaluates and yields `else`. If `else` is not supplied it defaults to `nil`.
265  
-
266  
----
267  
-### (*do* exprs*)
268  
-Evaluates the expressions in order and returns the value of the last. If no expressions are supplied, returns `nil`.
269  
-
270  
----
271  
-### (*let* [bindings* ] exprs*)
272  
-binding => symbol init-expr
273  
-
274  
-Evaluates the exprs in a context in which the symbols are bound to their respective init-exprs. The bindings are sequential, so each binding can see the prior bindings. The exprs are contained in an implicit `do`. If a binding symbol is annotated with a metadata tag, the compiler will try to resolve the tag to a class name and presume that type in subsequent references to the binding.
275  
-
276  
-<pre><code>
277  
-user=> (let [x 1 y x] y)
278  
-
279  
-1
280  
-</code></pre>	
281  
-
282  
----
283  
-### (*quote* form)
284  
-Yields the unevaluated form.
285  
-
286  
-<pre><code>
287  
-user=> '(a b c)
288  
-
289  
-(a b c)
290  
-</code></pre>
291  
-
292  
-Note there is no attempt made to call the function `a`. The return value is a list of 3 symbols.
293  
-
294  
----
295  
-### (*the-var* symbol)
296  
-The symbol must resolve to a var, and the Var object itself *(not its value)* is returned.
297  
-
298  
----
299  
-### (*fn* [params* ] exprs*)
300  
-### (*fn* ([params* ] exprs*)+)
301  
-params => positional-params* , or positional-params* `&` rest-param
302  
-
303  
-positional-param => symbol
304  
-
305  
-rest-param => symbol
306  
-
307  
-Defines a function (fn). Fns are first-class objects that implement the IFn interface. The IFn interface defines an invoke() function that is overloaded with arity ranging from 0-20. A single fn object can implement one or more invoke methods, and thus be overloaded on arity. One and only one overload can itself be variadic, by specifying the ampersand followed by a single rest-param. Such a variadic entry point, when called with arguments that exceed the positional params, will find them in a seq contained in the rest param. If the supplied args do not exceed the positional params, the rest param will be nil.
308  
-
309  
-The first form defines a fn with a single invoke method. The second defines a fn with one or more overloaded invoke methods. The arities of the overloads must be distinct. In either case, the result of the expression is a single fn object.
310  
-
311  
-The exprs are compiled in an environment in which the params are bound to the actual arguments. The exprs are enclosed in an implicit `do`. The reserved symbol `thisfn` is bound within the function definition to the function object itself, allowing for self-calling, even in anonymous functions. If a param symbol is annotated with a metadata tag, the compiler will try to resolve the tag to a class name and presume that type in subsequent references to the binding.
312  
-
313  
-<pre><code>
314  
-(def *
315  
-  (fn ([] 1)
316  
-      ([x] x)
317  
-      ([x y] (. Num (multiply x y)))
318  
-      ([x y & more]
319  
-          (apply thisfn (this-fn x y) more))))
320  
-</code></pre>
321  
-
322  
-A fn (overload) defines a recursion point at the top of the function, with arity equal to the number of params *including the rest param, if present*. See `recur`.
323  
-
324  
-IFns are Callable.
325  
-
326  
----
327  
-### (*loop* [bindings* ] exprs*)
328  
-
329  
-`Loop` is exactly like `let`, except that it establishes a recursion point at the top of the loop, with arity equal to the number of bindings. See `recur`.
330  
-
331  
----
332  
-### (*recur* exprs*)
333  
-
334  
-Evaluates the exprs in order, then, in parallel, rebinds the bindings of the recursion point to the values of the exprs. If the recursion point was a fn method, then it rebinds the params. If the recursion point was a `loop`, then it rebinds the loop bindings. Execution then jumps back to the recursion point. The `recur` expression must match the arity of the recursion point exactly. In particular, if the recursion point was the top of a variadic fn method, there is no gathering of rest args - a single seq (or null) should be passed. `recur` in other than a tail position is an error.
335  
-
336  
-Note that `recur` is the only non-stack-consuming looping construct in Clojure. There is no tail-call optimization and the use of self-calls for looping of unknown bounds is discouraged. `recur` is functional and its use in tail-position is verified by the compiler.
337  
-
338  
-<pre><code>
339  
-(def factorial 
340  
-  (fn [n]
341  
-    (loop [cnt n acc 1]
342  
-       (if (zero? cnt)
343  
-            acc
344  
-          (recur (dec cnt) (* acc cnt))))))
345  
-</code></pre>
346  
-
347  
----
348  
-### (*.* instance-expr instanceFieldName-symbol)
349  
-### (*.* Classname-symbol staticFieldName-symbol)
350  
-### (*.* instance-expr (instanceMethodName-symbol args*))
351  
-### (*.* Classname-symbol (staticMethodName-symbol args*))
352  
-
353  
-The '.' special form is the primary access to Java. It can be considered a member-access operator, and/or read as 'in the scope of'. 
354  
-
355  
-If the first operand is a symbol that resolves to a class name, the access is considered to be to a static member of the named class. Otherwise it is presumed to be an instance member and the first argument is evaluated to produce the target object. 
356  
-
357  
-If the second operand is a symbol it is taken to be a field access - the name of the field is the name of the symbol. The value of the expression is the value of the field.
358  
-
359  
-If the second operand is a list it is taken to be a method call. The first element of the list must be a simple symbol, and the name of the method is the name of the symbol. The args, if any, are evaluated from left to right, and passed to the matching method, which is called, and its value returned. If the method has a void return type, the value of the expression will be `nil`. 
360  
-
361  
-Note that boolean return values will be turned into `nil` or non-nil, chars will become Characters, and numeric primitives will become Clojure Nums.
362  
-
363  
----
364  
-### (*new* Classname-symbol args*)
365  
-The args, if any, are evaluated from left to right, and passed to the constructor of the class named by the symbol. The constructed object is returned.
366  
-
367  
----
368  
-### (*class* Classname-symbol)
369  
-Yields the java.lang.Class object corresponding to the symbol.
370  
-
371  
----
372  
-### (*instance?* expr Classname-symbol)
373  
-Evaluates expr and tests if it is an instance of the class named by the symbol. Returns `nil` or non-nil
374  
-
375  
----
376  
-### (*throw* expr)
377  
-The expr is evaluated and thrown, therefor it should yield an instance of some derivee of Throwable.
378  
-
379  
----
380  
-### (*try-finally* expr finally-expr)
381  
-The expr is evaluated and its value returned. Before returning, normally or abnormally, the finally-expr will be evaluated for its side effects.
382  
-
383  
----
384  
-### (*set!* (. instance-expr instanceFieldName-symbol) expr)
385  
-### (*set!* (. Classname-symbol staticFieldName-symbol) expr)
386  
-### (*set!* var-symbol expr)
387  
-Assignment. 
388  
-
389  
-When the first operand is a field member access form, the assignment is to the corresponding field. If it is an instance field, the instance expr will be evaluated, then the expr.
390  
-
391  
-When the first operand is a symbol, it must resolve to a global var. The value of the var's current thread binding is set to the value of expr. Currently, it is an error to attempt to set the root binding of a var using `set!`, i.e. var assignments are thread-local.
392  
-
393  
-In all cases the value of expr is returned.
394  
-
395  
-Note - *you cannot assign to function params or local bindings. Only Java fields, Vars and Refs are mutable in Clojure*.
396  
-
397  
----
398  
-### (*monitor-enter* x)
399  
-### (*monitor-exit* x)
400  
-
401  
-These are synchronization primitives that should be avoided in user code. Use the `locking` macro.
402  
-
403  
-<h2 id="macros">Macros</h2>
404  
-Clojure has a programmatic macro system which allows the compiler to be extended by user code. Macros can be used to define syntactic constructs  which would require primitives or built-in support in other languages. Many core constructs of Clojure are not, in fact, primitives, but are normal macros. First we'll cover some of the included macros and then look at the facilities for creating your own.
405  
-
406  
----
407  
-### (*and* exprs*)
408  
-Evaluates exprs one at a time, from left to right. If a form returns `nil`, `and` returns `nil` and doesn't evaluate any of the other expressions, otherwise it returns the value of the last expr. `(and)` returns `t`.
409  
-
410  
----
411  
-### (*or* exprs*)
412  
-Evaluates exprs one at a time, from left to right. If a form returns a non-nil value, `or` returns that value and doesn't evaluate any of the other expressions, otherwise it returns `nil`. `(or)` returns `nil`.
413  
-
414  
----
415  
-### (*when* test exprs*)
416  
-Evaluates `test`. If non-nil, evaluates exprs in an implicit `do`.
417  
-
418  
----
419  
-### (*when-not* test exprs*)
420  
-Evaluates `test`. If `nil`, evaluates exprs in an implicit `do`.
421  
-
422  
----
423  
-### (*cond* test-expr-pairs*)
424  
-test-expr-pair => test expr
425  
-
426  
-`cond` takes a set of test/expr pairs. It evaluates each test one at a time. If a test returns non-nil, `cond` evaluates and returns the value of the corresponding expr and doesn't evaluate any of the other tests or exprs. `(cond)` returns `nil`. `cond ` is a succinct and readable alternative to nested `if`s.
427  
-
428  
----
429  
-### (*locking* x exprs*)
430  
-Executes exprs in an implicit `do`, while holding the monitor of x. Will release the monitor of x in all circumstances.
431  
-
432  
----
433  
-### (*..* instance-expr member+)
434  
-### (*..* Classname-symbol member+)
435  
-
436  
-member => fieldName-symbol or (instanceMethodName-symbol args*)
437  
-
438  
-Expands into a member access (.) of the first member on the first argument, followed by the next member on the result etc. For instance:
439  
- 
440  
-`(.. System (getProperties) (get "os.name"))`
441  
-
442  
-expands to:
443  
-
444  
-`(. (. System (getProperties)) (get "os.name"))`
445  
-
446  
-but is easier to write, read, and understand.
447  
-
448  
----
449  
-### (*defn* name [params* ] exprs*)
450  
-### (*defn* name ([params* ] exprs*)+)
451  
-Same as `(def name (fn [params* ] exprs*))` or  `(def name (fn ([params* ] exprs*)+))`
452  
-
453  
----
454  
-### (*defmacro* name [params* ] exprs*)
455  
-### (*defmacro* name ([params* ] exprs*)+)
456  
-Like defn, but the resulting function name is declared as a macro and will be used as a macro by the compiler when it is called.
457  
-
458  
-<h2 id="other">Other Useful Functions</h2>
459  
-
460  
----
461  
-### (*apply* f args* argseq)
462  
-Applies fn f to the argument list formed by prepending args to argseq.
463  
-
464  
----
465  
-### (*appl* f args+)
466  
-Takes a function f and fewer than the normal arguments to f, and returns a fn that takes a variable number of additional args. When called, the returned function calls f with args + additional args.
467  
-
468  
-<pre><code>
469  
-
470  
-user=> (map (appl + 2) [1 2 3])
471  
-(3 4 5)
472  
-
473  
-</code></pre>
474  
-
475  
----
476  
-### (*comp* fns+)
477  
-
478  
-Takes a set of functions and returns a fn that is the composition of those fns. The returned fn takes a variable number of args, applies the rightmost of fns to the args, the next fn (right-to-left) to the result, etc.
479  
-
480  
-((comp a b c) x y z)  ==> (a (b (c x y z))) 
481  
-
482  
----
483  
-### (*nil?* x)
484  
-### (*not* x)
485  
-
486  
-Returns non-nil if x is nil.
487  
-
488  
----
489  
-### (*complement* f)
490  
-Takes a fn `f` and returns a fn that takes the same arguments as f, has the same effects, if any, and returns the opposite truth value.
491  
-
492  
----
493  
-### (*constantly* x)
494  
-Returns a function that takes any number of arguments and returns x.
495  
-
496  
----
497  
-### (*identity* x)
498  
-Returns x.
499  
-
500  
----
501  
-### (*str* x)
502  
-
503  
-Returns x.toString()
504  
-
505  
----
506  
-### (*strcat* x y)
507  
-
508  
-Returns x.concat(y)
509  
-
510  
-
511  
-<h2 id="datastructures">Data Structures</h2>
512  
-
513  
-Clojure has a rich set of data structures. They share a set of properties:
514  
-
515  
-*	They are immutable
516  
-*	They are read-able
517  
-*	They support proper equality semantics in their implementation of `equals` 
518  
-*	In addition, the collections: 
519  
-	*	Are manipulated via interfaces.
520  
-	*	Support sequencing
521  
-	*	Support persistent manipulation.
522  
-	*	Support metadata
523  
-	*	Implement Iterable
524  
-
525  
----
526  
-### (*eql?* obj1 obj2)
527  
-
528  
-Supported by all data structures.  Returns non-nil if obj1 equals obj2, `nil` if not. Same as Java `obj1.equals(obj2)` except it also works for `nil`.
529  
-
530  
-
531  
-### _nil_
532  
-`nil` is a possible value of any data type in Clojure (since primitives are always boxed). `nil` has the same value as Java `null`. The Clojure conditional system is based around `nil`/non-nil, with `nil` representing the value of logical false in conditional tests - anything else is logical true. In addition, `nil` is used as the end-of-sequence sentinel value in the sequence protocol.
533  
-
534  
-### _Nums_
535  
-All Clojure numbers are derived from clojure.lang.Num, which in turn is derived from java.lang.Number. There are 4 types:
536  
-
537  
-* 	FixNum
538  
-	
539  
-	Represent integer values that fit in 32 bits. When arithmetic involving FixNums exceeds their capacity, they automatically become BigNums.
540  
-	
541  
-*	BigNum
542  
-
543  
-	Represent integers of arbitrary precision.
544  
-	
545  
-*	DoubleNum
546  
-
547  
-	Correspond to Java's `double`.
548  
-	
549  
-*	RatioNum
550  
-
551  
-	Represents a ratio between integers. Division of integers that can't be reduced to an integer yields a ratio, i.e. 22/7 = 22/7, rather than a floating point value.
552  
-	
553  
-Any numeric operation involving DoubleNums yields a DoubleNum. 
554  
-
555  
----
556  
-### (*+* nums*)
557  
-Returns the sum of nums. `(+)` returns 0.
558  
-
559  
----
560  
-### (*\** nums*)
561  
-Returns the product of nums. `(*)` returns 1.
562  
-
563  
----
564  
-### (*/* numerator denominators*)
565  
-If no denominators are supplied, returns 1/numerator, else returns numerator divided by all of the denominators.
566  
-
567  
----
568  
-### (*-* num subs*)
569  
-If no subs are supplied, returns the negation of num, else subtracts of the subs from num and returns the result.
570  
-
571  
----
572  
-### (*==* nums+)
573  
-Returns non-nil if nums all have the same value, otherwise `nil`.
574  
-
575  
-<pre><code>
576  
-
577  
-user=> (== 1 1.0)
578  
-t
579  
-user=> (eql? 1 1.0)
580  
-nil
581  
-
582  
-</code></pre>
583  
----
584  
-### (*<* nums+)
585  
-Returns non-nil if nums are in monotonically increasing order, otherwise `nil`.
586  
-
587  
----
588  
-### (*<=* nums+)
589  
-Returns non-nil if nums are in monotonically non-decreasing order, otherwise `nil`.
590  
-
591  
----
592  
-### (*>* nums+)
593  
-Returns non-nil if nums are in monotonically decreasing order, otherwise `nil`.
594  
-
595  
----
596  
-### (*>=* nums+)
597  
-Returns non-nil if nums are in monotonically non-increasing order, otherwise `nil`.
598  
-
599  
----
600  
-### (*inc* num)
601  
-Returns a number one greater than num.
602  
-
603  
----
604  
-### (*dec* num)
605  
-Returns a number one less than num.
606  
-
607  
----
608  
-### (*zero?* num)
609  
-Returns non-nil if num is zero, else `nil`
610  
-
611  
----
612  
-### (*pos?* num)
613  
-Returns non-nil if num is greater than zero, else `nil`
614  
-
615  
----
616  
-### (*neg?* num)
617  
-Returns non-nil if num is less than zero, else `nil`
618  
-
619  
-### _Strings_
620  
-Clojure strings are Java `Strings`.
621  
-
622  
-### _Characters_
623  
-Clojure characters are Java `Characters`.
624  
-
625  
-### _Keywords_
626  
-Keywords are symbolic identifiers that evaluate to themselves. They provide very fast equality tests. Like Symbols, they have names and optional [namespaces](#namespaces), both of which are strings. The leading ':' is not part of the namespace or name. Keywords implement IFn, for invoke() of one argument, which they expect to be a map, in which they look themselves up, i.e. keywords are functions of maps.
627  
-
628  
-
629  
-
630  
-### _Symbols_
631  
-Symbols are identifiers that are normally used to refer to something else. They can be used in program forms to refer to function parameters, let bindings, class names and global vars. They have names and optional [namespaces](#namespaces), both of which are strings. Symbols can have metadata.
632  
-
633  
----
634  
-### (*gensym* prefix?)
635  
-
636  
-Returns a new symbol with a unique name. If a prefix string is supplied, the name is prefix__# where # is some unique number. If prefix is not supplied, the prefix is "G".
637  
-
638  
-### _Collections_
639  
-
640  
-All of the Clojure collections are immutable and [persistent][pd]. In particular, the Clojure collections support efficient creation of 'modified' versions, by utilizing structural sharing, and make all of their performance bound guarantees for persistent use. The collections are efficient and inherently thread-safe. Collections are represented by abstractions, and there may be one or more concrete realizations. In particular, since 'modification' operations yield new collections, the new collection might not have the same concrete type as the source collection, but will have the same logical (interface) type. All the collections support these functions:
641  
-
642  
----
643  
-### (*count* coll)
644  
-Returns the number of items in the collection. `(count nil)` returns `0`.
645  
-
646  
----
647  
-### (*conj* coll item)
648  
-Conj[oin]. Returns a *new* collection with the item 'added'. `(conj nil item)` returns `(item)`. The 'addition' may happen at different 'places' depending on the concrete type.
649  
-
650  
----
651  
-### (*seq* coll)
652  
-Sequence. Returns a new ISeq on the collection. If the collection is empty, returns `nil`. `(seq nil)` returns `nil`. `seq` also works on native Java arrays and any objects that implement Iterable.
653  
-
654  
-
655  
-### _Lists (IPersistentList)_
656  
-Lists are collections. They implement the ISeq interface directly. `count` is O(1). `conj` puts the item at the front of the list. In addition, lists support the functions:
657  
-
658  
----
659  
-### (*list*  items*)
660  
-Creates a new list containing the items.
661  
-
662  
----
663  
-### (*list** items* seq)
664  
-Creates a new list containing the items prepended to seq.
665  
-
666  
----
667  
-### (*peek* list)
668  
-Same as `first`. Returns the first item in the list. If the list is empty, returns `nil`.
669  
-
670  
----
671  
-### (*pop* list)
672  
-Returns a new list without the first item. If the list is empty, throws an exception. Note - *not* the same as `rest`.
673  
-
674  
-### _Vectors (IPersistentVector)_
675  
-Vectors are collections. They are sequences of values indexed by contiguous integers. Vectors support O(log<sub>32</sub>N) access to items by index. `count` is O(1). `conj` puts the item at the end of the vector. Vectors also support `rseq`, which returns the items in reverse order. Vectors implement IFn, for invoke() of one argument, which they presume is an index and look up in themselves as if by `nth`, i.e. vectors are functions of their indices.  In addition, vectors support the functions:
676  
-
677  
----
678  
-### (*vector* items*)
679  
-Creates a new vector containing the items.
680  
-
681  
----
682  
-### (*assoc* vector index val)
683  
-Assoc[iate]. Returns a new vector that contains val at index. Note - index must be <= (count vector).
684  
-
685  
----
686  
-### (*get* vector index)
687  
-### (*nth* vector index)
688  
-Returns the value at the index. `get` returns `nil` if index out of bounds, `nth` throws an exception. `nth` also works for Java arrays, and, in O(n) time, for sequences.
689  
-
690  
----
691  
-### (*peek* vector)
692  
-Returns the last item in the vector. If the vector is empty, returns `nil`.
693  
-
694  
----
695  
-### (*pop* vector)
696  
-Returns a new vector without the last item. If the vector is empty, throws an exception.
697  
-		
698  
-### _Maps_ (IPersistentMap)
699  
-
700  
-Map keys to values. Two different map types are provided - hashed and sorted. Hash maps require keys that correctly support hashCode and equals. Sorted maps require keys that implement Comparable, or an instance of Comparator. Hash maps provide faster access O(log<sub>32</sub>N) vs O(logN), but sorted maps are, well, sorted. `count` is O(1). `conj` expects another (possibly single entry) map as the item, and returns a new map which is the old map plus the entries from the new, which may overwrite entries of the old. `seq` returns a sequence of map entries, which are key/value pairs. Sorted map also supports `rseq`, which returns the entries in reverse order. Maps implement IFn, for invoke() of one argument, which they presume is a key and look up in themselves, i.e. maps are functions of their keys. `nil` keys and values are ok. 
701  
-
702  
-Map functions:
703  
-
704  
----
705  
-### (*hash-map* keyvals*)
706  
-### (*sorted-map* keyvals*)
707  
-### (*sorted-map-by* comparator keyvals*)
708  
-
709  
-keyval => key val
710  
-
711  
-Returns a new hash/sorted map with supplied mappings.
712  
-
713  
----
714  
-### (*assoc* map key val)
715  
-Assoc[iate]. Returns a new map of the same (hashed/sorted) type, that contains the mapping of key to val.
716  
-
717  
----
718  
-### (*dissoc* map key)
719  
-Dissoc[iate]. Returns a new map of the same (hashed/sorted) type, that does not contain a mapping for key.
720  
-
721  
----
722  
-### (*get* map key)
723  
-Returns the value mapped to key, or `nil` if key not present.
724  
-
725  
----
726  
-### (*contains* map key)
727  
-Returns `nil` if key not present, else non-nil.
728  
-
729  
----
730  
-### (*find* map key)
731  
-Returns the map entry for key, or `nil` if key not present.
732  
-
733  
----
734  
-### (*keys* map)
735  
-Returns a sequence of the map's keys.
736  
-
737  
----
738  
-### (*vals* map)
739  
-Returns a sequence of the map's values.
740  
-
741  
----
742  
-### (*merge* maps+)
743  
-Returns a map that consists of the rest of the maps conj-ed onto the first. If a key occurs in more than one map, the mapping from the latter (left-to-right) will be the mapping in the result.
744  
-
745  
-<h2 id="sequences">Sequences</h2>
746  
-
747  
-Clojure defines many algorithms in terms of sequences (seqs). A seq is a logical list, and unlike most Lisps where the list is represented by a concrete, 2-slot structure, Clojure uses the ISeq interface to allow many data structures to provide access to their elements as sequences. The `seq` function yields an implementation of ISeq appropriate to the collection. Seqs differ from iterators in that they are persistent and immutable, not stateful cursors into a collection. As such, they are useful for much more than foreach - functions can consume and produce seqs, they are thread safe, they can share structure etc. 
748  
-
749  
-Most of the sequence library functions are *lazy*, i.e. functions that return seqs do so incrementally, as they are consumed, and thus consume any seq arguments incrementally as well.
750  
-
751  
-When `seq` is used on native Java arrays and objects that implement Iterable, the resulting sequence is still immutable and persistent, and will represent a single pass across the data. Because that pass might happen lazily, the pass might see changes that happen after `seq` has been called. Also, if the backing iterator is subject to ConcurrentModificationException, then so to is the resulting seq. That said, there is still a lot of utility to using seq on Iterables and arrays - since seqs support multi-pass and lazy algorithms. Robust programs should not mutate arrays or Iterables that have seqs on them.
752  
-
753  
-####The Seq interface:
754  
-
755  
----
756  
-### (*first* seq)
757  
-Returns the first item in the sequence. Is seq is `nil`, returns `nil`.
758  
-
759  
----
760  
-### (*rest* seq)
761  
-Returns a seq of the items after the first. If there are no more items, returns `nil`.
762  
-
763  
----
764  
-### (*cons* item coll)
765  
-Returns a new seq where item is the first element and the sequence of items in coll is the rest of the seq.
766  
-
767  
-####The Seq library:
768  
-
769  
----
770  
-### (every pred seq)
771  
-### (not-every pred seq)
772  
-### (any pred seq)
773  
-### (not-any pred seq)
774  
-### (concat seqs*)
775  
-### (map f seqs*)
776  
-### (mapcat f seqs*)
777  
-### (reduce f seq)
778  
-### (reduce f seq val)
779  
-### (filter pred seq)
780  
-### (take n seq)
781  
-### (take-while pred seq)
782  
-### (drop n seq)
783  
-### (drop-while pred seq)
784  
-### (reverse seq)
785  
-### (cycle seq)
786  
-### (split-at n seq)
787  
-### (split-with pred seq)
788  
-### (repeat x)
789  
-### (replicate n x)
790  
-### (iterate f x)	
791  
-
792  
-<h2 id="metadata">Metadata</h2>
793  
-
794  
-Symbols and collections support metadata, a map of data *about* the symbol or collection. The metadata system allows for arbitrary annotation of data. It is used to convey information to the compiler about types, but can also be used by application developers for many purposes, annotating data sources, policy etc.
795  
-
796  
-An important thing to understand about metadata is that it is not considered to be part of the value of an object. As such, *metadata does not impact equality (or hash codes)*. Two objects that differ only in metadata are equal.
797  
-
798  
-That said, metadata and its relationship to an object is immutable - an object with different metadata is a different object.
799  
-
800  
----
801  
-### (*meta* obj)
802  
-### ^obj
803  
-Returns the metadata of obj, returns `nil` if there is no metadata.
804  
-
805  
----
806  
-### (*with-meta* obj map)
807  
-Returns an object of the same type and value as obj, with map as its metadata.
808  
-
809  
-
810  
-<h2 id="namespaces">Namespaces</h2>
811  
-
812  
-Symbols and keywords are two-part identifiers - with an optional namespace and a name, both strings. Namespaces are used to distinguish two symbols that have the same name. Vars are named by symbols that must have a namespace part, and thus can be considered to be in namespaces. Note that namespaces are not first-class - they are not collections of symbols/vars sharing the same prefix, they cannot be enumerated etc. Essentially, namespaces just allow simpler identifiers to be used in contexts where a namespace is either not required (fn params and let-locals) or can be inferred. Namespaces do have 2 concrete properties, `*imports*` and `*refers*`, described below, which create a lookup context associated with a namespace.
813  
-
814  
-As we've seen, all `def`s create vars in the current namespace. The `*current-namespace*` can and should be set only with a call to `in-namespace`.  `in-namespace` will set `*current-namespace*` to the supplied symbol, and will set up the bindings to the `*refers*` and `*imports*` vars. There are `*refers*` and `*imports*` in each namespace, and `in-namespace` will create them if they don't already exist. `*refers*` is a map from simple symbols to Vars, and its initial value consists of the symbols exported from the `clojure` namespace. `*imports*` is a map from simple symbols to fully-qualified classnames, and its initial value is the classes from the `java.lang` package.
815  
-Mappings can be added to `*refers*` with `refer`, and to `*imports*` with `import`, and only via those functions.
816  
-
817  
----
818  
-### (*in-namespace* ns-symbol)
819  
-Sets `*current-namespace*` to the supplied symbol, and will set up the bindings to the `*refers*` and `*imports*` vars, creating them if they don't already exist.
820  
-
821  
----
822  
-### (*import* import-lists+)
823  
-
824  
-import-list => (package-symbol class-name-symbols*)
825  
-
826  
-For each name in class-name-symbols, adds a mapping from `name` to "package.name" to the `*imports*` map of the current namespace.
827  
-
828  
-<pre><code>
829  
-(import '(java.util Date Timer Random)
830  
-        '(java.sql Connection Statement))
831  
-</code></pre>
832  
-  
833  
----
834  
-### (*unimport* symbols+)
835  
-
836  
-Removes the mappings from the `*imports*` map of the current namespace.
837  
-
838  
-<pre><code>
839  
-(unimport 'Date 'Statement)
840  
-</code></pre>
841  
-
842  
----
843  
-### (*refer* refer-lists+)
844  
-
845  
-refer-list => (ns-symbol name-symbols*)
846  
-
847  
-For each name in name-symbols, adds a mapping from `name` to the var named ns/name to the `*refers*` map of the current namespace. The vars must exist. Throws an exception if name is already in `*refers*` mapped to a different var.
848  
-
849  
-<pre><code>
850  
-(refer '(fred-ns ricky lucy ethel)
851  
-       '(barney-ns wilma fred betty))
852  
-</code></pre>
853  
-  
854  
----
855  
-### (*unrefer* symbols+)
856  
-
857  
-Removes the mappings from the `*refers*` map of the current namespace.
858  
-
859  
----
860  
-### (*name* symbol-or-keyword)
861  
-Returns the name String.
862  
-
863  
----
864  
-### (*namespace* symbol-or-keyword)
865  
-Returns the namespace String or `nil` if not present.
866  
-
867  
-<h2 id="vars">Vars and the Global Environment</h2>
868  
-Clojure is a practical language that recognizes the occasional need to maintain a persistent reference to a changing value and provides 2 distinct mechanisms for doing so in a controlled manner - Vars and [Refs](*refs). Vars provide a mechanism to refer to a mutable storage location that can be dynamically rebound (to a new storage location) on a per-thread basis. Every Var can (but needn't) have a root binding, which is a binding that is shared by all threads that do not have a per-thread binding. Thus, the value of a Var is the value of its per-thread binding, or, if it is not bound in the thread requesting the value, the value of the root binding, if any.
869  
-
870  
-The special form `def` creates (and [interns](#interning)) a Var. If the Var did not already exist and no initial value is supplied, the var is unbound:
871  
-
872  
-<pre><code>
873  
-	
874  
-user=> (def x)
875  
-Var: user/x
876  
-user=> x
877  
-java.lang.IllegalStateException: Var user/x is unbound.
878  
-
879  
-</code></pre>
880  
-
881  
-Supplying an initial value binds the root (even if it was already bound).
882  
-
883  
-<pre><code>
884  
-	
885  
-user=> (def x 1)
886  
-Var: user/x
887  
-user=> x
888  
-1
889  
-
890  
-</code></pre>
891  
-
892  
-Per-thread bindings for one or more Vars can be established via the macro `binding`:
893  
-
894  
----
895  
-### (*binding* [bindings* ] exprs*) - Macro
896  
-binding => var-symbol init-expr
897  
-
898  
-Creates new bindings for the (*already-existing*) vars, with the supplied initial values, executes the exprs in an implicit `do`, then re-establishes the bindings that existed before. 
899  
-
900  
-Thus within-thread bindings obey a stack discipline:
901  
-
902  
-<pre><code>
903  
-	
904  
-user=> (def x 1)
905  
-user=> (def y 1)
906  
-user=> (+ x y)
907  
-2
908  
-user=> (binding [x 2 y 3] 
909  
-         (+ x y))
910  
-5
911  
-user=> (+ x y)
912  
-2
913  
-
914  
-</code></pre>
915  
-
916  
-Bindings created with `binding` cannot be seen by any other thread. Bindings created with `binding` can be assigned to, which provides a means for nested contexts to communicate with code before it the call stack.
917  
-
918  
-Functions defined with `defn` are stored in Vars, allowing for the re-definition of functions in a running program. This also enables many of the possibilities of aspect- or context-oriented programming. For instance, you could wrap a function with logging behavior only in certain call contexts or threads. 
919  
-
920  
-<h3 id="interning">Interning</h3>
921  
-	
922  
-The Var system maintains a global map of (namespace-qualified) symbols to Var objects. If a `def` expression does not find an entry in this map for the symbol being `def`-ed, it creates one, otherwise, it uses the existing Var. This find-or-create process is called interning. This means is that, unless they have been `unintern`-ed, Var objects are stable references, and need not be looked up every time. It also means that the Var map constitutes a global environment, in which, as described in [Evaluation](#evaluation), the compiler attempts to resolve all free symbols as Vars.
923  
-
924  
----
925  
-### (*find-var* varsym)
926  
-
927  
-Returns the global var named by the namespace-qualified symbol, or `nil` if not var with that name.
928  
-
929  
----
930  
-### (*unintern* varsym)
931  
-
932  
-Removes the global var named by the namespace-qualified symbol from the global namespace.
933  
-
934  
- 
935  
-<h2 id="refs">Refs and Transactions</h2>
936  
-While Vars ensure safe use of mutable mutable storage locations via thread isolation, Refs ensure safe *shared* use of mutable storage locations via a [software transactional memory][stm] (STM) system. Refs are bound to a single storage location for their lifetime, and only allow reference to<sup>*</sup>, and mutation of, that location to occur within a transaction.
937  
-
938  
-<sup>*</sup>(except the `deref!` function, which yields the current value of a Ref outside of a transaction)
939  
-
940  
-Clojure transactions should be easy to understand if you've ever used database transactions - they ensure that all actions on Refs are atomic and isolated. Atomic means that every change to Refs made within a transaction occurs or none do. Isolated means that no transaction sees the effects of any other transaction while it is running. Another feature common to STMs is that, should a transaction have a conflict while running, it is automatically retried.
941  
-
942  
-There are many ways to do STMs (locking/pessimistic, lock-free/optimistic and hybrids) and it is still a research problem. The Clojure STM is, I think, novel in its use of [multiversion concurrency control][mvcc] with adaptive history queues for [snapshot isolation][snapshot], and providing a distinct `commute` operation.
943  
-
944  
-In practice, this means:
945  
-
946  
-1.	All reads of Refs will see a consistent snapshot of the 'Ref world' as of the starting point of the transaction (its 'read point'). The transaction *will* see any changes it has made. This is called the *in-transaction-value*.
947  
-
948  
-2.	All changes made to Refs during a transaction (via `set` or `commute`) will appear to occur at a single point in the 'Ref world' timeline (its 'write point').
949  
-
950  
-3.	No changes will have been made by any other transactions to any Refs that have been `set` by this transaction.
951  
-
952  
-4.	Changes *may have* been made by other transactions to any Refs that have been `commute`d by this transaction. That should be okay since the function applied by `commute` should be commutative.
953  
-
954  
-5.	Readers and commuters will never block writers, commuters, or other readers.
955  
-
956  
-6.	Writers will never block commuters, or readers.
957  
-
958  
-7.	I/O and other activities with side-effects should be avoided in transactions, since transactions *will* be retried.
959  
-
960  
-8.	If a constraint on the validity of a value of a Ref that is being changed depends upon the simultaneous value of a Ref that is *not being changed*, that second Ref can be protected from modification by calling `set` without a second argument. Refs 'set' this way will be protected (item #3), but don't change the world (item #2).
961  
-
962  
-9.	The Clojure MVCC STM is designed to work with the persistent collections, and it is strongly recommended that you use the Clojure collections as the values of your Refs. Since all work done in an STM transaction is speculative, it is imperative that there be a low cost to making copies and modifications. Persistent collections have free copies (just use the original, it can't be changed), and 'modifications' share structure efficiently. In any case:
963  
-
964  
-10.	The values placed in Refs *must be, or be considered, immutable*!! Otherwise, Clojure can't help you.
965  
-
966  
-[mvcc]:     http://en.wikipedia.org/wiki/Multiversion_concurrency_control
967  
-[snapshot]: http://en.wikipedia.org/wiki/Snapshot_isolation
968  
-
969  
----
970  
-### (*ref* init-val)
971  
-Creates and returns a Ref with an initial value of `init-val`.
972  
-
973  
----
974  
-### (*sync* transaction-flags exprs*) - Macro
975  
-transaction-flags => TBD, pass `nil` for now
976  
-
977  
-Runs the exprs (in an implicit `do`) in a transaction that encompasses exprs and any nested calls. Starts a transaction if none is already running on this thread. Any uncaught exception will abort the transaction and flow out of `sync`. The exprs may be run more than once, but any effects on Refs will be atomic.
978  
-
979  
----
980  
-### (*deref* ref)
981  
-### @ref
982  
-
983  
-Must be called in a transaction. Returns the in-transaction-value of ref.
984  
-
985  
-### (*deref!* ref)
986  
-### @!ref
987  
-
988  
-May be called outside a transaction. Returns the most-recently-committed value of ref.
989  
-
990  
----
991  
-### (*set* ref)
992  
-Must be called in a transaction. Protects the ref from modification by other transactions. Returns the in-transaction-value of ref. Allows for more concurrency than `(set ref @ref)`
993  
-
994  
-### (*set* ref val)
995  
-Must be called in a transaction. Sets the value of ref. Returns val.
996  
-
997  
----
998  
-### (*commute* ref fun)
999  
-Must be called in a transaction. Sets the in-transaction-value of ref to:
1000  
-
1001  
- `(fun in-transaction-value-of-ref)`
1002  
-
1003  
-At the commit point of the transaction, sets the value of ref to be: 
1004  
-
1005  
-`(fun most-recently-committed-value-of-ref)`
1006  
-
1007  
-Thus `fun` should be commutative, or, failing that, you must accept last-one-in-wins behavior. `commute` allows for more concurrency than `set`.
1008  
-
1009  
-<h2 id="lisp">Differences with other Lisps</h2>
1010  
-This information is provided for programmers familiar with Common Lisp or Scheme.
1011  
- 
1012  
-* Clojure is case sensitive
1013  
-* Clojure is a Lisp-1
1014  
-* () is not the same as nil
1015  
-* The reader is side-effect free
1016  
-* Keywords are not Symbols
1017  
-* Symbols are not storage locations (see Var)
1018  
-* `nil` is not a Symbol
1019  
-* The read table is currently not accessible to user programs
1020  
-* `let` binds sequentially
1021  
-* `do` is not a looping construct
1022  
-* There is no tail-call optimization, use `recur`.
1023  
-* syntax-quote does symbol resolution, so \`x is not the same as 'x. 
1024  
-* \` has auto-gensyms.
1025  
-* ~ is unquote ',' is whitespace
1026  
-* There is reader syntax for maps and vectors
1027  
-* `cons`, `first` and `rest` manipulate sequence abstractions, not concrete cons cells
1028  
-* Most data structures are immutable
1029  
-* lambda is fn, and supports overloading by arity
1030  
-* eql? is the equality predicate
1031  
-* All Vars can be dynamically rebound, no `special` declaration. Since Clojure is a Lisp-1, functions can be dynamically rebound.
1032  
-
1033  
-<a href="http://sourceforge.net"><img src="http://sflogo.sourceforge.net/sflogo.php?group_id=137961&amp;type=1" width="88" height="31" border="0" alt="SourceForge.net Logo" /></a>
261  epl-v10.html