From 02ada611dfe018f99febfb5fe70ebde90b3a33e3 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Tue, 13 May 2014 19:30:46 -0400 Subject: [PATCH] Remove monad atom evaluation skipping in macros --- include/monads.lfe | 17 ++++------------- test/unit/unit-error-monad-tests.lfe | 20 ++++++++++---------- test/unit/unit-identity-monad-tests.lfe | 6 +++--- test/unit/unit-maybe-monad-tests.lfe | 10 +++++----- 4 files changed, 22 insertions(+), 31 deletions(-) diff --git a/include/monads.lfe b/include/monads.lfe index b8a0aa2..62574c1 100644 --- a/include/monads.lfe +++ b/include/monads.lfe @@ -4,25 +4,16 @@ (monad:do-transform monad statements))) (defmacro >>= (monad m f) - (if (: lfe-utils atom? monad) - `(call ',monad '>>= ,m ,f) - `(call ,monad '>>= ,m ,f))) + `(call ,monad '>>= ,m ,f)) (defmacro >> (monad m1 m2) - (let ((f `(lambda (_) ,m2))) - (if (: lfe-utils atom? monad) - `(call ',monad '>>= ,m1 ,f) - `(call ,monad '>>= ,m1 ,f)))) + `(call ,monad '>>= ,m1 (lambda (_) , m2))) (defmacro return (monad expr) - (if (: lfe-utils atom? monad) - `(call ',monad 'return ,expr) - `(call ,monad 'return ,expr))) + `(call ,monad 'return ,expr)) (defmacro fail (monad expr) - (if (: lfe-utils atom? monad) - `(call ',monad 'fail ,expr) - `(call ,monad 'fail ,expr))) + `(call ,monad 'fail ,expr)) (defmacro sequence (monad list) `(: lists foldr diff --git a/test/unit/unit-error-monad-tests.lfe b/test/unit/unit-error-monad-tests.lfe index 8f2982d..41739b0 100644 --- a/test/unit/unit-error-monad-tests.lfe +++ b/test/unit/unit-error-monad-tests.lfe @@ -9,28 +9,28 @@ (include-lib "include/monads.lfe") (include-lib "include/monad-tests.lfe") -(test-monad error-monad) +(test-monad 'error-monad) (deftest return-ok (is-equal 'ok - (return error-monad 'ok))) + (return 'error-monad 'ok))) (deftest return-value (is-equal #(ok 123) - (return error-monad 123))) + (return 'error-monad 123))) (deftest fail-with-reason (is-equal #(error reason) - (fail error-monad 'reason))) + (fail 'error-monad 'reason))) (deftest fail-short-circuits-value - (is-equal (fail error-monad 'something-bad) - (>> error-monad - (fail error-monad 'something-bad) - (return error-monad 123)))) + (is-equal (fail 'error-monad 'something-bad) + (>> 'error-monad + (fail 'error-monad 'something-bad) + (return 'error-monad 123)))) (deftest fail-short-circuits-error (is-equal #(error something-bad) - (>> error-monad - (fail error-monad 'something-bad) + (>> 'error-monad + (fail 'error-monad 'something-bad) (throw 'error)))) diff --git a/test/unit/unit-identity-monad-tests.lfe b/test/unit/unit-identity-monad-tests.lfe index d1b7bc6..36ab6bd 100644 --- a/test/unit/unit-identity-monad-tests.lfe +++ b/test/unit/unit-identity-monad-tests.lfe @@ -9,12 +9,12 @@ (include-lib "include/monads.lfe") (include-lib "include/monad-tests.lfe") -(test-monad identity-monad) +(test-monad 'identity-monad) (deftest identity (is-equal 'ok - (return identity-monad 'ok))) + (return 'identity-monad 'ok))) (deftest fail-with-error (is-throw #(error value) - (fail identity-monad 'value))) \ No newline at end of file + (fail 'identity-monad 'value))) \ No newline at end of file diff --git a/test/unit/unit-maybe-monad-tests.lfe b/test/unit/unit-maybe-monad-tests.lfe index 99b92d3..309eb17 100644 --- a/test/unit/unit-maybe-monad-tests.lfe +++ b/test/unit/unit-maybe-monad-tests.lfe @@ -9,22 +9,22 @@ (include-lib "include/monads.lfe") (include-lib "include/monad-tests.lfe") -(test-monad maybe-monad) +(test-monad 'maybe-monad) (deftest nothing-short-circuits-value (is-equal 'nothing - (>>= maybe-monad 'nothing + (>>= 'maybe-monad 'nothing (lambda (x) (+ 5 x))))) (deftest nothing-short-circuits-error (is-equal 'nothing - (>>= maybe-monad 'nothing + (>>= 'maybe-monad 'nothing (lambda (_) (error 'bad-func))))) (deftest fold-increment-value (is-equal #(just 3) - (let ((minc (lambda (x) (return maybe-monad (+ 1 x)))) - (bind (lambda (f m) (>>= maybe-monad m f)))) + (let ((minc (lambda (x) (return 'maybe-monad (+ 1 x)))) + (bind (lambda (f m) (>>= 'maybe-monad m f)))) (lists:foldr bind #(just 0) (list minc