Skip to content

Instantly share code, notes, and snippets.

@apskii
Created September 8, 2013 19:21
Show Gist options
  • Save apskii/6487612 to your computer and use it in GitHub Desktop.
Save apskii/6487612 to your computer and use it in GitHub Desktop.
(defmacro monadic (&body statements)
`(let ((m *monad*))
(statements-of (monad m) ,@statements)))
(defun monad-example (ma mb)
(monadic
(get x ma)
(get y mb)
(val z (+ x y))
(ret (list x y z))))
(monad-example 1 2) ; >-id-monad-> (1 2 3)
(let ((*monad* +list-monad+))
(monad-example (list 1 2) (list 3))) ; >-> ((1 3 4) (2 3 5))
(let ((*monad* +nil-monad+))
(monad-example 1 2)) ; >-> (1 2 3)
(let ((*monad* +nil-monad+))
(monad-example nil 2)) ; >-> nil
(let ((*monad* +nil-monad+))
(monad-example 1 nil)) ; >-> nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment