<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Clojure: A few things I&#039;ve been tripping up on</title>
	<atom:link href="http://www.markhneedham.com/blog/2009/11/20/clojure-a-few-things-ive-been-tripping-up-on/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.markhneedham.com/blog/2009/11/20/clojure-a-few-things-ive-been-tripping-up-on/</link>
	<description>Thoughts on Software Development</description>
	<lastBuildDate>Sun, 14 Mar 2010 09:50:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Steve Gilardi</title>
		<link>http://www.markhneedham.com/blog/2009/11/20/clojure-a-few-things-ive-been-tripping-up-on/comment-page-1/#comment-27044</link>
		<dc:creator>Steve Gilardi</dc:creator>
		<pubDate>Sat, 21 Nov 2009 19:01:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1851#comment-27044</guid>
		<description>Regarding &quot;edge cases&quot; for truthiness, http://clojure.org/special_forms#if gives the full details. The potential gotcha is covered there: all instances of class java.lang.Boolean other than the canonical false instance Boolean/FALSE are logically true.

; clojure false is Boolean/FALSE
user=&gt; (identical? false Boolean/FALSE)
true
; other Boolean instances are logically true
user=&gt; (Boolean. false)
false
user=&gt; (if (Boolean. false) &quot;truthy&quot; &quot;not truthy&quot;)
&quot;truthy&quot;
; always use Boolean/valueOf rather than the constructor
user=&gt; (Boolean/valueOf false)
false
user=&gt; (if (Boolean/valueOf false) &quot;truthy&quot; &quot;not truthy&quot;)
&quot;not truthy&quot;
; clojure.core/boolean will fix up any Boolean instance
user=&gt; (if (boolean (Boolean. false)) &quot;truthy&quot; &quot;not truthy&quot;)
&quot;not truthy&quot;
; so will Boolean/valueOf
user=&gt; (if (Boolean/valueOf (Boolean. false)) &quot;truthy&quot; &quot;not truthy&quot;)
&quot;not truthy&quot;
user=&gt;

Pure Clojure code will always produce and consume canonical false. This subtlety only comes up when using Java interop either directly (calling a Boolean constructor, something you can and should always avoid) or when interfacing with Java libraries. When in doubt about a Boolean value returned from Java, casting using either clojure.core/boolean or Boolean/valueOf will ensure no surprises.

Note that many (most?) Java libraries will return a boolean (primitive) value rather than a Boolean (object) value. Primitive false always works without surprises.

user=&gt; (identical? Boolean/FALSE (.booleanValue (Boolean. false)))
true</description>
		<content:encoded><![CDATA[<p>Regarding "edge cases" for truthiness, <a href="http://clojure.org/special_forms#if" rel="nofollow">http://clojure.org/special_forms#if</a> gives the full details. The potential gotcha is covered there: all instances of class java.lang.Boolean other than the canonical false instance Boolean/FALSE are logically true.</p>
<p>; clojure false is Boolean/FALSE<br />
user=&gt; (identical? false Boolean/FALSE)<br />
true<br />
; other Boolean instances are logically true<br />
user=&gt; (Boolean. false)<br />
false<br />
user=&gt; (if (Boolean. false) "truthy" "not truthy")<br />
"truthy"<br />
; always use Boolean/valueOf rather than the constructor<br />
user=&gt; (Boolean/valueOf false)<br />
false<br />
user=&gt; (if (Boolean/valueOf false) "truthy" "not truthy")<br />
"not truthy"<br />
; clojure.core/boolean will fix up any Boolean instance<br />
user=&gt; (if (boolean (Boolean. false)) "truthy" "not truthy")<br />
"not truthy"<br />
; so will Boolean/valueOf<br />
user=&gt; (if (Boolean/valueOf (Boolean. false)) "truthy" "not truthy")<br />
"not truthy"<br />
user=&gt;</p>
<p>Pure Clojure code will always produce and consume canonical false. This subtlety only comes up when using Java interop either directly (calling a Boolean constructor, something you can and should always avoid) or when interfacing with Java libraries. When in doubt about a Boolean value returned from Java, casting using either clojure.core/boolean or Boolean/valueOf will ensure no surprises.</p>
<p>Note that many (most?) Java libraries will return a boolean (primitive) value rather than a Boolean (object) value. Primitive false always works without surprises.</p>
<p>user=&gt; (identical? Boolean/FALSE (.booleanValue (Boolean. false)))<br />
true</p>
]]></content:encoded>
	</item>
</channel>
</rss>
