aboutsummaryrefslogtreecommitdiff
path: root/clojure/src/core.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/core.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/core.clj')
-rw-r--r--clojure/src/core.clj63
1 files changed, 63 insertions, 0 deletions
diff --git a/clojure/src/core.clj b/clojure/src/core.clj
new file mode 100644
index 0000000..23dfc55
--- /dev/null
+++ b/clojure/src/core.clj
@@ -0,0 +1,63 @@
+(ns core)
+
+;; Errors/exceptions
+(defn mal_throw [obj]
+ (throw (ex-info "mal exception" {:data obj})))
+
+;; Atoms
+(defn atom? [atm]
+ (= (type atm) clojure.lang.Atom))
+
+;; core_ns is core namespaces functions
+(def core_ns
+ [['= =]
+ ['throw mal_throw]
+ ['nil? nil?]
+ ['true? true?]
+ ['false? false?]
+ ['symbol? symbol?]
+ ['pr-str pr-str]
+ ['str str]
+ ['prn prn]
+ ['println println]
+ ['< <]
+ ['<= <=]
+ ['> >]
+ ['>= >=]
+ ['+ +]
+ ['- -]
+ ['* *]
+ ['/ /]
+
+ ['list list]
+ ['list? seq?]
+ ['vector vector]
+ ['vector? vector?]
+ ['hash-map hash-map]
+ ['map? map?]
+ ['assoc assoc]
+ ['dissoc dissoc]
+ ['get get]
+ ['contains? contains?]
+ ['keys keys]
+ ['vals vals]
+
+ ['sequential? sequential?]
+ ['cons cons]
+ ['concat concat]
+ ['nth nth]
+ ['first first]
+ ['rest rest]
+ ['empty? empty?]
+ ['count count]
+ ['conj conj]
+ ['apply apply]
+ ['map #(doall (map %1 %2))]
+
+ ['with-meta with-meta]
+ ['meta meta]
+ ['atom atom]
+ ['atom? atom?]
+ ['deref deref]
+ ['reset! reset!]
+ ['swap! swap!]])