summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2008-10-04 21:16:00 +0000
committerRich Hickey <richhickey@gmail.com>2008-10-04 21:16:00 +0000
commit75dcef321baeb94e4d35036fb7a7805e6350e662 (patch)
tree99addcd5ffe740059e447bdaee01e86aa01c6ca1
parent2394b54131cb9c7f64176b354c75a98f066ffd73 (diff)
improved error on malformed let
-rw-r--r--src/clj/clojure/boot.clj19
-rw-r--r--src/jvm/clojure/lang/Compiler.java7
2 files changed, 18 insertions, 8 deletions
diff --git a/src/clj/clojure/boot.clj b/src/clj/clojure/boot.clj
index 30c8d68f..668e7ca7 100644
--- a/src/clj/clojure/boot.clj
+++ b/src/clj/clojure/boot.clj
@@ -784,6 +784,15 @@
"Bitwise shift right"
[x n] (. clojure.lang.Numbers shiftRight x n))
+(defn even?
+ "Returns true if n is even, throws an exception if n is not an integer"
+ [n] (zero? (bit-and n 1)))
+
+(defn odd?
+ "Returns true if n is odd, throws an exception if n is not an integer"
+ [n] (not (even? n)))
+
+
;;
(defn complement
@@ -2167,6 +2176,8 @@
the binding-forms are bound to their respective init-exprs or parts
therein."
[bindings & body]
+ (when (odd? (count bindings))
+ (throw (Exception. "Odd number of elements in let bindings")))
`(let* ~(destructure bindings) ~@body))
;redefine fn with destructuring
@@ -3347,14 +3358,6 @@
"Returns true if coll implements Reversible"
[coll] (instance? clojure.lang.Reversible coll))
-(defn even?
- "Returns true if n is even, throws an exception if n is not an integer"
- [n] (zero? (bit-and n 1)))
-
-(defn odd?
- "Returns true if n is odd, throws an exception if n is not an integer"
- [n] (not (even? n)))
-
(defn pmap
"Like map, except f is applied in parallel. Semi-lazy in that the
parallel computation stays ahead of the consumption, but doesn't
diff --git a/src/jvm/clojure/lang/Compiler.java b/src/jvm/clojure/lang/Compiler.java
index 6f1351cd..4b6c9ab7 100644
--- a/src/jvm/clojure/lang/Compiler.java
+++ b/src/jvm/clojure/lang/Compiler.java
@@ -3962,6 +3962,13 @@ private static Expr analyzeSeq(C context, ISeq form, String name) throws Excepti
else
return InvokeExpr.parse(context, form);
}
+ catch(Throwable e)
+ {
+ if(!(e instanceof CompilerException))
+ throw new CompilerException((String) SOURCE.get(), (Integer) LINE.get(), e);
+ else
+ throw (CompilerException) e;
+ }
finally
{
Var.popThreadBindings();