Re: Re: Schema for data structures

2009-10-01 Thread Emeka
Artyom, (provide/contract [interp (- AE? number?)]) ;; interpret an arithmetical expression yielding a number (define (interp exp) ;; type-case is very much like a case ... of in Haskell/ML (type-case AE exp (num (n) n) (plus (l r) (+ (interp l) (interp r))) (sub (l

Re: Schema for data structures

2009-09-27 Thread Miron Brezuleanu
Hi, On Sat, Sep 26, 2009 at 3:36 PM, Daniel Werner daniel.d.wer...@googlemail.com wrote: On Sep 24, 10:14 am, Miron Brezuleanu mbr...@gmail.com wrote: 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

Re: Schema for data structures

2009-09-26 Thread Daniel Werner
On Sep 24, 10:14 am, Miron Brezuleanu mbr...@gmail.com wrote: 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.) You may be interested in Konrad Hinsen's (algebraic)

Fwd: Re: Schema for data structures

2009-09-26 Thread Artyom Shalkhakov
Ooops, sent it to the wrong address. -- Forwarded message -- From: Artyom Shalkhakov artyom.shalkha...@gmail.com Date: 2009/9/25 Subject: Re: Schema for data structures To: clojure group nore...@googlegroups.com Hello Miron, is there a way to check if a data structure

Re: Schema for data structures

2009-09-26 Thread Daniel Renfer
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

Re: Schema for data structures

2009-09-25 Thread Miron Brezuleanu
Hi, thanks for the suggestions about writing an alternate defstruct. I tried to turn the wishful thinking from my initial email into code. Results here: http://github.com/mbrezu/beak-check Testing structures with beak-check requires some code, but it allows to test nested structures and

Re: Schema for data structures

2009-09-24 Thread tmountain
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

Re: Schema for data structures

2009-09-24 Thread Miron Brezuleanu
Hello, On Thu, Sep 24, 2009 at 5:09 PM, tmountain tinymount...@gmail.com wrote: 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

Re: Schema for data structures

2009-09-24 Thread Constantine Vetoshev
On Sep 24, 10:59 am, Miron Brezuleanu mbr...@gmail.com wrote: Well, I only want to enforce duck-typing :-) - for instance, make sure via unit tests that a function that should return a data structure with certain properties always returns such a data structure. Not exactly what you asked for,

Re: Schema for data structures

2009-09-24 Thread Richard Newman
Use it just like you use defstruct, e.g.: (defstruct* person :first- name :last-name :age), but it will also create a little type-checker function: is-person? Here are some tests to see how it works: Note that your type checker will give false positives if you're intending to use accessors: