Skip to content

Commit

Permalink
Added doseq
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoduncan authored and arohner committed May 22, 2010
1 parent bcbce5e commit 39b48e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/com/reasonr/scriptjure.clj
Expand Up @@ -65,7 +65,7 @@
(defmethod emit :default [expr]
(str expr))

(def special-forms (set ['var '. 'if 'funcall 'fn 'set! 'return 'delete 'new 'do 'aget]))
(def special-forms (set ['var '. 'if 'funcall 'fn 'set! 'return 'delete 'new 'do 'aget 'doseq]))

(def infix-operators (set ['+ '- '/ '* '% '== '=== '< '> '<= '>= '!= '<< '>> '<<< '>>> '!== '& '| '&& '||]))

Expand Down Expand Up @@ -126,6 +126,13 @@
(defmethod emit-special 'do [type [ do & exprs]]
(emit-do exprs))

(defmethod emit-special 'doseq [type [doseq bindings & body]]
(str "for (" (emit (first bindings)) " in " (second bindings) ") { \n"
(if-let [more (nnext bindings)]
(emit (list* 'doseq more body))
(emit-do body))
"\n }"))

(defn emit-function [name sig body]
(assert (or (symbol? name) (nil? name)))
(assert (vector? sig))
Expand Down
6 changes: 6 additions & 0 deletions test/test_scriptjure.clj
Expand Up @@ -73,6 +73,12 @@
(var y 4)
(+ x y))) "var x = 3; var y = 4; (x + y);")))

(deftest test-doseq
(is (= (strip-whitespace (js (doseq [i [1 2 3]] (foo i))))
"for (i in [1 2 3]) { foo(i); }"))
(is (= (strip-whitespace (js (doseq [i [1 2 3] j [4 5]] (foo i j))))
"for (i in [1 2 3]) { for (j in [4 5]) { foo(i, j); } }")))

(deftest test-combine-forms
(let [stuff (js* (do
(var x 3)
Expand Down

0 comments on commit 39b48e9

Please sign in to comment.