Is this boolean behavior intentional?

11 views
Skip to first unread message

Raffael Cavallaro

unread,
Nov 19, 2008, 1:12:14 PM11/19/08
to Clojure
user> (def test-array (make-array (. Boolean TYPE) 100))
#'user/test-array
user> (aget test-array 0)
false
user> (= (aget test-array 0) false)
true
user> (if (aget test-array 0) 'true-value 'false-value)
true-value

Same issue with when, and when-not as well. IOW, (aget some-boolean-
array some-index) is treated as returning true even if the actual
return value of aget is false.


Rich Hickey

unread,
Nov 19, 2008, 2:21:17 PM11/19/08
to Clojure


On Nov 19, 1:12 pm, Raffael Cavallaro <raffaelcavall...@gmail.com>
wrote:
Fixed (svn 1112) - thanks for the report.

The problem is that the Java reflection APIs return new Boolean values
other than the canonic Boolean.TRUE and Boolean.FALSE when boxing
booleans, but for efficiency only canonic false is logical false in
Clojure. Apparently, Array.get also falls into this category, so I had
to fix up all Boolean returns from Array.get

Rich

Raffael Cavallaro

unread,
Nov 19, 2008, 3:21:12 PM11/19/08
to Clojure


On Nov 19, 2:21 pm, Rich Hickey <richhic...@gmail.com> wrote:
>
> Fixed (svn 1112) - thanks for the report.
>
> The problem is that the Java reflection APIs return new Boolean values
> other than the canonic Boolean.TRUE and Boolean.FALSE when boxing
> booleans, but for efficiency only canonic false is logical false in
> Clojure. Apparently, Array.get also falls into this category, so I had
> to fix up all Boolean returns from Array.get
>
> Rich

Ah, I thought it might have something to do with the boxing. Thanks
for looking into this so quickly.

warmest regards,


Ralph
Reply all
Reply to author
Forward
0 new messages