-
Notifications
You must be signed in to change notification settings - Fork 0
/
repl.hy
69 lines (54 loc) · 2.23 KB
/
repl.hy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
;;Tool Builder v0.1 - Build any software tool with Hy-interpreted pseudocode
;;@author Andrew Phillips
;;@copyright 2016 Andrew Phillips <[email protected]>
;;Tool Builder is free software; you can redistribute it and/or
;;modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
;;License as published by the Free Software Foundation; either
;;version 3 of the License, or any later version.
;;Tool Builder is distributed in the hope that it will be useful,
;;but WITHOUT ANY WARRANTY; without even the implied warranty of
;;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;GNU AFFERO GENERAL PUBLIC LICENSE for more details.
;;You should have received a copy of the GNU Affero General Public
;;License along with Tool Builder. If not, see <http://www.gnu.org/licenses/>.
;; TB REPL
(import [loader :as -loader] io)
(defclass Store []
[
[--init-- (fn [self reducer]
(setv (. self -reducer) reducer)
(setv (. self -state) None)
(setv (. self -listeners) [])
(.dispatch self))]
[dispatch (fn [self action]
(do (if (= action None) (setv action {}))
(setv (. self -state)
(.-reducer self (. self -state) action))
(for [listener (. self -listeners)] (.listener))))]
[subscribe (fn [self listener]
(do (.append (. self -listeners) listener)
(defn unsubscribe []
(.remove (. self -listeners listener)))))]
])
(setv -dish "<=: ")
(setv -food "error... :(")
(setv -diet "diet.hy")
(setv -nutri "nutri")
(setv -store {})
(defn eat [] ; BUG: input not registered
(setv -food
(input -dish)))
(defn digest [food]
(do (with [[f (open -diet "a")]]
(.write f (+ food "
")))
(if (= ":=>" (slice food 0 3))
(swallow (slice food 4))
(cook food))))
(defn feed []
(do (while True (setv -food (input -dish)) ;(eat)
(if (= -food "sleep-pills") (break))
(digest -food))))
(defn cook [food] (cond [(= (slice food 0 3) "ex ") (print food)] [True (print "I cannot cook this food...")]))
;(defn prep [] (for [ingr (.split (. self food) " ")] (yield ingr)))
;(defn )