Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial

  • Loading branch information...
commit cfe135ef54b218d1134acad381c97c99b78fdacc 0 parents
@mmikulicic authored
Showing with 63 additions and 0 deletions.
  1. +15 −0 README
  2. +1 −0  project.clj
  3. +47 −0 src/clarsec.clj
15 README
@@ -0,0 +1,15 @@
+# clarsec
+
+FIXME: write description
+
+## Usage
+
+FIXME: write
+
+## Installation
+
+FIXME: write
+
+## License
+
+FIXME: write
1  project.clj
@@ -0,0 +1 @@
+(defproject clarsec "1.0.0-SNAPSHOT" :description "FIXME: write" :dependencies [[org.clojure/clojure "1.1.0-master-SNAPSHOT"] [org.clojure/clojure-contrib "1.0-SNAPSHOT"]] :main clarsec)
47 src/clarsec.clj
@@ -0,0 +1,47 @@
+(ns clarsec
+ (:gen-class)
+ (:use [clojure.contrib.monads]))
+
+(defn consumed? [x] (= (:type x) :consumed))
+(defn failed? [x] (= (:type x) :failed))
+
+(defn failed [] {:type :failed})
+(defn consumed [value rest] {:type :consumed
+ :value value
+ :rest rest})
+
+(defmonad parser-m
+ [m-result (fn m-result-parser [x] (fn [str] {:type :consumed
+ :value x
+ :rest str}))
+ m-bind (fn m-bind-parser [parser func]
+ (fn [strn]
+ (let [result (parser strn)]
+ (if (consumed? result)
+ ((func (:value result)) (:rest result))
+ result
+ ))))
+
+ m-zero (fn [strn] (failed))
+
+ m-plus (fn [& parsers] (println "ciao" parsers))
+ ]
+)
+
+(defmonadfn any-char [strn]
+ (if (= "" strn)
+ (failed)
+ (consumed (first strn)
+ (. strn (substring 1))))
+)
+
+
+(defmonadfn body []
+ (domonad [x any-char
+ y any-char] (str y x))
+)
+
+
+(defn mytest [ n]
+ (with-monad parser-m ((body) n)
+ ))
Please sign in to comment.
Something went wrong with that request. Please try again.