(symbol (js/Date))
Notice the .call(null)
We'll come back to it later...
(map inc [1 2 3])
[1,2,3].map((x) => x + 1)
[1,2,3]*10
print([x + 1 for x in range(10)])
(defn foo[] "hello")
(foo)
The code is evaluated in the browser
The readers are confident that the code executes as the author of the code claims.
Instead of:
(map inc [1 2 3])
;; returns [2 3 4]
The readers see:
(map inc [1 2 3])
BTW, do you see the bug in the non-interactive code snippet?
The code can be modified by the reader.
Now, the reader can explore the code:
dec
instead of inc
(map inc [1 2 3])
vector
(map inc [1 2 3])
list
(map inc [1 2 3])
map
instead of a vector
e.g. {:a 1 :b 2}
(map inc [1 2 3])
“Why are we doing this? Because Clojure rocks, and JavaScript reaches.” — Rich Hickey
There are a lot of tools that can host code snippets.
All of them require you (the writer and the reader) to come to them.
KLIPSE takes a different approach: it comes to you (on any web page).
cljs_in=(map inc (range 10))
static-fns=true
javascript
tag:
<link rel="stylesheet" type="text/css" href="http://app.klipse.tech/css/codemirror.css">
<script>
window.klipse_settings = {
selector: '.language-klipse'// css selector for the html elements you want to klipsify
};
</script>
<script src="http://app.klipse.tech/plugin/js/klipse_plugin.js"></script>
A live code snippet that loads code from a gist
This gist :require
code from another gist
This code runs in a loop every 3 seconds.
Here is the gist:
Here is the KLIPSE snippet with this attributes: data-loop-msec="3000" data-gist-id="viebel/08a311453c9d31378b357ced54221fb4"
:
And here is the HTML element colorized by the code snippet:
core.async
, test.check
Join the KLIPSE community:
cljs_in=
url param: demos, bug reports, questions, stackoverflow, clojurians...Dreams
/