You might be looking for the instance? function. It can be used to determine if something is an instance of a particular class.
user=> (instance? java.lang.Integer 5) true user=> (instance? java.lang.Integer "5") false To apply that to a data structure, you'd need to walk your structure and compare the elements contained within against the desired type. Depending on the structure, you could do something similar to this. (defn exclusively-contains-type? [datatype coll] (every? true? (map #(instance? datatype %1) coll))) (def my-data [1 2 3]) (println (exclusively-contains-type? java.lang.Integer my-data)) true (println (exclusively-contains-type? java.lang.Integer [1 2 3 "a"])) false This being said, Clojure is dynamically typed for a reason. It's best not to enforce types with an iron fist unless you absolutely have to. I've written large amounts of code without ever worrying about the explicit concrete type working behind the scenes, but if it gives you warm fuzzies, then by all means ;-). -Travis On Sep 24, 4:14 am, Miron Brezuleanu <mbr...@gmail.com> 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 -~----------~----~----~----~------~----~------~--~---