Rename 'do' to 'do-m'

'do' is a built-in lisp macro
This commit is contained in:
Correl Roush 2014-04-25 01:11:04 -04:00
parent f923b68374
commit 888effbf13
3 changed files with 25 additions and 25 deletions

View file

@ -12,12 +12,12 @@
(return ,monad 1))))
(deftest monad-do
(is-equal (return ,monad 'ok)
(do ,monad
(do-m ,monad
(return ,monad 'ignored)
(return ,monad 'ok))))
(deftest monad-do-binding
(is-equal (return ,monad 9)
(do ,monad
(do-m ,monad
(a <- (return ,monad 3))
(return ,monad (* a a)))))
(deftest monad-sequence
@ -50,25 +50,25 @@
(deftest monad-do-left-identity
(let ((a 3)
(f (lambda (n) (return ,monad (* 3 n)))))
(is-equal (do ,monad (a' <- (return ,monad a))
(is-equal (do-m ,monad (a' <- (return ,monad a))
(funcall f a'))
(do ,monad (funcall f a)))))
(do-m ,monad (funcall f a)))))
(deftest monad-do-right-identity
(let ((m (return ,monad 3)))
(is-equal (do ,monad (x <- m)
(is-equal (do-m ,monad (x <- m)
(return ,monad x))
(do ,monad m))))
(do-m ,monad m))))
(deftest monad-do-associativity
(let ((m (return ,monad 3))
(f (lambda (n) (return ,monad (* 3 n))))
(g (lambda (n) (return ,monad (+ 5 n)))))
(is-equal (do ,monad (y <- (do ,monad (x <- m)
(is-equal (do-m ,monad (y <- (do-m ,monad (x <- m)
(funcall f x)))
(funcall g y))
(do ,monad (x <- m)
(do ,monad (y <- (funcall f x))
(do-m ,monad (x <- m)
(do-m ,monad (y <- (funcall f x))
(funcall g y))))))
))

View file

@ -1,4 +1,4 @@
(defmacro do args
(defmacro do-m args
(let ((monad (car args))
(statements (cdr args)))
(monad:do-transform monad statements)))
@ -19,7 +19,7 @@
,list))
(defmacro mcons (monad m mlist)
`(do ,monad
`(do-m ,monad
(x <- ,m)
(rest <- ,mlist)
(return ,monad (cons x rest))))

View file

@ -38,13 +38,13 @@
(deftest do-bindings
(is-equal #(just 3)
(do maybe-monad
(do-m maybe-monad
(a <- #(just 1))
(b <- #(just 2))
(return maybe-monad (+ a b)))))
(deftest do-nobindings
(is-equal #(just 3)
(do maybe-monad
(do-m maybe-monad
#(just 5)
#(just 3))))