Parsing in Clojure via a Backtracking State Monad Posted by stevenashley on Thursday February 11, 2010 @07:33PM from the brehaut.net dept. http://brehaut.net/blog/2010/ghosts_in_the_machine ( 4 comments | 16 points | on HN )
(def parse-number (domonad [sign (optional parse-sign "+") [type digits] (choice parse-integer parse-float) _ eof] [type (apply str (cons sign digits))])))
The fact that you can fail on the eof and backtrack into the choice (if it is possible) is the main advantage. It lets you lay out your parser in a logical way.
I wrote clarsec because I was in hurry and the "kotka"'s sources weren't available.