diff options
Diffstat (limited to 'clojure/src/step9_interop.clj')
| -rw-r--r-- | clojure/src/step9_interop.clj | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/clojure/src/step9_interop.clj b/clojure/src/step9_interop.clj index d78aed7..da37574 100644 --- a/clojure/src/step9_interop.clj +++ b/clojure/src/step9_interop.clj @@ -1,11 +1,11 @@ (ns step9-interop (:refer-clojure :exclude [macroexpand]) (:require [clojure.repl] - [types] [readline] - [reader])) - -(declare EVAL) + [reader] + [printer] + [env] + [core])) ;; read (defn READ [& [strng]] @@ -13,6 +13,7 @@ (reader/read-string strng))) ;; eval +(declare EVAL) (defn is-pair [x] (and (sequential? x) (> (count x) 0))) @@ -33,19 +34,19 @@ (defn is-macro-call [ast env] (and (seq? ast) (symbol? (first ast)) - (types/env-find env (first ast)) - (:ismacro (meta (types/env-get env (first ast)))))) + (env/env-find env (first ast)) + (:ismacro (meta (env/env-get env (first ast)))))) (defn macroexpand [ast env] (loop [ast ast] (if (is-macro-call ast env) - (let [mac (types/env-get env (first ast))] + (let [mac (env/env-get env (first ast))] (recur (apply mac (rest ast)))) ast))) (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)) @@ -71,12 +72,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)) 'quote @@ -88,7 +89,7 @@ 'defmacro! (let [func (with-meta (EVAL a2 env) {:ismacro true})] - (types/env-set env a1 func)) + (env/env-set env a1 func)) 'macroexpand (macroexpand a1 env) @@ -113,7 +114,7 @@ :environment env :parameters a1} (fn [& args] - (EVAL a2 (types/env env a1 args))) + (EVAL a2 (env/env env a1 args))) ;; apply (let [el (eval-ast ast env) @@ -121,22 +122,22 @@ args (rest el) {:keys [expression environment parameters]} (meta f)] (if expression - (recur expression (types/env environment parameters args)) + (recur expression (env/env environment parameters args)) (apply f args)))))))))) ;; print (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)) ;; Import types related functions -(doseq [[k v] types/types_ns] (_ref k v)) +(doseq [[k v] core/core_ns] (_ref k v)) ;; Defined using the language itself (_ref 'read-string reader/read-string) |
