Skip to content

Instantly share code, notes, and snippets.

@xitij2000
Created December 8, 2011 13:47
Show Gist options
  • Select an option

  • Save xitij2000/1447038 to your computer and use it in GitHub Desktop.

Select an option

Save xitij2000/1447038 to your computer and use it in GitHub Desktop.
ClojureScript code to print squares of first 10 numbers.
(ns example)
(defn ^:export square [n]
(for [x (range n)]
(* x x)))
(.write js/document
(reduce str
(interpose ","
(square 10))))
goog.provide('example');
goog.require('cljs.core');
example.square = (function square(n) {
var iter__378__auto____2376 = (function iter__2372(s__2373) {
return (new cljs.core.LazySeq(null, false, (function () {
var s__2373__2374 = s__2373;
while (true) {
if (cljs.core.truth_(cljs.core.seq.call(null, s__2373__2374))) {
var x__2375 = cljs.core.first.call(null, s__2373__2374);
return cljs.core.cons.call(null, (x__2375 * x__2375), iter__2372.call(null, cljs.core.rest.call(null, s__2373__2374)));
} else {
return null;
}
break;
}
})));
});
return iter__378__auto____2376.call(null, cljs.core.range.call(null, n));
});
goog.exportSymbol('example.square', example.square);
document.write(cljs.core.reduce.call(null, cljs.core.str, cljs.core.interpose.call(null, ",", example.square.call(null, 10))));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment