aboutsummaryrefslogtreecommitdiff
path: root/clojure/src/step3_env.clj
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-04-02 22:23:37 -0500
committerJoel Martin <github@martintribe.org>2014-04-02 22:23:37 -0500
commitea81a8087bcd7953b083a2be9db447f75e7ebf56 (patch)
tree6cf47a2dbd55d42efc4a901eaabdec952f40ce89 /clojure/src/step3_env.clj
parent1617910ad342a55762f3ddabb975849d843cff85 (diff)
downloadmal-ea81a8087bcd7953b083a2be9db447f75e7ebf56.tar.gz
mal-ea81a8087bcd7953b083a2be9db447f75e7ebf56.zip
All: split types into types, env, printer, core.
- types: low-level mapping to the implementation language. - core: functions on types that are exposed directly to mal. - printer: implementation called by pr-str, str, prn, println. - env: the environment implementation - Also, unindent all TCO while loops so that the diff of step4 and step5 are minimized.
Diffstat (limited to 'clojure/src/step3_env.clj')
-rw-r--r--clojure/src/step3_env.clj20
1 files changed, 10 insertions, 10 deletions
diff --git a/clojure/src/step3_env.clj b/clojure/src/step3_env.clj
index c0c4e8e..449bf79 100644
--- a/clojure/src/step3_env.clj
+++ b/clojure/src/step3_env.clj
@@ -1,10 +1,9 @@
(ns step3-env
(:require [clojure.repl]
- [types]
[readline]
- [reader]))
-
-(declare EVAL)
+ [reader]
+ [printer]
+ [env]))
;; read
(defn READ [& [strng]]
@@ -12,9 +11,10 @@
(reader/read-string strng)))
;; eval
+(declare EVAL)
(defn eval-ast [ast env]
(cond
- (symbol? ast) (types/env-get env ast)
+ (symbol? ast) (env/env-get env ast)
(seq? ast) (doall (map #(EVAL % env) ast))
@@ -34,12 +34,12 @@
(let [[a0 a1 a2 a3] ast]
(condp = a0
'def!
- (types/env-set env a1 (EVAL a2 env))
+ (env/env-set env a1 (EVAL a2 env))
'let*
- (let [let-env (types/env env)]
+ (let [let-env (env/env env)]
(doseq [[b e] (partition 2 a1)]
- (types/env-set let-env b (EVAL e let-env)))
+ (env/env-set let-env b (EVAL e let-env)))
(EVAL a2 let-env))
;; apply
@@ -52,12 +52,12 @@
(defn PRINT [exp] (pr-str exp))
;; repl
-(def repl-env (types/env))
+(def repl-env (env/env))
(defn rep
[strng]
(PRINT (EVAL (READ strng), repl-env)))
-(defn _ref [k,v] (types/env-set repl-env k v))
+(defn _ref [k,v] (env/env-set repl-env k v))
(_ref '+ +)
(_ref '- -)
(_ref '* *)