diff options
| author | Joel Martin <github@martintribe.org> | 2014-03-24 16:32:24 -0500 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2014-03-24 16:32:24 -0500 |
| commit | 3169070063b2cb877200117ebb384269d73bcb93 (patch) | |
| tree | 23de3db1ea5c37afd21a45b6ed7771f56a08c0c4 /clojure/src/step1_read_print.clj | |
| download | mal-3169070063b2cb877200117ebb384269d73bcb93.tar.gz mal-3169070063b2cb877200117ebb384269d73bcb93.zip | |
Current state of mal for Clojure West lighting talk.
Diffstat (limited to 'clojure/src/step1_read_print.clj')
| -rw-r--r-- | clojure/src/step1_read_print.clj | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/clojure/src/step1_read_print.clj b/clojure/src/step1_read_print.clj new file mode 100644 index 0000000..a99a0ed --- /dev/null +++ b/clojure/src/step1_read_print.clj @@ -0,0 +1,33 @@ +(ns step1-read-print + (:require [clojure.repl] + [types] + [readline] + [reader])) + +;; read +(defn READ [& [strng]] + (let [line (if strng strng (read-line))] + (reader/read-string strng))) + +;; eval +(defn EVAL [ast env] + ast) + +;; print +(defn PRINT [exp] (pr-str exp)) + +;; repl +(defn rep + [strng] + (PRINT (EVAL (READ strng), {}))) + +(defn -main [& args] + (loop [] + (let [line (readline/readline "user> ")] + (when line + (when-not (re-seq #"^\s*$|^\s*;.*$" line) ; blank/comment + (try + (println (rep line)) + (catch Throwable e + (clojure.repl/pst e)))) + (recur))))) |
