From a96bb768a5f02c2dc9c0de1e50dc14376d2e7f35 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 26 Nov 2014 19:26:22 -0400 Subject: + Can now define functions. % However, they currently access Clojure's environment, instead of the interpreter's. --- src/lang/util.clj | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/lang/util.clj') diff --git a/src/lang/util.clj b/src/lang/util.clj index 1290d91df..d9745e9ab 100644 --- a/src/lang/util.clj +++ b/src/lang/util.clj @@ -58,12 +58,15 @@ (fn [state] (match (monad state) [::ok [?state ?head]] - ((exec [tail (repeat-m monad)] - (return (cons ?head tail))) - ?state) + (do ;; (prn 'repeat-m/?state ?state) + (match ((repeat-m monad) ?state) + [::ok [?state* ?tail]] + (do ;; (prn 'repeat-m/?state* ?state*) + (return* ?state* (cons ?head ?tail))))) - [::failure _] - (return* state '())))) + [::failure ?message] + (do ;; (println "Failed at last:" ?message) + (return* state '()))))) (defn try-all-m [monads] (fn [state] @@ -90,7 +93,7 @@ (fn [state] ;; (prn 'apply-m monad call-state) (let [output (monad call-state)] - ;; (prn 'output output) + ;; (prn 'apply-m/output output) (match output [::ok [?state ?datum]] [::ok [state ?datum]] @@ -105,3 +108,7 @@ (defn pass [m-value] (fn [state] m-value)) + +(def get-state + (fn [state] + (return* state state))) -- cgit v1.2.3