diff --git a/include/monad-tests.lfe b/include/monad-tests.lfe index 0e99d4a..7630bba 100644 --- a/include/monad-tests.lfe +++ b/include/monad-tests.lfe @@ -1,5 +1,5 @@ (defmacro evaluate-m (monad mval) - `(cond ((: calrissian-util implements? 'state ,monad) + `(cond ((: calrissian-util implements? 'calrissian-state ,monad) (call ,monad 'run ,mval 'undefined)) ('true ,mval))) diff --git a/include/monads.lfe b/include/monads.lfe index 62574c1..6f1a197 100644 --- a/include/monads.lfe +++ b/include/monads.lfe @@ -1,7 +1,7 @@ (defmacro do-m args (let ((monad (car args)) (statements (cdr args))) - (monad:do-transform monad statements))) + (calrissian-monad:do-transform monad statements))) (defmacro >>= (monad m f) `(call ,monad '>>= ,m ,f)) diff --git a/src/error-monad.lfe b/src/calrissian-error-monad.lfe similarity index 82% rename from src/error-monad.lfe rename to src/calrissian-error-monad.lfe index f37e0bd..0beffd0 100644 --- a/src/error-monad.lfe +++ b/src/calrissian-error-monad.lfe @@ -1,5 +1,5 @@ -(defmodule error-monad - (behaviour monad) +(defmodule calrissian-error-monad + (behaviour calrissian-monad) (export (>>= 2) (return 1) (fail 1))) diff --git a/src/identity-monad.lfe b/src/calrissian-identity-monad.lfe similarity index 70% rename from src/identity-monad.lfe rename to src/calrissian-identity-monad.lfe index 62d190b..f090464 100644 --- a/src/identity-monad.lfe +++ b/src/calrissian-identity-monad.lfe @@ -1,5 +1,5 @@ -(defmodule identity-monad - (behaviour monad) +(defmodule calrissian-identity-monad + (behaviour calrissian-monad) (export (>>= 2) (return 1) (fail 1))) diff --git a/src/maybe-monad.lfe b/src/calrissian-maybe-monad.lfe similarity index 75% rename from src/maybe-monad.lfe rename to src/calrissian-maybe-monad.lfe index 5ff3264..77160b5 100644 --- a/src/maybe-monad.lfe +++ b/src/calrissian-maybe-monad.lfe @@ -1,5 +1,5 @@ -(defmodule maybe-monad - (behaviour monad) +(defmodule calrissian-maybe-monad + (behaviour calrissian-monad) (export (>>= 2) (return 1) (fail 1))) diff --git a/src/monad.lfe b/src/calrissian-monad.lfe similarity index 94% rename from src/monad.lfe rename to src/calrissian-monad.lfe index 179470f..81a636d 100644 --- a/src/monad.lfe +++ b/src/calrissian-monad.lfe @@ -1,4 +1,4 @@ -(defmodule monad +(defmodule calrissian-monad (export (behaviour_info 1) (do-transform 2))) diff --git a/src/state-monad.lfe b/src/calrissian-state-monad.lfe similarity index 90% rename from src/state-monad.lfe rename to src/calrissian-state-monad.lfe index 22eb1b2..7f2dd5b 100644 --- a/src/state-monad.lfe +++ b/src/calrissian-state-monad.lfe @@ -1,6 +1,6 @@ -(defmodule state-monad - (behaviour monad) - (behaviour state) +(defmodule calrissian-state-monad + (behaviour calrissian-monad) + (behaviour calrissian-state) (export (return 1) (fail 1) (run 2) diff --git a/src/state-transformer.lfe b/src/calrissian-state-transformer.lfe similarity index 64% rename from src/state-transformer.lfe rename to src/calrissian-state-transformer.lfe index 6816a2d..eb30588 100644 --- a/src/state-transformer.lfe +++ b/src/calrissian-state-transformer.lfe @@ -1,21 +1,21 @@ -(defmodule state-transformer +(defmodule calrissian-state-transformer (export all)) (include-lib "include/monads.lfe") (defun new (inner-monad) - (tuple 'state-transformer inner-monad)) + (tuple 'calrissian-state-transformer inner-monad)) (defun return - ((x (tuple 'state-transformer inner-monad)) + ((x (tuple 'calrissian-state-transformer inner-monad)) (lambda (s) (call inner-monad 'return (tuple x s))))) (defun fail - ((reason (tuple 'state-transformer inner-monad)) + ((reason (tuple 'calrissian-state-transformer inner-monad)) (lambda (_) (call inner-monad 'fail reason)))) (defun >>= - ((x f (tuple 'state-transformer inner-monad)) + ((x f (tuple 'calrissian-state-transformer inner-monad)) (lambda (s) (call inner-monad '>>= (funcall x s) @@ -30,31 +30,31 @@ (tuple 'ok s))) (defun modify - ((f (tuple 'state-transformer inner-monad)) + ((f (tuple 'calrissian-state-transformer inner-monad)) (lambda (s) (tuple 'ok (call inner-monad 'return (funcall f s)))))) (defun modify-and-return - ((f (tuple 'state-transformer inner-monad)) + ((f (tuple 'calrissian-state-transformer inner-monad)) (lambda (s) (let ((newstate (call inner-monad 'return (funcall f s)))) (tuple newstate newstate))))) (defun eval - ((m s (tuple 'state-transformer inner-monad)) + ((m s (tuple 'calrissian-state-transformer inner-monad)) (call inner-monad '>>= (funcall m s) (match-lambda (((tuple x s1)) (call inner-monad 'return x)))))) (defun exec - ((m s (tuple 'state-transformer inner-monad)) + ((m s (tuple 'calrissian-state-transformer inner-monad)) (call inner-monad '>>= (funcall m s) (match-lambda (((tuple x s1)) (call inner-monad 'return s1)))))) (defun run - ((m s (tuple 'state-transformer inner-monad)) + ((m s (tuple 'calrissian-state-transformer inner-monad)) (funcall m s))) diff --git a/src/state.lfe b/src/calrissian-state.lfe similarity index 91% rename from src/state.lfe rename to src/calrissian-state.lfe index 797241b..6fc37a0 100644 --- a/src/state.lfe +++ b/src/calrissian-state.lfe @@ -1,4 +1,4 @@ -(defmodule state +(defmodule calrissian-state (export (behaviour_info 1))) (defun behaviour_info diff --git a/test/unit/unit-calrissian-error-monad-tests.lfe b/test/unit/unit-calrissian-error-monad-tests.lfe new file mode 100644 index 0000000..24bc78f --- /dev/null +++ b/test/unit/unit-calrissian-error-monad-tests.lfe @@ -0,0 +1,36 @@ +(defmodule unit-calrissian-error-monad-tests + (export all) + (import + (from lfeunit-util + (check-failed-assert 2) + (check-wrong-assert-exception 2)))) + +(include-lib "deps/lfeunit/include/lfeunit-macros.lfe") +(include-lib "include/monads.lfe") +(include-lib "include/monad-tests.lfe") + +(test-monad 'calrissian-error-monad) + +(deftest return-ok + (is-equal 'ok + (return 'calrissian-error-monad 'ok))) + +(deftest return-value + (is-equal #(ok 123) + (return 'calrissian-error-monad 123))) + +(deftest fail-with-reason + (is-equal #(error reason) + (fail 'calrissian-error-monad 'reason))) + +(deftest fail-short-circuits-value + (is-equal (fail 'calrissian-error-monad 'something-bad) + (>> 'calrissian-error-monad + (fail 'calrissian-error-monad 'something-bad) + (return 'calrissian-error-monad 123)))) + +(deftest fail-short-circuits-error + (is-equal #(error something-bad) + (>> 'calrissian-error-monad + (fail 'calrissian-error-monad 'something-bad) + (throw 'error)))) diff --git a/test/unit/unit-identity-monad-tests.lfe b/test/unit/unit-calrissian-identity-monad-tests.lfe similarity index 63% rename from test/unit/unit-identity-monad-tests.lfe rename to test/unit/unit-calrissian-identity-monad-tests.lfe index 36ab6bd..ed4e467 100644 --- a/test/unit/unit-identity-monad-tests.lfe +++ b/test/unit/unit-calrissian-identity-monad-tests.lfe @@ -1,4 +1,4 @@ -(defmodule unit-identity-monad-tests +(defmodule unit-calrissian-identity-monad-tests (export all) (import (from lfeunit-util @@ -9,12 +9,12 @@ (include-lib "include/monads.lfe") (include-lib "include/monad-tests.lfe") -(test-monad 'identity-monad) +(test-monad 'calrissian-identity-monad) (deftest identity (is-equal 'ok - (return 'identity-monad 'ok))) + (return 'calrissian-identity-monad 'ok))) (deftest fail-with-error (is-throw #(error value) - (fail 'identity-monad 'value))) \ No newline at end of file + (fail 'calrissian-identity-monad 'value))) \ No newline at end of file diff --git a/test/unit/unit-maybe-monad-tests.lfe b/test/unit/unit-calrissian-maybe-monad-tests.lfe similarity index 68% rename from test/unit/unit-maybe-monad-tests.lfe rename to test/unit/unit-calrissian-maybe-monad-tests.lfe index 309eb17..1e1b09e 100644 --- a/test/unit/unit-maybe-monad-tests.lfe +++ b/test/unit/unit-calrissian-maybe-monad-tests.lfe @@ -1,4 +1,4 @@ -(defmodule unit-maybe-monad-tests +(defmodule unit-calrissian-maybe-monad-tests (export all) (import (from lfeunit-util @@ -9,22 +9,22 @@ (include-lib "include/monads.lfe") (include-lib "include/monad-tests.lfe") -(test-monad 'maybe-monad) +(test-monad 'calrissian-maybe-monad) (deftest nothing-short-circuits-value (is-equal 'nothing - (>>= 'maybe-monad 'nothing + (>>= 'calrissian-maybe-monad 'nothing (lambda (x) (+ 5 x))))) (deftest nothing-short-circuits-error (is-equal 'nothing - (>>= 'maybe-monad 'nothing + (>>= 'calrissian-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 'calrissian-maybe-monad (+ 1 x)))) + (bind (lambda (f m) (>>= 'calrissian-maybe-monad m f)))) (lists:foldr bind #(just 0) (list minc diff --git a/test/unit/unit-state-monad-tests.lfe b/test/unit/unit-calrissian-state-monad-tests.lfe similarity index 75% rename from test/unit/unit-state-monad-tests.lfe rename to test/unit/unit-calrissian-state-monad-tests.lfe index 87e9211..fe80e76 100644 --- a/test/unit/unit-state-monad-tests.lfe +++ b/test/unit/unit-calrissian-state-monad-tests.lfe @@ -1,4 +1,4 @@ -(defmodule unit-state-monad-tests +(defmodule unit-calrissian-state-monad-tests (export all) (import (from lfeunit-util @@ -9,4 +9,4 @@ (include-lib "include/monads.lfe") (include-lib "include/monad-tests.lfe") -(test-monad 'state-monad) +(test-monad 'calrissian-state-monad) diff --git a/test/unit/unit-state-transformer-tests.lfe b/test/unit/unit-calrissian-state-transformer-tests.lfe similarity index 68% rename from test/unit/unit-state-transformer-tests.lfe rename to test/unit/unit-calrissian-state-transformer-tests.lfe index 594c5f5..d6c693f 100644 --- a/test/unit/unit-state-transformer-tests.lfe +++ b/test/unit/unit-calrissian-state-transformer-tests.lfe @@ -1,4 +1,4 @@ -(defmodule unit-state-transformer-tests +(defmodule unit-calrissian-state-transformer-tests (export all) (import (from lfeunit-util @@ -9,23 +9,23 @@ (include-lib "include/monads.lfe") (include-lib "include/monad-tests.lfe") -(test-monad (: state-transformer new 'identity-monad)) +(test-monad (: calrissian-state-transformer new 'calrissian-identity-monad)) (deftest eval (is-equal 5 - (let* ((m (: state-transformer new 'identity-monad)) + (let* ((m (: calrissian-state-transformer new 'calrissian-identity-monad)) (mval (call m 'return 5))) (call m 'eval mval 'undefined)))) (deftest exec-unchanged (is-equal 'foo - (let* ((m (: state-transformer new 'identity-monad)) + (let* ((m (: calrissian-state-transformer new 'calrissian-identity-monad)) (mval (call m 'return 5))) (call m 'exec mval 'foo)))) (deftest exec-modify (is-equal 10 - (let ((m (: state-transformer new 'identity-monad))) + (let ((m (: calrissian-state-transformer new 'calrissian-identity-monad))) (call m 'exec (do-m m (call m 'modify (lambda (x) (* x 2)))) @@ -33,7 +33,7 @@ (deftest exec-put-and-modify (is-equal 30 - (let ((m (: state-transformer new 'identity-monad))) + (let ((m (: calrissian-state-transformer new 'calrissian-identity-monad))) (call m 'exec (do-m m (call m 'put 10) @@ -44,7 +44,7 @@ (deftest exec-bind-and-modify (is-equal 16 - (let ((m (: state-transformer new 'identity-monad))) + (let ((m (: calrissian-state-transformer new 'calrissian-identity-monad))) (call m 'exec (do-m m (a <- (call m 'modify-and-return (lambda (x) (+ x 5)))) @@ -53,7 +53,7 @@ (deftest exec-fail (is-throw #(error value) - (let ((m (: state-transformer new 'identity-monad))) + (let ((m (: calrissian-state-transformer new 'calrissian-identity-monad))) (call m 'exec (call m 'fail 'value) 'undefined)))) diff --git a/test/unit/unit-error-monad-tests.lfe b/test/unit/unit-error-monad-tests.lfe deleted file mode 100644 index 41739b0..0000000 --- a/test/unit/unit-error-monad-tests.lfe +++ /dev/null @@ -1,36 +0,0 @@ -(defmodule unit-error-monad-tests - (export all) - (import - (from lfeunit-util - (check-failed-assert 2) - (check-wrong-assert-exception 2)))) - -(include-lib "deps/lfeunit/include/lfeunit-macros.lfe") -(include-lib "include/monads.lfe") -(include-lib "include/monad-tests.lfe") - -(test-monad 'error-monad) - -(deftest return-ok - (is-equal 'ok - (return 'error-monad 'ok))) - -(deftest return-value - (is-equal #(ok 123) - (return 'error-monad 123))) - -(deftest fail-with-reason - (is-equal #(error 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)))) - -(deftest fail-short-circuits-error - (is-equal #(error something-bad) - (>> 'error-monad - (fail 'error-monad 'something-bad) - (throw 'error))))