bfe6fc955a8f25cd75f17d7423d9a75242da3dce
[myslice.git] / third-party / codemirror-3.15 / mode / clojure / index.html
1 <!doctype html>
2 <html>
3   <head>
4     <meta charset="utf-8">
5     <title>CodeMirror: Clojure mode</title>
6     <link rel="stylesheet" href="../../lib/codemirror.css">
7     <script src="../../lib/codemirror.js"></script>
8     <script src="clojure.js"></script>
9     <style>.CodeMirror {background: #f8f8f8;}</style>
10     <link rel="stylesheet" href="../../doc/docs.css">
11   </head>
12   <body>
13     <h1>CodeMirror: Clojure mode</h1>
14     <form><textarea id="code" name="code">
15 ; Conway's Game of Life, based on the work of:
16 ;; Laurent Petit https://gist.github.com/1200343
17 ;; Christophe Grand http://clj-me.cgrand.net/2011/08/19/conways-game-of-life
18
19 (ns ^{:doc "Conway's Game of Life."}
20  game-of-life)
21
22 ;; Core game of life's algorithm functions
23
24 (defn neighbours
25   "Given a cell's coordinates, returns the coordinates of its neighbours."
26   [[x y]]
27   (for [dx [-1 0 1] dy (if (zero? dx) [-1 1] [-1 0 1])]
28     [(+ dx x) (+ dy y)]))
29
30 (defn step
31   "Given a set of living cells, computes the new set of living cells."
32   [cells]
33   (set (for [[cell n] (frequencies (mapcat neighbours cells))
34              :when (or (= n 3) (and (= n 2) (cells cell)))]
35          cell)))
36
37 ;; Utility methods for displaying game on a text terminal
38
39 (defn print-board
40   "Prints a board on *out*, representing a step in the game."
41   [board w h]
42   (doseq [x (range (inc w)) y (range (inc h))]
43     (if (= y 0) (print "\n"))
44     (print (if (board [x y]) "[X]" " . "))))
45
46 (defn display-grids
47   "Prints a squence of boards on *out*, representing several steps."
48   [grids w h]
49   (doseq [board grids]
50     (print-board board w h)
51     (print "\n")))
52
53 ;; Launches an example board
54
55 (def
56   ^{:doc "board represents the initial set of living cells"}
57    board #{[2 1] [2 2] [2 3]})
58
59 (display-grids (take 3 (iterate step board)) 5 5)
60
61 ;; Let's play with characters
62 (println \1 \a \# \\
63          \" \( \newline
64          \} \" \space
65          \tab \return \backspace
66          \u1000 \uAaAa \u9F9F)
67
68 </textarea></form>
69     <script>
70       var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
71     </script>
72
73     <p><strong>MIME types defined:</strong> <code>text/x-clojure</code>.</p>
74
75   </body>
76 </html>