How about a macro like this?
--
(defmacro my-case [e & clauses]
`(condp = ~e
~...@clauses))
--
(defn panda-3 [x]
(my-case (type x)
java.lang.String "HELLZ YEAH IT'S A STRING!"
java.lang.Integer "it's an integer..."))
--
I'll just stick with condp though. Thanks David
On Tue, Dec 21, 2010 at 12:23 AM, Sean Corfield wrote:
> On Mon, Dec 20, 2010 at 7:54 PM, Stephen Pardue
> wrote:
> > (defn panda [x]
> >(case (type x)
> >java.lang.String "HELLZ YEAH IT'S A STRING!"
> >java.lang.Integer "it's an integer.."))
>
> Since (type x) returns a Class
On Mon, Dec 20, 2010 at 7:54 PM, Stephen Pardue
wrote:
> (defn panda [x]
> (case (type x)
> java.lang.String "HELLZ YEAH IT'S A STRING!"
> java.lang.Integer "it's an integer.."))
Since (type x) returns a Class object, you could do this:
user=> (defn panda[x] (case (.getName (typ
user> (type 'java.lang.Integer)
clojure.lang.Symbol
user>
the docs for case say the test constants are not evaluated.
On Mon, Dec 20, 2010 at 8:16 PM, David Nolen wrote:
> On Mon, Dec 20, 2010 at 10:54 PM, Stephen Pardue
> wrote:
>>
>> (defn panda-2 [x]
>> (let [xType (type x)]
>> (co
On Mon, Dec 20, 2010 at 10:54 PM, Stephen Pardue
wrote:
> (defn panda-2 [x]
>(let [xType (type x)]
>(cond
>(= java.lang.String xType) "HELLZ YEAH IT'S A STRING!"
>(= java.lang.Integer xType) "it's an integer...")))
>
You should take a look at condp.
If you fin
Hello Clojure land!
I am writing a function that I just realized that I could implement
using multi methods (I think).
However, I will describe the problem anyways.
I want to be able to call a function that will take different actions
depending on the type of in the input.
I first wrote this funct