From 3169070063b2cb877200117ebb384269d73bcb93 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Mon, 24 Mar 2014 16:32:24 -0500 Subject: Current state of mal for Clojure West lighting talk. --- clojure/src/step1_read_print.clj | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 clojure/src/step1_read_print.clj (limited to 'clojure/src/step1_read_print.clj') 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))))) -- cgit v1.2.3