diff options
author | Nivesh Rajbhandari | 2012-02-20 11:14:44 -0800 |
---|---|---|
committer | Nivesh Rajbhandari | 2012-02-20 11:14:44 -0800 |
commit | abf78e2d7a97d295ce5a1c425fd359d47379137e (patch) | |
tree | d08c91bd2aef31e6325e0b499b2ffc390018bec6 /imports/codemirror/mode/clojure/index.html | |
parent | e80a79bff57fecf3aa9b869d8ed2de5fd815287c (diff) | |
parent | e23708721a71ca4c71365f5f8e8ac7d6113926db (diff) | |
download | ninja-abf78e2d7a97d295ce5a1c425fd359d47379137e.tar.gz |
Merge branch 'refs/heads/ninja-internal' into ToolFixes
Diffstat (limited to 'imports/codemirror/mode/clojure/index.html')
-rwxr-xr-x | imports/codemirror/mode/clojure/index.html | 66 |
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> | ||