One of the things I'm doing in my application is I modified clj-record  
to attach metadata about the record's type to each record when find- 
records is used. I am then able to have a function that checks that  
metadata which can be used as a predicate.

It gets even better because I can then write multi-methods that  
dispatch on the type of record I have. You will have to take care that  
your multimethods will only work if you have the metadata attached, so  
you'll have to take care to with-meta any records you create yourself.

my fork of clj-record is on github

On Sep 24, 2009, at 4:14 AM, Miron Brezuleanu wrote:

>
> Hello,
>
> is there a way to check if a data structure complies to a given
> schema? (e.g. people is a vector of persons).
>
> I'm using C# a lot and maybe the static typing has changed the way I
> think. I feel like adding "type checks" in unit tests and being able
> to say something like:
>
> (is-type (people (vector person)))
>
> sounds like a neat way to check types (I know 'vector' is a 'taken'
> name, I'm just trying to illustrate the kind of syntax I'm thinking
> about). The degree of typing can be varied (i.e. a person is any map
> with a :name key, or any map with only a :name key, or any map with a
> :name key which is nil or string etc.)
>
> I browsed through clojure.test (which is clojure.contrib.test-is
> integrated into Clojure, right?) but couldn't find something like
> this.
>
> Thank you,
> -- 
> Miron Brezuleanu
>
> >


--~--~---------~--~----~------------~-------~--~----~
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
Note that posts from new members are moderated - please be patient with your 
first post.
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