Skip to content

Commit cc99a60

Browse files
author
Dimitry Gashinsky
committed
Merge branch 'master' of git://github.com/richhickey/clojure
2 parents 9e1c4bf + d910b3d commit cc99a60

File tree

19 files changed

+827
-63
lines changed

19 files changed

+827
-63
lines changed

build.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
classpath="${build}:${cljsrc}"
8989
failonerror="true">
9090
<sysproperty key="clojure.compile.path" value="${build}"/>
91+
<!-- <sysproperty key="clojure.compile.warn-on-reflection" value="true"/> -->
9192
<arg value="clojure.core"/>
9293
<arg value="clojure.main"/>
9394
<arg value="clojure.set"/>

src/clj/clojure/core.clj

Lines changed: 90 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,14 @@
357357

358358
(defn symbol
359359
"Returns a Symbol with the given namespace and name."
360+
{:tag clojure.lang.Symbol}
360361
([name] (if (symbol? name) name (clojure.lang.Symbol/intern name)))
361362
([ns name] (clojure.lang.Symbol/intern ns name)))
362363

363364
(defn keyword
364365
"Returns a Keyword with the given namespace and name. Do not use :
365366
in the keyword strings, it will be added automatically."
367+
{:tag clojure.lang.Keyword}
366368
([name] (if (keyword? name) name (clojure.lang.Keyword/intern name)))
367369
([ns name] (clojure.lang.Keyword/intern ns name)))
368370

@@ -540,10 +542,11 @@
540542

541543

542544
(defn compare
543-
"Comparator. Returns 0 if x equals y, -1 if x is logically 'less
544-
than' y, else 1. Same as Java x.compareTo(y) except it also works
545-
for nil, and compares numbers and collections in a type-independent
546-
manner. x must implement Comparable"
545+
"Comparator. Returns a negative number, zero, or a positive number
546+
when x is logically 'less than', 'equal to', or 'greater than'
547+
y. Same as Java x.compareTo(y) except it also works for nil, and
548+
compares numbers and collections in a type-independent manner. x
549+
must implement Comparable"
547550
{:tag Integer
548551
:inline (fn [x y] `(. clojure.lang.Util compare ~x ~y))}
549552
[x y] (. clojure.lang.Util (compare x y)))
@@ -1070,6 +1073,16 @@
10701073
(list form x)))
10711074
([x form & more] `(-> (-> ~x ~form) ~@more)))
10721075

1076+
(defmacro ->>
1077+
"Threads the expr through the forms. Inserts x as the
1078+
last item in the first form, making a list of it if it is not a
1079+
list already. If there are more forms, inserts the first form as the
1080+
last item in second form, etc."
1081+
([x form] (if (seq? form)
1082+
`(~(first form) ~@(next form) ~x)
1083+
(list form x)))
1084+
([x form & more] `(->> (->> ~x ~form) ~@more)))
1085+
10731086
;;multimethods
10741087
(def global-hierarchy)
10751088

@@ -1181,28 +1194,58 @@
11811194
(let [~form temp#]
11821195
~@body)))))
11831196

1197+
(defn push-thread-bindings
1198+
"WARNING: This is a low-level function. Prefer high-level macros like
1199+
binding where ever possible.
1200+
1201+
Takes a map of Var/value pairs. Binds each Var to the associated value for
1202+
the current thread. Each call *MUST* be accompanied by a matching call to
1203+
pop-thread-bindings wrapped in a try-finally!
1204+
1205+
(push-thread-bindings bindings)
1206+
(try
1207+
...
1208+
(finally
1209+
(pop-thread-bindings)))"
1210+
[bindings]
1211+
(clojure.lang.Var/pushThreadBindings bindings))
1212+
1213+
(defn pop-thread-bindings
1214+
"Pop one set of bindings pushed with push-binding before. It is an error to
1215+
pop bindings without pushing before."
1216+
[]
1217+
(clojure.lang.Var/popThreadBindings))
1218+
1219+
(defn get-thread-bindings
1220+
"Get a map with the Var/value pairs which is currently in effect for the
1221+
current thread."
1222+
[]
1223+
(clojure.lang.Var/getThreadBindings))
1224+
11841225
(defmacro binding
11851226
"binding => var-symbol init-expr
11861227
11871228
Creates new bindings for the (already-existing) vars, with the
11881229
supplied initial values, executes the exprs in an implicit do, then
1189-
re-establishes the bindings that existed before."
1230+
re-establishes the bindings that existed before. The new bindings
1231+
are made in parallel (unlike let); all init-exprs are evaluated
1232+
before the vars are bound to their new values."
11901233
[bindings & body]
1191-
(assert-args binding
1192-
(vector? bindings) "a vector for its binding"
1193-
(even? (count bindings)) "an even number of forms in binding vector")
1194-
(let [var-ize (fn [var-vals]
1195-
(loop [ret [] vvs (seq var-vals)]
1196-
(if vvs
1197-
(recur (conj (conj ret `(var ~(first vvs))) (second vvs))
1198-
(next (next vvs)))
1199-
(seq ret))))]
1200-
`(let []
1201-
(. clojure.lang.Var (pushThreadBindings (hash-map ~@(var-ize bindings))))
1202-
(try
1203-
~@body
1204-
(finally
1205-
(. clojure.lang.Var (popThreadBindings)))))))
1234+
(assert-args binding
1235+
(vector? bindings) "a vector for its binding"
1236+
(even? (count bindings)) "an even number of forms in binding vector")
1237+
(let [var-ize (fn [var-vals]
1238+
(loop [ret [] vvs (seq var-vals)]
1239+
(if vvs
1240+
(recur (conj (conj ret `(var ~(first vvs))) (second vvs))
1241+
(next (next vvs)))
1242+
(seq ret))))]
1243+
`(let []
1244+
(push-thread-bindings (hash-map ~@(var-ize bindings)))
1245+
(try
1246+
~@body
1247+
(finally
1248+
(pop-thread-bindings))))))
12061249

12071250
(defn find-var
12081251
"Returns the global var named by the namespace-qualified symbol, or
@@ -1759,6 +1802,15 @@
17591802
([s] (drop-last 1 s))
17601803
([n s] (map (fn [x _] x) s (drop n s))))
17611804

1805+
(defn take-last
1806+
"Returns a seq of the last n items in coll. Depending on the type
1807+
of coll may be no better than linear time. For vectors, see also subvec."
1808+
[n coll]
1809+
(loop [s (seq coll), lead (seq (drop n coll))]
1810+
(if lead
1811+
(recur (next s) (next lead))
1812+
s)))
1813+
17621814
(defn drop-while
17631815
"Returns a lazy sequence of the items in coll starting from the first
17641816
item for which (pred item) returns nil."
@@ -2936,7 +2988,7 @@
29362988
(conj (pop groups) (conj (peek groups) [k v]))
29372989
(conj groups [k v])))
29382990
[] (partition 2 seq-exprs)))
2939-
err (fn [& msg] (throw (IllegalArgumentException. (apply str msg))))
2991+
err (fn [& msg] (throw (IllegalArgumentException. #^String (apply str msg))))
29402992
emit-bind (fn emit-bind [[[bind expr & mod-pairs]
29412993
& [[_ next-expr] :as next-groups]]]
29422994
(let [giter (gensym "iter__")
@@ -3728,7 +3780,7 @@
37283780
(defmacro with-loading-context [& body]
37293781
`((fn loading# []
37303782
(. clojure.lang.Var (pushThreadBindings {clojure.lang.Compiler/LOADER
3731-
(-> loading# .getClass .getClassLoader)}))
3783+
(.getClassLoader (.getClass #^Object loading#))}))
37323784
(try
37333785
~@body
37343786
(finally
@@ -4403,9 +4455,9 @@
44034455
"clojure/version.properties")
44044456
properties (doto (new java.util.Properties) (.load version-stream))
44054457
prop (fn [k] (.getProperty properties (str "clojure.version." k)))
4406-
clojure-version {:major (Integer/valueOf (prop "major"))
4407-
:minor (Integer/valueOf (prop "minor"))
4408-
:incremental (Integer/valueOf (prop "incremental"))
4458+
clojure-version {:major (Integer/valueOf #^String (prop "major"))
4459+
:minor (Integer/valueOf #^String (prop "minor"))
4460+
:incremental (Integer/valueOf #^String (prop "incremental"))
44094461
:qualifier (prop "qualifier")}]
44104462
(def *clojure-version*
44114463
(if (not (= (prop "interim") "false"))
@@ -4502,6 +4554,18 @@
45024554
[#^clojure.lang.ITransientVector coll]
45034555
(.pop coll))
45044556

4557+
(defn disj!
4558+
"disj[oin]. Returns a transient set of the same (hashed/sorted) type, that
4559+
does not contain key(s)."
4560+
([set] set)
4561+
([#^clojure.lang.ITransientSet set key]
4562+
(. set (disjoin key)))
4563+
([set key & ks]
4564+
(let [ret (disj set key)]
4565+
(if ks
4566+
(recur ret (first ks) (next ks))
4567+
ret))))
4568+
45054569
;redef into with batch support
45064570
(defn into
45074571
"Returns a new coll consisting of to-coll with all of the items of
@@ -4516,3 +4580,4 @@
45164580
(if items
45174581
(recur (conj ret (first items)) (next items))
45184582
ret)))))
4583+

src/clj/clojure/core_proxy.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@
258258
pname (proxy-name super interfaces)]
259259
(or (RT/loadClassForName pname)
260260
(let [[cname bytecode] (generate-proxy super interfaces)]
261-
(. (deref clojure.lang.Compiler/LOADER) (defineClass pname bytecode))))))
261+
(. #^DynamicClassLoader (deref clojure.lang.Compiler/LOADER) (defineClass pname bytecode))))))
262262

263263
(defn construct-proxy
264264
"Takes a proxy class and any arguments for its superclass ctor and

src/clj/clojure/main.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
(defn- root-cause
9494
"Returns the initial cause of an exception or error by peeling off all of
9595
its wrappers"
96-
[throwable]
96+
[#^Throwable throwable]
9797
(loop [cause throwable]
9898
(if-let [cause (.getCause cause)]
9999
(recur cause)
@@ -161,7 +161,7 @@
161161
(let [{:keys [init need-prompt prompt flush read eval print caught]
162162
:or {init #()
163163
need-prompt (if (instance? LineNumberingPushbackReader *in*)
164-
#(.atLineStart *in*)
164+
#(.atLineStart #^LineNumberingPushbackReader *in*)
165165
#(identity true))
166166
prompt repl-prompt
167167
flush flush
@@ -203,7 +203,7 @@
203203
(defn load-script
204204
"Loads Clojure source from a file or resource given its path. Paths
205205
beginning with @ or @/ are considered relative to classpath."
206-
[path]
206+
[#^String path]
207207
(if (.startsWith path "@")
208208
(RT/loadResourceScript
209209
(.substring path (if (.startsWith path "@/") 2 1)))

src/clj/clojure/test.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ Chas Emerick, Allen Rohner, and Stuart Halloway",
505505
"Returns a vector [filename line-number] for the nth call up the
506506
stack."
507507
[n]
508-
(let [s (nth (.getStackTrace (new java.lang.Throwable)) n)]
508+
(let [#^StackTraceElement s (nth (.getStackTrace (new java.lang.Throwable)) n)]
509509
[(.getFileName s) (.getLineNumber s)]))
510510

511511
(defn testing-vars-str

src/clj/clojure/test/tap.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"Prints a TAP diagnostic line. data is a (possibly multi-line)
5252
string."
5353
[data]
54-
(doseq [line (.split data "\n")]
54+
(doseq [line (.split #^String data "\n")]
5555
(println "#" line)))
5656

5757
(defn print-tap-pass

src/clj/clojure/xml.clj

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,22 @@
2626
(assoc e :content (conj (or (:content e) []) c)))
2727
push-chars (fn []
2828
(when (and (= *state* :chars)
29-
(some (complement #(. Character (isWhitespace %))) (str *sb*)))
29+
(some (complement #(Character/isWhitespace (char %))) (str *sb*)))
3030
(set! *current* (push-content *current* (str *sb*)))))]
3131
(new clojure.lang.XMLHandler
3232
(proxy [ContentHandler] []
3333
(startElement [uri local-name q-name #^Attributes atts]
3434
(let [attrs (fn [ret i]
3535
(if (neg? i)
3636
ret
37-
(recur (assoc ret
38-
(. clojure.lang.Keyword (intern (symbol (. atts (getQName i)))))
39-
(. atts (getValue i)))
37+
(recur (assoc ret
38+
(clojure.lang.Keyword/intern (symbol (.getQName atts i)))
39+
(.getValue atts (int i)))
4040
(dec i))))
41-
e (struct element
41+
e (struct element
4242
(. clojure.lang.Keyword (intern (symbol q-name)))
43-
(when (pos? (. atts (getLength)))
44-
(attrs {} (dec (. atts (getLength))))))]
43+
(when (pos? (.getLength atts))
44+
(attrs {} (dec (.getLength atts)))))]
4545
(push-chars)
4646
(set! *stack* (conj *stack* *current*))
4747
(set! *current* e)
@@ -53,11 +53,11 @@
5353
(set! *stack* (pop *stack*))
5454
(set! *state* :between)
5555
nil)
56-
(characters [ch start length]
56+
(characters [#^chars ch start length]
5757
(when-not (= *state* :chars)
5858
(set! *sb* (new StringBuilder)))
5959
(let [#^StringBuilder sb *sb*]
60-
(. sb (append ch start length))
60+
(.append sb ch (int start) (int length))
6161
(set! *state* :chars))
6262
nil)
6363
(setDocumentLocator [locator])
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
}

0 commit comments

Comments
 (0)