Look at every?. The predicate true? returns true if its argument is
the boolean literal true, and false otherwise. If, instead, you want
to check for logical truth (false and nil are false, everything else
is true), then use identity. As you can see, every? falls out at the
first false result.

user=> (every? true? (list true true true))
true
user=> (every? true? (lazy-cat [true false] (println "not executed")))
false
user=> (every? true? (lazy-cat [true true] (println "executed")))
executed
true
user=> (every? true? [])
true
user=> (every? true? (list true 1))
false
user=> (every? identity (list true 1))
true

On Jan 15, 1:53 pm, Daniel Jomphe <danieljom...@gmail.com> wrote:
> I'm in the following situation:
>
>    (and '(true true))
>    ;doesn't work
>
> I tried apply, reduce, and a few other things. Reading the apidocs,
> reduce is said to be the proper choice to compute a boolean from a
> seq. But:
>
>    (reduce and '(true true))
>    ;Exception: Can't take value of a macro: #'clojure.core/and
>
> Also, the following isn't the solution:
>
>    (reduce 'and '(true false true))
>    ;true
>
> In any case, I think using reduce with "and" wouldn't be nice because
> it won't return false as soon as it can like "and" does. Therefore, I
> came up with the following working solution:
>
>    (defmacro and-booleans [logical-booleans-list]
>      `(and ~...@logical-booleans-list))
>
>    (and-booleans (true false true))
>    ;false
>
> But I wonder if I have overlooked something fundamental, either about
> reduce or anything else.
>
> Of course, I could have built my final boolean value imperatively, in
> effect reimplementing "and" for lists as a function that wraps the
> "ant" built-in macro. But I'm hoping to leave imperative programming
> as much behing me as possible.
>
> What would you consider the normal way of solving this small problem
> of mine?
--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to