(defn repl1
"Reads a single line from stdin, `evaluate`s it and prints the result to stdout.
Returns the evaluated expression."
[]
(-> (read) (evaluate env-global) (doto (prn))))
;; this is called `toplevel` in the book
(defn repl
"`repl1` in a loop with support for a clean exit via `(end)`.
To exit enter "
([]
(println "Welcome to the REPL!")
(println "You can evaluate forms one by one - they are read from stdin.")
(println "When you are done, type (end)")
(repl nil))
([last-ret]
(if (= last-ret 'repl.exit)
(println "Bye!")
(recur (repl1)))))