> 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
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
> 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
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
> (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
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
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?)
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