I've been whipping up a simple schema library for validating Clojure
data based on their tags, but I'm worried that what I'm doing might be
redundant with an already existing library. Is there something, such
as in clojure-contrib, that can do things similar to the code below
(note the make-schemata and validate functions)?

(derive ::employee ::person)
(derive ::special-employee ::employee)

(def schemata-plans
  {::person {:required {:name string?}
             :optional {:id (partial < 0)}}
   ::employee {:required {:dept keyword?}}
   ::special-employee {:required {:name integer?}}})

(defn with-tag
  "Changes its argument's tag to the given tag."
  [tag x]
  (with-meta x (merge ^x {:tag x})))

(defstruct person-s :name :id)
(def valid-employee
  (with-tag ::employee (struct-map person-s :name "Bill", :id 10
                                            :dept :management)))
(def invalid-employee
  (with-tag ::employee (struct-map person-s :name "Bob", :id -11
                                            :dept :management)))

(binding [*schemata* (make-schemata schemata-plans)]
 (println (validate valid-employee)) ; nil
 (println (validate invalid-employee)) ; A map of validation problems


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to