Skip to content

Commit 8c59f86

Browse files
committed
[lazy] added (optional) detection of conditional test of LazySeq, build with:
ant -Dclojure.assert-if-lazy-seq=true patch from Chouser
1 parent db27101 commit 8c59f86

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

build.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<property name="build" location="classes"/>
1212
<property name="clojure_jar" location="clojure.jar"/>
1313
<property name="slim_jar" location="clojure-slim.jar"/>
14+
<property name="clojure.assert-if-lazy-seq" value=""/>
1415

1516
<target name="init" depends="clean">
1617
<tstamp/>
@@ -28,6 +29,7 @@
2829
<java classname="clojure.lang.Compile"
2930
classpath="${build}:${cljsrc}">
3031
<sysproperty key="clojure.compile.path" value="${build}"/>
32+
<sysproperty key="clojure.assert-if-lazy-seq" value="${clojure.assert-if-lazy-seq}"/>
3133
<arg value="clojure.core"/>
3234
<arg value="clojure.main"/>
3335
<arg value="clojure.set"/>

src/clj/clojure/core.clj

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
#^{:macro true}
3636
fn (fn* fn [& decl] (cons 'fn* decl)))
3737

38+
(def
39+
#^{:macro true}
40+
if (fn* if [& decl] (cons 'if* decl)))
41+
3842
(def
3943
#^{:arglists '([coll])
4044
:doc "Returns the first item in the collection. Calls seq on its
@@ -291,6 +295,20 @@
291295

292296
(. (var defmacro) (setMacro))
293297

298+
(defmacro assert-if-lazy-seq? {:private true} []
299+
(let [prop (System/getProperty "clojure.assert-if-lazy-seq")]
300+
(if prop
301+
(if (clojure.lang.Util/equals prop "") nil true))))
302+
303+
(defmacro if [tst & etc]
304+
(if* (assert-if-lazy-seq?)
305+
(let [tstsym 'G__0_0]
306+
(list 'let [tstsym tst]
307+
(list 'if* (list 'clojure.core/instance? clojure.lang.LazySeq tstsym)
308+
(list 'throw (list 'new Exception "LazySeq used in 'if'"))
309+
(cons 'if* (cons tstsym etc)))))
310+
(cons 'if* (cons tst etc))))
311+
294312
(defmacro when
295313
"Evaluates test. If logical true, evaluates body in an implicit do."
296314
[test & body]
@@ -1642,7 +1660,7 @@
16421660
([coll]
16431661
(sort compare coll))
16441662
([#^java.util.Comparator comp coll]
1645-
(when (and coll (not (zero? (count coll))))
1663+
(when (seq coll)
16461664
(let [a (to-array coll)]
16471665
(. java.util.Arrays (sort a comp))
16481666
(seq a)))))

src/clj/clojure/core_proxy.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
meths (concat
156156
(seq (. c (getDeclaredMethods)))
157157
(seq (. c (getMethods))))]
158-
(if meths
158+
(if (seq meths)
159159
(let [#^java.lang.reflect.Method meth (first meths)
160160
mods (. meth (getModifiers))
161161
mk (method-sig meth)]

src/jvm/clojure/lang/Compiler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class Compiler implements Opcodes{
4040
static final Symbol DEF = Symbol.create("def");
4141
static final Symbol LOOP = Symbol.create("loop*");
4242
static final Symbol RECUR = Symbol.create("recur");
43-
static final Symbol IF = Symbol.create("if");
43+
static final Symbol IF = Symbol.create("if*");
4444
static final Symbol LET = Symbol.create("let*");
4545
static final Symbol DO = Symbol.create("do");
4646
static final Symbol FN = Symbol.create("fn*");

0 commit comments

Comments
 (0)