diff options
author | Jose Antonio Marquez | 2012-02-15 20:37:48 -0800 |
---|---|---|
committer | Jose Antonio Marquez | 2012-02-15 20:37:48 -0800 |
commit | 89b5e793ea88ef235b54b6e1d1c379698d3e612b (patch) | |
tree | 4d29118f35df77ca6b423119a4ff61694a442cbf /imports/codemirror/mode/clojure/index.html | |
parent | 9d2c2a80483415d7560b00cda5519153db23e241 (diff) | |
parent | d366c0bd1af6471511217ed574083e15059519b5 (diff) | |
download | ninja-89b5e793ea88ef235b54b6e1d1c379698d3e612b.tar.gz |
Merge branch 'refs/heads/NinjaInternal' into Color
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> | ||