From 0a0300b129df4499782cbe47aeaee581f57cc3db Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Fri, 26 Dec 2014 01:00:30 -0400 Subject: Reimplemented basic pattern-matching. --- src/lang/util.clj | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/lang/util.clj') diff --git a/src/lang/util.clj b/src/lang/util.clj index cdfa8555d..e2edfb550 100644 --- a/src/lang/util.clj +++ b/src/lang/util.clj @@ -59,14 +59,14 @@ (match (monad state) [::ok [?state ?head]] (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))))) + (match ((repeat-m monad) ?state) + [::ok [?state* ?tail]] + (do ;; (prn 'repeat-m/?state* ?state*) + (return* ?state* (cons ?head ?tail))))) [::failure ?message] (do ;; (println "Failed at last:" ?message) - (return* state '()))))) + (return* state '()))))) (defn try-all-m [monads] (fn [state] @@ -89,6 +89,12 @@ outputs (map-m f (rest inputs))] (return (conj outputs output))))) +(defn reduce-m [f init inputs] + (if (empty? inputs) + (return init) + (exec [init* (f init (first inputs))] + (reduce-m f init* (rest inputs))))) + (defn apply-m [monad call-state] (fn [state] ;; (prn 'apply-m monad call-state) -- cgit v1.2.3