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).
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?
Thanks.
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 with that phrase.
The next-to-last sentence describes the behavior you're talking about. The last sentence is addressing the no-args case. Starting a sentence with a parenthesized form makes it hard to read.
--
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.
--
--
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?")
--
On 23 May 2013 18:30, atkaaz <atk...@gmail.com> wrote:I mean false-the-Boolean-value.
> 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
To rephrase the point I was making previously, "(false x) is a truthy
value for any x in []" is a true sentence, indeed trivially so because
[] is empty. Thus (every? false []) returning true totally makes
sense.
So, assuming non-empty collections are the norm, we get an exception
either way -- would having the exception come from every? rather than
the attempt to call the not-really-a-predicate object be of much help
in debugging?
Cheers,
M.
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 in a map.