9From [Matt Earnshaw](https://github.com/mattearnshaw/anock/blob/master/src/anock/core.clj):
13 (:import anock.NockException))
15(declare atom? cell? cell)
18 "A noun is an atom or a cell."
21 (or (atom? noun) (cell? noun))))
24 "An atom is a natural number."
27 (and (integer? noun) (>= noun 0))))
30 "A cell is an ordered pair of nouns."
35 (not= 2 (count noun)) false
36 :else (and (noun? (first noun))
37 (noun? (second noun)))))
40 "= (pronounced 'tis') tests a cell for equality."
42 (if (atom? noun) (throw (anock.NockException. "Cannot tis an atom."))
47 "? (pronounced 'wut') tests whether a noun is a cell."
52 :else (throw (anock.NockException. "Invalid noun."))))
55 "+ (pronounced 'lus') adds 1 to an atom."
57 (if (atom? noun) (inc noun)
58 (throw (anock.NockException. "Can only lus atoms."))))
61 "/ (pronounced 'fas') is a tree address function."
63 (if (atom? noun) (throw (anock.NockException. "Cannot fas an atom."))
64 (let [[a b] (cell noun)]
65 (assert (and (pos? a) (atom? a)) "Subject of fas must be a positive atom.")
66 (if (and (not (coll? b)) (or (= 2 a) (= 3 a)))
67 (throw (anock.NockException. (str "Cannot fas noun: " noun))))
72 (even? a) (fas [2 (fas [(/ a 2) b])])
73 (odd? a) (fas [3 (fas [(/ (dec a) 2) b])])))))
76 "* (pronounced 'tar') means Nock"
78 (if (atom? noun) (throw (anock.NockException. "Cannot tar an atom."))
80 (let [noun (cell noun) [x [y z]] noun]
82 (cell? y) (cell (tar [x y]) (tar [x z]))
85 (= 3 y) (wut (tar [x z]))
86 (= 4 y) (lus (tar [x z]))
87 (= 5 y) (tis (tar [x z]))
90 (= 2 y) (tar [(tar [x p]) (tar [x q])])
91 (= 6 y) (tar [x 2 [0 1] 2 [1 (first q) (second q)]
92 [1 0] 2 [1 2 3] [1 0] 4 4 p])
93 (= 7 y) (tar [x 2 p 1 q])
94 (= 8 y) (tar [x 7 [[7 [0 1] p] 0 1] q])
95 (= 9 y) (tar [x 7 q 2 [0 1] 0 p])
96 (= 10 y) (if (cell? p)
97 (tar [x 8 (second p) 7 [0 3] q])
99 (catch RuntimeException e
100 (throw (anock.NockException. (str "Cannot tar the noun " noun)))))))
104; Some convenience functions
106 (if (and (= 1 (count x)) (coll? (first x)))
111 "[a b c] -> [a [b c]]"
115 (and (noun? a) (apply noun? b)) (vec c)
116 (apply noun? b) (apply vector (bracket a) b)
117 (noun? a) [a (apply* bracket b)]
118 :else [(bracket a) (apply* bracket b)])))
121 (if (apply atom? nouns)
122 (throw (anock.NockException. "Cannot convert atom to cell."))
123 (apply* bracket nouns)))
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list