inverted anomaly

23 views
Skip to first unread message

peter hodgson

unread,
May 22, 2017, 11:18:35 PM5/22/17
to 4clo...@googlegroups.com

an example from

https://clojuredocs.org/clojure.core/some

;;if you want to return the element that caused the predicate to return true
;;use the "and" function on the predicate and the argument:

(some #(and (even? %) %) [1 3 5 7 8 2])
;;=> 8
--------------

even? is the pred of and
and is the pred of some

But how does some both extract and identify 8, if "and" forages for a
negative?

Thanks, imputerate

--
imput...@puteracy.com

Leif

unread,
May 23, 2017, 4:18:39 PM5/23/17
to 4Clojure
Hi, Peter.

The key is that numbers are all truthy in clojure; if all its arguments are truthy, "and" returns the last value:

(and (even? 8) 8) =>
(and true 8) =>
8

Hope that helps,
Leif
Reply all
Reply to author
Forward
0 new messages