Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
  • 3 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Commits on Jul 26, 2010
@purcell purcell Expand lazy seqs as arrays inside clj blocks 8a02445
Commits on Aug 12, 2010
@purcell purcell Expand more than 2 args for some infix operators, e.g. (+ a b c) => "…
…(a + b + c)"

The current implementation silently drops extra arguments.
e2fa59d
@purcell purcell Merge remote branch 'arohner/master' d93398f
Showing with 9 additions and 2 deletions.
  1. +5 −1 src/com/reasonr/scriptjure.clj
  2. +4 −1 test/test_scriptjure.clj
View
6 src/com/reasonr/scriptjure.clj
@@ -75,6 +75,8 @@
(def infix-operators (set ['+ '+= '- '-= '/ '* '% '== '=== '< '> '<= '>= '!= '<< '>> '<<< '>>> '!== '& '| '&& '||]))
+(def chainable-infix-operators (set ['+ '- '* '/ '& '| '&& '||]))
+
(defn special-form? [expr]
(contains? special-forms expr))
@@ -84,7 +86,9 @@
(defn emit-infix [type [operator & args]]
(when (< (count args) 2)
(throw (Exception. "not supported yet")))
- (str "(" (emit (first args)) " " operator " " (emit (second args)) ")" ))
+ (when (and (not (chainable-infix-operators operator)) (> (count args) 2))
+ (throw (Exception. (str "operator " operator " supports only 2 arguments"))))
+ (str "(" (str/join (str " " operator " ") (map emit args)) ")"))
(defmethod emit-special 'var [type [var name expr]]
(str "var " (emit name) " = " (emit expr)))
View
5 test/test_scriptjure.clj
@@ -28,7 +28,10 @@
(is (= (js (a b c)) "a(b, c)")))
(deftest test-arithmetic
- (is (= (js (* x y)) "(x * y)")))
+ (is (= (js (* x y)) "(x * y)"))
+ (is (= (js (+ x y)) "(x + y)"))
+ (is (= (js (* x y z a b c)) "(x * y * z * a * b * c)"))
+ (is (= (js (+ x y z a b c)) "(x + y + z + a + b + c)")))
(deftest test-return
(is (= (strip-whitespace (js (return 42))) "return 42")))

No commit comments for this range

Something went wrong with that request. Please try again.