diff options
| author | Joel Martin <github@martintribe.org> | 2015-03-02 21:33:10 -0600 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2015-03-02 21:33:10 -0600 |
| commit | 835fb7d8b06e2b44792a97ac89994658bf6d00af (patch) | |
| tree | 578f67726ab9e3ce5fcbc50220e9761a66c5ddf1 /clojure/src | |
| parent | 6b72e6078a7d505ecf9d711eb4a16fc4dfac36b6 (diff) | |
| parent | 8a98ef9a3f3a6b6d05d02dc305a0c886c907e0f3 (diff) | |
| download | mal-835fb7d8b06e2b44792a97ac89994658bf6d00af.tar.gz mal-835fb7d8b06e2b44792a97ac89994658bf6d00af.zip | |
Merge branch 'master' into gh-pages
Conflicts:
.gitignore
Diffstat (limited to 'clojure/src')
| -rw-r--r-- | clojure/src/core.clj | 20 | ||||
| -rw-r--r-- | clojure/src/readline.clj | 3 | ||||
| -rw-r--r-- | clojure/src/step9_try.clj (renamed from clojure/src/step9_interop.clj) | 22 | ||||
| -rw-r--r-- | clojure/src/stepA_mal.clj (renamed from clojure/src/stepA_more.clj) | 2 |
4 files changed, 27 insertions, 20 deletions
diff --git a/clojure/src/core.clj b/clojure/src/core.clj index 6b0d9b5..4438e29 100644 --- a/clojure/src/core.clj +++ b/clojure/src/core.clj @@ -5,11 +5,6 @@ (defn mal_throw [obj] (throw (ex-info "mal exception" {:data obj}))) -;; Number functions - -(defn time-ms [] - (System/currentTimeMillis)) - ;; Metadata functions ;; - store metadata at :meta key of the real metadata (defn mal_with_meta [obj m] @@ -19,10 +14,6 @@ (defn mal_meta [obj] (:meta (meta obj))) -;; Atom functions -(defn atom? [atm] - (= (type atm) clojure.lang.Atom)) - ;; core_ns is core namespaces functions (def core_ns [['= =] @@ -30,7 +21,10 @@ ['nil? nil?] ['true? true?] ['false? false?] + ['symbol symbol] ['symbol? symbol?] + ['keyword keyword] + ['keyword? keyword?] ['pr-str pr-str] ['str str] @@ -47,7 +41,7 @@ ['- -] ['* *] ['/ /] - ['time-ms time-ms] + ['time-ms (fn time-ms [] (System/currentTimeMillis))] ['list list] ['list? seq?] @@ -59,8 +53,8 @@ ['dissoc dissoc] ['get get] ['contains? contains?] - ['keys keys] - ['vals vals] + ['keys (fn [hm] (let [ks (keys hm)] (if (nil? ks) '() ks)))] + ['vals (fn [hm] (let [vs (vals hm)] (if (nil? vs) '() vs)))] ['sequential? sequential?] ['cons cons] @@ -77,7 +71,7 @@ ['with-meta mal_with_meta] ['meta mal_meta] ['atom atom] - ['atom? atom?] + ['atom? (fn atom? [atm] (= (type atm) clojure.lang.Atom))] ['deref deref] ['reset! reset!] ['swap! swap!]]) diff --git a/clojure/src/readline.clj b/clojure/src/readline.clj index 0fc449a..a510e13 100644 --- a/clojure/src/readline.clj +++ b/clojure/src/readline.clj @@ -27,7 +27,8 @@ (def load-history (jna/to-fn Integer readline/read_history))) (defn readline [prompt & [lib]] - (if (not @history-loaded) + (when (not @history-loaded) + (reset! history-loaded true) (load-history HISTORY-FILE)) (let [line (readline-call prompt)] (when line diff --git a/clojure/src/step9_interop.clj b/clojure/src/step9_try.clj index c4d67e5..7e18a74 100644 --- a/clojure/src/step9_interop.clj +++ b/clojure/src/step9_try.clj @@ -1,4 +1,4 @@ -(ns step9-interop +(ns step9-try (:refer-clojure :exclude [macroexpand]) (:require [clojure.repl] [readline] @@ -94,9 +94,20 @@ 'macroexpand (macroexpand a1 env) - 'clj* - (eval (reader/read-string a1)) - + 'try* + (if (= 'catch* (nth a2 0)) + (try + (EVAL a1 env) + (catch clojure.lang.ExceptionInfo ei + (EVAL (nth a2 2) (env/env env + [(nth a2 1)] + [(:data (ex-data ei))]))) + (catch Throwable t + (EVAL (nth a2 2) (env/env env + [(nth a2 1)] + [(.getMessage t)])))) + (EVAL a1 env)) + 'do (do (eval-ast (->> ast (drop-last) (drop 1)) env) (recur (last ast) env)) @@ -161,4 +172,5 @@ (env/env-set repl-env '*ARGV* (rest args)) (if args (rep (str "(load-file \"" (first args) "\")")) - (repl-loop))) + (do + (repl-loop)))) diff --git a/clojure/src/stepA_more.clj b/clojure/src/stepA_mal.clj index fc7451f..ce289b6 100644 --- a/clojure/src/stepA_more.clj +++ b/clojure/src/stepA_mal.clj @@ -1,4 +1,4 @@ -(ns stepA-more +(ns stepA-mal (:refer-clojure :exclude [macroexpand]) (:require [clojure.repl] [readline] |
