Re: Porting Scala example to Clojure

2008-08-25 Thread Stuart Halloway
> On Aug 25, 11:27 am, Stuart Halloway <[EMAIL PROTECTED]> > wrote: >>> It's a bit apples and oranges emulating pattern matching and case >>> classes with multimethods, but very illustrative. It's important to >>> note that the Scala code is using type tags, not values, in doing >>> the >>> matc

Re: Porting Scala example to Clojure

2008-08-25 Thread Rich Hickey
On Aug 25, 11:27 am, Stuart Halloway <[EMAIL PROTECTED]> wrote: > > It's a bit apples and oranges emulating pattern matching and case > > classes with multimethods, but very illustrative. It's important to > > note that the Scala code is using type tags, not values, in doing the > > match, so I

Re: Porting Scala example to Clojure

2008-08-25 Thread Stuart Halloway
> It's a bit apples and oranges emulating pattern matching and case > classes with multimethods, but very illustrative. It's important to > note that the Scala code is using type tags, not values, in doing the > match, so I think using tags rather than looking for non-zero values > is more similar

Re: Porting Scala example to Clojure

2008-08-25 Thread Rich Hickey
On Aug 25, 8:45 am, Stuart Halloway <[EMAIL PROTECTED]> wrote: > For Java.next [1,2] part 3, I am porting Daniel Spiewak's color > example [3] to Clojure. Here's the Clojure version: > > (defstruct color :red :green :blue) > > (defn red [v] (struct color v 0 0)) > (defn green [v] (struct color 0 v

Re: Porting Scala example to Clojure

2008-08-25 Thread Stuart Halloway
> (defn basic-colors-in [color] > (for [[k v] color :when (not= v 0)] k)) Chouser: That is way better, thanks! Stuart --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send em

Re: Porting Scala example to Clojure

2008-08-25 Thread Chouser
On Mon, Aug 25, 2008 at 9:16 AM, Chouser <[EMAIL PROTECTED]> wrote: > On Mon, Aug 25, 2008 at 8:45 AM, Stuart Halloway > <[EMAIL PROTECTED]> wrote: >> >> (defn keys-with-value-matching [map test-fn] >> (for [pair (map identity map) :when (test-fn (last pair))] >> (first pair))) >> >> (de

Re: Porting Scala example to Clojure

2008-08-25 Thread Chouser
On Mon, Aug 25, 2008 at 8:45 AM, Stuart Halloway <[EMAIL PROTECTED]> wrote: > > (defn keys-with-value-matching [map test-fn] > (for [pair (map identity map) :when (test-fn (last pair))] > (first pair))) > > (defn basic-colors-in [color] > (keys-with-value-matching color (comp not zero?)

Porting Scala example to Clojure

2008-08-25 Thread Stuart Halloway
For Java.next [1,2] part 3, I am porting Daniel Spiewak's color example [3] to Clojure. Here's the Clojure version: (defstruct color :red :green :blue) (defn red [v] (struct color v 0 0)) (defn green [v] (struct color 0 v 0)) (defn blue [v] (struct color 0 0 v)) (defn keys-with-value-matching