Konrad,
I've looked over your monad code and I like it, FWIW.
The macro programming will twist your mind if you don't have
experience writing Lisp style macros, but the resulting syntax seems
pretty clean.
I would make some minor changes in two places. I would write with-
monad as:
(defmacro with-monad
"Evaluates an expression after replacing the keywords defining the
monad operations by the functions associated with these keywords
in the monad definition given by name."
[name & exprs]
`(let [~'m-bind (:m-bind ~name)
~'m-result (:m-result ~name)
~'m-zero (:m-zero ~name)
~'m-plus (:m-plus ~name)]
(do ~...@exprs)))
And I would write m-lift as
(defmacro m-lift
"Converts a function f of n arguments into a function of n
monadic arguments returning a monadic value."
[n f]
(let [expr (take n (repeatedly #(gensym "x_")))
vars (vec (take n (repeatedly #(gensym "mv_"))))
steps (vec (interleave expr vars))]
(list `fn vars (monad-expr steps (cons f expr)))))
This removes the creation of the 'syms' list which you immediately
tear apart to generate the other lists.
All in all, a fine piece of code that I'll be using whenever I want to
use monads in Clojure.
I've also modified my parser combinator monad and uploaded a new
version at:
http://groups.google.com/group/clojure/web/monad-parser%20%282%29.clj
Jim
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---