<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: guarding an expression</title>
	<atom:link href="http://twoguysarguing.wordpress.com/2011/02/01/guarding-an-expression/feed/" rel="self" type="application/rss+xml" />
	<link>http://twoguysarguing.wordpress.com/2011/02/01/guarding-an-expression/</link>
	<description>colorful back and forth from two highly opinionated programmers</description>
	<lastBuildDate>Fri, 17 May 2013 10:05:20 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: youngnh</title>
		<link>http://twoguysarguing.wordpress.com/2011/02/01/guarding-an-expression/#comment-591</link>
		<dc:creator><![CDATA[youngnh]]></dc:creator>
		<pubDate>Sun, 13 Feb 2011 20:08:51 +0000</pubDate>
		<guid isPermaLink="false">http://twoguysarguing.wordpress.com/?p=1295#comment-591</guid>
		<description><![CDATA[This solution certainly looks like it would work. 

After pondering it for a while, though, I think I would pass on this solution.  It&#039;s doing more work than necessary.  First, it has to be wrapped up in a new list, which has a (possibly minimal) cost, and finally you have to unwrap it from the list filter returns using first, which also has a (probably very minimal) cost.]]></description>
		<content:encoded><![CDATA[<p>This solution certainly looks like it would work. </p>
<p>After pondering it for a while, though, I think I would pass on this solution.  It&#8217;s doing more work than necessary.  First, it has to be wrapped up in a new list, which has a (possibly minimal) cost, and finally you have to unwrap it from the list filter returns using first, which also has a (probably very minimal) cost.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jacek Laskowski</title>
		<link>http://twoguysarguing.wordpress.com/2011/02/01/guarding-an-expression/#comment-590</link>
		<dc:creator><![CDATA[Jacek Laskowski]]></dc:creator>
		<pubDate>Fri, 11 Feb 2011 21:58:14 +0000</pubDate>
		<guid isPermaLink="false">http://twoguysarguing.wordpress.com/?p=1295#comment-590</guid>
		<description><![CDATA[What&#039;s wrong with the following?

user=&gt; (defn check? [v] (= v 5))
#&#039;user/check?
user=&gt; (defn some-computation [x y z] (+ x y z))
#&#039;user/some-computation
user=&gt; (filter check? (list (some-computation 1 3 1) 7))
(5)
user=&gt; (first (filter check? (list (some-computation 1 3 1) 7)))
5]]></description>
		<content:encoded><![CDATA[<p>What&#8217;s wrong with the following?</p>
<p>user=&gt; (defn check? [v] (= v 5))<br />
#&#8217;user/check?<br />
user=&gt; (defn some-computation [x y z] (+ x y z))<br />
#&#8217;user/some-computation<br />
user=&gt; (filter check? (list (some-computation 1 3 1) 7))<br />
(5)<br />
user=&gt; (first (filter check? (list (some-computation 1 3 1) 7)))<br />
5</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul deGrandis (ohpauleez)</title>
		<link>http://twoguysarguing.wordpress.com/2011/02/01/guarding-an-expression/#comment-589</link>
		<dc:creator><![CDATA[Paul deGrandis (ohpauleez)]]></dc:creator>
		<pubDate>Wed, 02 Feb 2011 17:51:29 +0000</pubDate>
		<guid isPermaLink="false">http://twoguysarguing.wordpress.com/?p=1295#comment-589</guid>
		<description><![CDATA[I usually use if and if-let to achieve this:
(if-let [n-shared (if (empty? shared-items) false (count shared-items))]
  (let [...])
  0)

I check for a condition with if, within the if-let, if I see the condition, I return false, which hits the false return condition.  Otherwise I bind and move into the next let block.]]></description>
		<content:encoded><![CDATA[<p>I usually use if and if-let to achieve this:<br />
(if-let [n-shared (if (empty? shared-items) false (count shared-items))]<br />
  (let [...])<br />
  0)</p>
<p>I check for a condition with if, within the if-let, if I see the condition, I return false, which hits the false return condition.  Otherwise I bind and move into the next let block.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex Miller</title>
		<link>http://twoguysarguing.wordpress.com/2011/02/01/guarding-an-expression/#comment-588</link>
		<dc:creator><![CDATA[Alex Miller]]></dc:creator>
		<pubDate>Wed, 02 Feb 2011 02:56:56 +0000</pubDate>
		<guid isPermaLink="false">http://twoguysarguing.wordpress.com/?p=1295#comment-588</guid>
		<description><![CDATA[I don&#039;t know of anything that does exactly this - seems like if-let has some of the feel and the :when guard in for comprehensions suggest some other patterns.

What about starting from if-let and adding a :when guard (which is evaled with the let val):

(defmacro guard-let
  [[v f _ guard?] then else]
  `(let [~v ~f]
     (if (~guard? ~v)
       ~then
       ~else)))

(defn add-or-even [x y]
  (guard-let [val (+ x y) :when odd?] val :even))

(add-or-even 1 2)
&gt; 3
(add-or-even 2 2)
&gt;:even

Could easily do a form that implicitly named val and returned it when the guard is true so it would look like:  (guard-let [(+ x y) :when odd?] :even)  and then you could let go of the let binding form and just do something like:  (guard (+ x y) :when odd? :even) which is pretty much what you have but orders the computation better and echoes the (for) style :when guard.]]></description>
		<content:encoded><![CDATA[<p>I don&#8217;t know of anything that does exactly this &#8211; seems like if-let has some of the feel and the :when guard in for comprehensions suggest some other patterns.</p>
<p>What about starting from if-let and adding a :when guard (which is evaled with the let val):</p>
<p>(defmacro guard-let<br />
  [[v f _ guard?] then else]<br />
  `(let [~v ~f]<br />
     (if (~guard? ~v)<br />
       ~then<br />
       ~else)))</p>
<p>(defn add-or-even [x y]<br />
  (guard-let [val (+ x y) :when odd?] val :even))</p>
<p>(add-or-even 1 2)<br />
&gt; 3<br />
(add-or-even 2 2)<br />
&gt;:even</p>
<p>Could easily do a form that implicitly named val and returned it when the guard is true so it would look like:  (guard-let [(+ x y) :when odd?] :even)  and then you could let go of the let binding form and just do something like:  (guard (+ x y) :when odd? :even) which is pretty much what you have but orders the computation better and echoes the (for) style :when guard.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
