aboutsummaryrefslogtreecommitdiff
path: root/clojure/src/types.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/types.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/types.clj')
-rw-r--r--clojure/src/types.clj71
1 files changed, 0 insertions, 71 deletions
diff --git a/clojure/src/types.clj b/clojure/src/types.clj
deleted file mode 100644
index 922cf79..0000000
--- a/clojure/src/types.clj
+++ /dev/null
@@ -1,71 +0,0 @@
-(ns types)
-
-;; Custom printing
-
-(defmethod clojure.core/print-method clojure.lang.Atom [a writer]
- (.write writer "(atom ")
- (.write writer (pr-str @a))
- (.write writer ")"))
-
-;; Errors/exceptions
-(defn mal_throw [obj]
- (throw (ex-info "mal exception" {:data obj})))
-
-
-;; Atoms
-(defn atom? [atm]
- (= (type atm) clojure.lang.Atom))
-
-
-;; env
-
-(defn env [& [outer binds exprs]]
- ;;(prn "env" binds exprs)
- ;; (when (not= (count binds) (count exprs))
- ;; (throw (Exception. "Arity mistmatch in env call")))
- (atom
- (loop [env {:outer outer}
- b binds
- e exprs]
- (cond
- (= nil b)
- env
-
- (= '& (first b))
- (assoc env (nth b 1) e)
-
- :else
- (recur (assoc env (first b) (first e)) (next b) (next e))))))
-
-(defn env-find [env k]
- (cond
- (contains? @env k) env
- (:outer @env) (env-find (:outer @env) k)
- :else nil))
-
-(defn env-get [env k]
- (let [e (env-find env k)]
- (when-not e
- (throw (Exception. (str "'" k "' not found"))))
- (get @e k)))
-
-(defn env-set [env k v]
- (swap! env assoc k v)
- v)
-
-(def types_ns
- [['pr-str pr-str] ['str str] ['prn prn] ['println println]
- ['with-meta with-meta] ['meta meta] ['= =]
- ['nil? nil?] ['true? true?] ['false? false?] ['symbol? symbol?]
- ['> >] ['>= >=] ['< <] ['<= <=] ['+ +] ['- -] ['* *] ['/ /]
- ['hash-map hash-map] ['map? map?]
- ['assoc assoc] ['dissoc dissoc] ['get get]
- ['contains? contains?] ['keys keys] ['vals vals]
- ['throw mal_throw]
- ['list list] ['list? seq?] ['vector vector] ['vector? vector?]
- ['atom atom] ['atom? atom?] ['deref deref]
- ['reset! reset!] ['swap! swap!]
- ['sequential? sequential?] ['cons cons] ['nth nth]
- ['empty? empty?] ['count count] ['concat concat]
- ['conj conj] ['first first] ['rest rest]
- ['apply apply] ['map #(doall (map %1 %2))]])