I don't see why not if you really really need to return true/false...
Of course as Tassilo said nil is falsey so it is unlikely that you would
ever need to do that...
Jim
On 14/06/12 18:16, David Nolen wrote:
Definitely something that should not written as a macro :)
David
On Thu, Jun 14, 2012 at 1:14 PM, Jim - FooBar(); <jimpil1...@gmail.com
<mailto:jimpil1...@gmail.com>> wrote:
you can always make your own with a little macro but if you just
started learning today you may want to stick with some...
I, like you, wanted a version that returns true or false a couple
of months ago.. here it is:
(defmacro in?
"Returns true if colle contains elm, false otherwise."
[colle elm]
`(if (some #{~elm} ~colle) true false))
Hope that helps...notice this is a macro not a function - the call
to in? will expand at compile time into the body of the macro...in
other words you've just created some new syntax!
Jim
On 14/06/12 16:31, Jacobo Polavieja wrote:
Hi!
I've just started learning Clojure today. I've started reading
"Clojure - Functional Programming for the JVM"
(http://java.ociweb.com/mark/clojure/article.html
<http://java.ociweb.com/mark/clojure/article.html#Collections>).
Anyway, on the collections part
(http://java.ociweb.com/mark/clojure/article.html#Collections) it
called my attention that 'some' returns "nil" instead of "false".
The examples given (being stooges a vector of Strings) are:
(not-every? #(instance? String %) stooges) ; -> false
(some #(instance? Number %) stooges) ; -> nil
Is there a reason why (some) doesn't return false also? I've read
through the doc but as I supposed, there's no explanation about
the reasoning behind it.
Thanks!
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
<mailto:clojure@googlegroups.com>
Note that posts from new members are moderated - please be
patient with your first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
<mailto:clojure+unsubscr...@googlegroups.com>
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
<mailto:clojure@googlegroups.com>
Note that posts from new members are moderated - please be patient
with your first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
<mailto:clojure%2bunsubscr...@googlegroups.com>
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient
with your first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en