-
Notifications
You must be signed in to change notification settings - Fork 1
/
repl.cljs
39 lines (29 loc) · 838 Bytes
/
repl.cljs
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
(ns fif.impl.repl
(:require
[fif.stack-machine.evaluators :as evaluators]
[fif.protocols.repl
:refer [IRepl repl-init repl-prompt
repl-read repl-eval repl-loop
repl-run]]))
;; Untested and likely unsupported. Use fif.impl.prepl instead.
(defrecord Repl [*sm]
IRepl
(repl-init [this]
(println this "Fif Repl"))
(repl-prompt [this]
(print this "> "))
(repl-read [this])
(repl-eval [this sform]
(swap! (:*sm this) evaluators/eval-string sform))
(repl-loop [this]
(loop []
(repl-prompt this)
(let [sform (repl-read this)]
(if-not (= sform "bye")
(do (repl-eval this sform) (recur))
(println "For now, bye!!")))))
(repl-run [this]
(repl-init this)
(repl-loop this)))
(defn new-repl [sm]
(map->Repl {:*sm (atom sm)}))