arohner / scriptjure

a Clojure library for generating javascript
187 stars 15 forks source link

document 'while' #13

Closed sneilan closed 13 years ago

sneilan commented 13 years ago

This is a slight problem. There's no way to create a loop at the moment. For now, I'll just use the quote operator:

user=> (js (quote "while (1) {") (alert "asdf") (quote "}")) "while (1) {;\nalert(\"asdf\");\n};\n"

arohner commented 13 years ago

while already works, but is apparently not documented.

sneilan commented 13 years ago

OK, I'll see if maybe I can write some documentation for that.

sneilan commented 13 years ago

Oh wow! You're right, it does work. A while loop has the same syntax as any other function, therefore you can go like this: (js (while (== a 5) (alert "asdf!"))) Which will print "while ((a == 5)) { \nalert(\"asdf\");\n\n }"

sneilan commented 13 years ago

Definitely can't write for loops without the quote operator though: user=> (js (for (var i 5) (<= i 5) (++ i))) "var i;\nfor(i = 5;\n, (i <= 5), i++)"