Created
November 4, 2013 05:13
-
-
Save thefloweringash/7298326 to your computer and use it in GitHub Desktop.
Why not Haskell syntax?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns gist.monad | |
(use [clojure.algo.monads :only [domonad]])) | |
(def <-) | |
(defn transform-monad-syntax [body last-was-assign] | |
(let [[v o e & r] body] | |
(cond (empty? body) | |
(if last-was-assign | |
(throw (IllegalArgumentException. "last value in m-do must be expression")) | |
[]) | |
(= o '<-) | |
(concat [v e] (transform-monad-syntax r true)) | |
:else | |
(concat ['_ v] (transform-monad-syntax (rest body) false))))) | |
(defmacro m-do [monad & body] | |
`(domonad ~monad | |
~(vec (transform-monad-syntax body false)) | |
~(last body))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment