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)))
>
Hi,
On Sat, Sep 26, 2009 at 3:36 PM, Daniel Werner
wrote:
>
> On Sep 24, 10:14 am, Miron Brezuleanu 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.)
>
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 wr
On Sep 24, 10:14 am, Miron Brezuleanu 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) data type supp
Ooops, sent it to the wrong address.
-- Forwarded message --
From: Artyom Shalkhakov
Date: 2009/9/25
Subject: Re: "Schema" for data structures
To: clojure group
Hello Miron,
> is there a way to check if a data structure complies to a given
> schema? (e.g. pe
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 testing
> 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 accessor
On Sep 24, 10:59 am, Miron Brezuleanu 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, but I added a
Hello,
On Thu, Sep 24, 2009 at 5:09 PM, tmountain 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 exclusively-cont
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 comp
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
11 matches
Mail list logo