Usage: (every? pred coll)
(see http://clojuredocs.org/clojure_core/clojure.core/every_q )
Function *every?* expects a predicate and a collection. Converting the map
{:a 1} into a collection returns a sequence of 2-element vectors:
user= (seq {:a 1})
([:a 1])
Calling the function :a on a
Thank you, I see it now. Based on your comment I actually took at look at
the source code for every? (haven't checked it before, oddly enough)
= (source every?)
(defn every?
Returns true if (pred x) is logical true for every x in coll, else
false.
{:tag Boolean
:added 1.0
:static
typo, I meant: thanks to everyone that replieD
On Fri, May 24, 2013 at 9:25 PM, atkaaz atk...@gmail.com wrote:
Thank you, I see it now. Based on your comment I actually took at look at
the source code for every? (haven't checked it before, oddly enough)
= (source every?)
(defn every?
On Fri, May 24, 2013 at 1:25 PM, atkaaz atk...@gmail.com wrote:
It kinda makes sense except I wouldn't have expected that on the map it
would return a vector (but then how else could it return both key and value
right? ) so everyone expects the input to the pred would be a vector
when passed
Whether (false 1) or (false true) is truthy is irrelevant. What
matters is that false returns truthy values when called with any
members of [], which is of course the case, as [] has no members. (For
it not to be the case, there would have to exist an x in [] for which
(false x) were not truthy --
when you say the word false I'm assuming you're referring to false? the
function (not false the boolean value), otherwise I don't understand
so like: What matters is that *false?* returns truthy values when called
with any members of []
makes sense to me.
So all I was saying above is that it
On Thu, May 23, 2013 at 11:30 AM, atkaaz atk...@gmail.com wrote:
So all I was saying above is that it should throw when [] is empty just as
it does when [] is not empty, but it doesn't throw when empty because it's
never called (by it i mean false not false?)
This sort of behavior is handy
A while back I saw some java slides that elude me now, they mentioned
approaches to safety like defensive copying, immutability, etc.. their
conclusion at the end, that I seem to remember, was it only really made
sense to validate user input, a sort of wall, where anything past the wall
is
On 23 May 2013 18:30, atkaaz atk...@gmail.com wrote:
when you say the word false I'm assuming you're referring to false? the
function (not false the boolean value), otherwise I don't understand
I mean false-the-Boolean-value.
To rephrase the point I was making previously, (false x) is a truthy
At this moment after reading again this thread, I lost my sense of what false
and true
mean :) I'll now stick with maybe, it's much clearer...
Luc P.
On 23 May 2013 18:30, atkaaz atk...@gmail.com wrote:
when you say the word false I'm assuming you're referring to false? the
function (not
Firstly let me just say that I really enjoy this conversation, ergo I thank
you!
On Thu, May 23, 2013 at 9:00 PM, Michał Marczyk michal.marc...@gmail.comwrote:
On 23 May 2013 18:30, atkaaz atk...@gmail.com wrote:
when you say the word false I'm assuming you're referring to false?
the
OK long time lurker here. I've been growing in my Clojure strength for a
while now. For the most part I think I get it and I have no problem getting
programs to do what I want. However, sometimes I get stumped.
I have one function that produces a list of booleans like '(false false
true). It
Using a lambda seems to be a sane approach -
(reduce #(and %1 %2) '(false false true))
;= false
On Wed, May 22, 2013 at 5:36 AM, Peter Mancini pe...@cicayda.com wrote:
OK long time lurker here. I've been growing in my Clojure strength for a
while now. For the most part I think I get it and I
Using eval should be a rarity.
I'd use (every? identity [false false true]) to do a reduce-and, and I'd
use (some identity [false false true]) to do a reduce-or (keeping in mind
the latter actually returns nil rather than false).
--
--
You received this message because you are subscribed to
The reason and is a macro is that it's designed to short-circuit - ie if
the first result is false the rest shouldn't even be evaluated.
Using it on raw booleans works, because booleans evaluate to themselves,
but it's really designed to be given forms.
The absence of a pure function for
On Wed, May 22, 2013 at 3:06 AM, Peter Mancini pe...@cicayda.com wrote:
I noticed that '(nil nil true) will cause and to produce false, so I am
aware of that edge case. Anything else I should be aware of?
What about the other edge?
user= (reduce #(and %1 %2) '(1 true 2))
2
user= (eval (conj
I find the wording of this confusing otherwise it returns the value
of the last
expr. (and) returns true.
I mean, I know it returns the last true value, but that's because I've
tested it not because the doc is trying(failing) to tell me so with that
phrase.
On Wed, May 22, 2013 at 1:28 PM,
On May 22, 2013 5:35 AM, atkaaz atk...@gmail.com wrote:
I find the wording of this confusing otherwise it returns the value of
the last expr. (and) returns true.
I mean, I know it returns the last true value, but that's because I've
tested it not because the doc is trying(failing) to tell me so
Oh i see now, thank you!
so it's like this:
otherwise it returns the value of the last expression.
(and) returns true.
i though expr. is the short for of the word expression which requires a
dot, but the dot was in fact an end of sentence.
On Wed, May 22, 2013 at 2:40 PM, John D. Hume
On 22 May 2013 08:09, Baishampayan Ghose b.gh...@gmail.com wrote:
Using a lambda seems to be a sane approach -
(reduce #(and %1 %2) '(false false true))
;= false
Note that this will always traverse the entire input collection,
whereas every? stops at the first false value.
Same thing goes
Thanks everyone for the help. The nil behavior of the 'or' version breaks
what I wanted, but I may create functions that return just true or false
though the odd edge case where and will return a value will mean I'll
have to handle that. My preference would be to throw an exception but thats
On 22/05/13 15:54, Peter Mancini wrote:
The nil behavior of the 'or' version breaks what I wanted, but I may
create functions that return just true or false though the odd edge
case where and will return a value will mean I'll have to handle that.
wrap that call in a 'boolean' call (e.g.
Well, excepts that it is not correct. It will return false when really
there was a faulty collection handed to it. I'd rather catch an error like
that than to pretend it didn't happen and give a result that isn't correct
while also being hard to detect. If you can guarantee it won't get a bad
On Wed, May 22, 2013 at 12:14 AM, Chris Ford christophertf...@gmail.comwrote:
The reason and is a macro is that it's designed to short-circuit - ie if
the first result is false the rest shouldn't even be evaluated.
Using it on raw booleans works, because booleans evaluate to themselves,
but
So I did some coding and came up with this but it is broken;
(= java.lang.Boolean (type false)) ;;evaluates to true
(defn all-true?
[coll]
(every? (cond (= java.lang.Boolean (type identity)) identity :else false)
coll)) ;;compiles
(all-true? '(true true true)) ;; throws
= (type identity)
clojure.core$identity
On Wed, May 22, 2013 at 7:17 PM, Peter Mancini peter.manc...@gmail.comwrote:
So I did some coding and came up with this but it is broken;
(= java.lang.Boolean (type false)) ;;evaluates to true
(defn all-true?
[coll]
(every? (cond (=
Try:
user= (every? #(= Boolean (type %)) [true false false])
true
user= (every? #(= Boolean (type %)) [true false false 1])
false
On 22 May 2013 18:20, atkaaz atk...@gmail.com wrote:
= (type identity)
clojure.core$identity
On Wed, May 22, 2013 at 7:17 PM, Peter Mancini
Duh never mind - simplified it and it works like a charm now.
(defn all-true?
[coll]
(every? (fn [x] (= x true)) coll))
(all-true? '(true true true))
(all-true? '(true true false))
(all-true? '(true true 3))
(all-true? '(3 \# !))
No exception on bad input data but if I really need to do
I think the exception is thrown because you basically called (every? false
coll) however on my clojure version I cannot reproduce it oh wait there we
go, some bug here with empty collection (maybe someone can pick it up):
= (every? false [1 2 3])
ClassCastException java.lang.Boolean cannot be
there's another edge case when using and/or :
getting passed an unbound var where for example `nil?` and `str` applied
to it don't throw, and of course also `or` and `and`, ie.:
= (def a)
#'cgws.notcore/a
= a
#Unbound Unbound: #'cgws.notcore/a
= (nil? a)
false
= (str a)
Unbound:
On Wed, May 22, 2013 at 9:32 AM, Peter Mancini peter.manc...@gmail.com wrote:
(defn all-true?
[coll]
(every? (fn [x] (= x true)) coll))
(defn all-true?
[coll]
(every? true? coll))
--
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. --
On 22 May 2013 18:34, atkaaz atk...@gmail.com wrote:
I think the exception is thrown because you basically called (every? false
coll) however on my clojure version I cannot reproduce it oh wait there we
go, some bug here with empty collection (maybe someone can pick it up):
= (every? false [1
Well, seems to me more like this:
if [] is empty then return true
otherwise check (pred everyx in coll)
however this allows for any pred especially(in this case) invalid preds:
`false` is not a function/pred
= (false 1)
ClassCastException java.lang.Boolean cannot be cast to clojure.lang.IFn
33 matches
Mail list logo