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