Created
December 8, 2011 13:47
-
-
Save xitij2000/1447038 to your computer and use it in GitHub Desktop.
ClojureScript code to print squares of first 10 numbers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns example) | |
| (defn ^:export square [n] | |
| (for [x (range n)] | |
| (* x x))) | |
| (.write js/document | |
| (reduce str | |
| (interpose "," | |
| (square 10)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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