aboutsummaryrefslogtreecommitdiff
path: root/imports/codemirror/mode/clojure/index.html
diff options
context:
space:
mode:
authorValerio Virgillito2012-02-14 11:07:21 -0800
committerValerio Virgillito2012-02-14 11:07:21 -0800
commitf060190a3bffd9a16718f2ce0499699103d46372 (patch)
treea308fe7eacec2156c8212dff0892a3de925d5f9a /imports/codemirror/mode/clojure/index.html
parentf766cc203f30ea43ae8b83cf4b65d45cc4435ee9 (diff)
parent33bc9d62b8e6694500bf14d5b18187bd99a520a3 (diff)
downloadninja-f060190a3bffd9a16718f2ce0499699103d46372.tar.gz
Merge branch 'FileIO' of https://github.com/joseeight/ninja-internal into integration
Diffstat (limited to 'imports/codemirror/mode/clojure/index.html')
-rwxr-xr-ximports/codemirror/mode/clojure/index.html66
1 files changed, 66 insertions, 0 deletions
diff --git a/imports/codemirror/mode/clojure/index.html b/imports/codemirror/mode/clojure/index.html
new file mode 100755
index 00000000..9762d589
--- /dev/null
+++ b/imports/codemirror/mode/clojure/index.html
@@ -0,0 +1,66 @@
1<!doctype html>
2<html>
3 <head>
4 <title>CodeMirror: Clojure mode</title>
5 <link rel="stylesheet" href="../../lib/codemirror.css">
6 <script src="../../lib/codemirror.js"></script>
7 <script src="clojure.js"></script>
8 <style>.CodeMirror {background: #f8f8f8;}</style>
9 <link rel="stylesheet" href="../../doc/docs.css">
10 </head>
11 <body>
12 <h1>CodeMirror: Clojure mode</h1>
13 <form><textarea id="code" name="code">
14; Conway's Game of Life, based on the work of:
15;; Laurent Petit https://gist.github.com/1200343
16;; Christophe Grand http://clj-me.cgrand.net/2011/08/19/conways-game-of-life
17
18(ns ^{:doc "Conway's Game of Life."}
19 game-of-life)
20
21;; Core game of life's algorithm functions
22
23(defn neighbours
24 "Given a cell's coordinates, returns the coordinates of its neighbours."
25 [[x y]]
26 (for [dx [-1 0 1] dy (if (zero? dx) [-1 1] [-1 0 1])]
27 [(+ dx x) (+ dy y)]))
28
29(defn step
30 "Given a set of living cells, computes the new set of living cells."
31 [cells]
32 (set (for [[cell n] (frequencies (mapcat neighbours cells))
33 :when (or (= n 3) (and (= n 2) (cells cell)))]
34 cell)))
35
36;; Utility methods for displaying game on a text terminal
37
38(defn print-board
39 "Prints a board on *out*, representing a step in the game."
40 [board w h]
41 (doseq [x (range (inc w)) y (range (inc h))]
42 (if (= y 0) (print "\n"))
43 (print (if (board [x y]) "[X]" " . "))))
44
45(defn display-grids
46 "Prints a squence of boards on *out*, representing several steps."
47 [grids w h]
48 (doseq [board grids]
49 (print-board board w h)
50 (print "\n")))
51
52;; Launches an example board
53
54(def
55 ^{:doc "board represents the initial set of living cells"}
56 board #{[2 1] [2 2] [2 3]})
57
58(display-grids (take 3 (iterate step board)) 5 5) </textarea></form>
59 <script>
60 var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
61 </script>
62
63 <p><strong>MIME types defined:</strong> <code>text/x-clojure</code>.</p>
64
65 </body>
66</html>