-
Notifications
You must be signed in to change notification settings - Fork 1
/
repl.clj
41 lines (30 loc) · 836 Bytes
/
repl.clj
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
(ns fif.impl.repl
"Clojure Implementation of a basic repl."
(:require
[fif.protocols.repl :refer :all]
[fif.stack-machine.evaluators :as evaluators]))
(defrecord Repl [*sm]
IRepl
(repl-init [this]
(println "Fif Repl")
(println " 'help' for Help Message,")
(println " 'bye' to Exit.")
(flush))
(repl-prompt [this]
(print "> ") (flush))
(repl-read [this]
(read-line))
(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) (flush) (recur))
(println "For now, bye!")))))
(repl-run [this]
(repl-init this)
(repl-loop this)))
(defn new-repl [sm]
(map->Repl {:*sm (atom sm)}))