<?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: Writing a Java function in Clojure</title>
	<atom:link href="http://www.markhneedham.com/blog/2009/11/23/writing-a-java-function-in-clojure/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.markhneedham.com/blog/2009/11/23/writing-a-java-function-in-clojure/</link>
	<description>Thoughts on Software Development</description>
	<lastBuildDate>Thu, 18 Mar 2010 23:35:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Steve</title>
		<link>http://www.markhneedham.com/blog/2009/11/23/writing-a-java-function-in-clojure/comment-page-1/#comment-27345</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Sat, 28 Nov 2009 22:43:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1868#comment-27345</guid>
		<description>I see, your test cases really like:

null*, 1, 2, 3, null* =&gt; no gaps

where null* is any number of nulls and not just a single null at the beginning and end. Your original code makes more sense to me now.</description>
		<content:encoded><![CDATA[<p>I see, your test cases really like:</p>
<p>null*, 1, 2, 3, null* =&gt; no gaps</p>
<p>where null* is any number of nulls and not just a single null at the beginning and end. Your original code makes more sense to me now.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://www.markhneedham.com/blog/2009/11/23/writing-a-java-function-in-clojure/comment-page-1/#comment-27341</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Sat, 28 Nov 2009 22:01:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1868#comment-27341</guid>
		<description>You could make your java code a bit more lispish by using subList instead of iterator.  Something like:

public boolean hasGaps(List values) {
        if (values.size() &lt; 3) return false;
        boolean rv = false;
        List sub = values.subList(1, values.size()-1);
        while(! rv &amp;&amp; sub.size() &gt; 0) {
            rv = (sub.get(0) == null);
            sub = sub.subList(1, sub.size());
        }
        return rv;
    }

Similar in Clojure:
(defn has-gaps [v]
         (cond (&lt; (count v) 3) nil
           :else (some (fn[x] (nil? x)) (subvec (vec v) 1 (dec (count v))))))</description>
		<content:encoded><![CDATA[<p>You could make your java code a bit more lispish by using subList instead of iterator.  Something like:</p>
<p>public boolean hasGaps(List values) {<br />
        if (values.size() &lt; 3) return false;<br />
        boolean rv = false;<br />
        List sub = values.subList(1, values.size()-1);<br />
        while(! rv &amp;&amp; sub.size() &gt; 0) {<br />
            rv = (sub.get(0) == null);<br />
            sub = sub.subList(1, sub.size());<br />
        }<br />
        return rv;<br />
    }</p>
<p>Similar in Clojure:<br />
(defn has-gaps [v]<br />
         (cond (&lt; (count v) 3) nil<br />
           :else (some (fn[x] (nil? x)) (subvec (vec v) 1 (dec (count v))))))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dimitris Andreou</title>
		<link>http://www.markhneedham.com/blog/2009/11/23/writing-a-java-function-in-clojure/comment-page-1/#comment-27273</link>
		<dc:creator>Dimitris Andreou</dc:creator>
		<pubDate>Thu, 26 Nov 2009 11:17:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1868#comment-27273</guid>
		<description>Using Collections.reverse() in the original java solution is bad. Using a ListIterator from the end of the list should make it at least almost twice as fast.</description>
		<content:encoded><![CDATA[<p>Using Collections.reverse() in the original java solution is bad. Using a ListIterator from the end of the list should make it at least almost twice as fast.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stand</title>
		<link>http://www.markhneedham.com/blog/2009/11/23/writing-a-java-function-in-clojure/comment-page-1/#comment-27242</link>
		<dc:creator>stand</dc:creator>
		<pubDate>Wed, 25 Nov 2009 19:17:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1868#comment-27242</guid>
		<description>Stuart, the partition by threes approach won&#039;t work if there are consecutive nils inside the list, or am I missing something?</description>
		<content:encoded><![CDATA[<p>Stuart, the partition by threes approach won't work if there are consecutive nils inside the list, or am I missing something?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stefan Bistram</title>
		<link>http://www.markhneedham.com/blog/2009/11/23/writing-a-java-function-in-clojure/comment-page-1/#comment-27234</link>
		<dc:creator>Stefan Bistram</dc:creator>
		<pubDate>Wed, 25 Nov 2009 16:42:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1868#comment-27234</guid>
		<description>@Stuart
cool solution and almost ok: not instead not?

First I was puzzled about -&gt;&gt;, it&#039;s unknown in the release clojure 1.0.0, but in snapshot clojure-1.0.0-2009-10-28 it&#039;s working:

user=&gt; (-&gt;&gt; 1 (+ 3) (+ 4))
8

Woudn&#039;t it be more readable to use empty? false? instead of seq boolean. I would create a more general trim utils function like (if it&#039;s not already in the contrib lib): 

(defn trim [s t]
  (-&gt;&gt;
    s
    (drop-while #(= t %))
    reverse
    (drop-while #(= t %))
    reverse))

and use it like:

(defn has-nil-gaps? [s]
  (some nil? (trim s nil)))</description>
		<content:encoded><![CDATA[<p>@Stuart<br />
cool solution and almost ok: not instead not?</p>
<p>First I was puzzled about -&gt;&gt;, it's unknown in the release clojure 1.0.0, but in snapshot clojure-1.0.0-2009-10-28 it's working:</p>
<p>user=&gt; (-&gt;&gt; 1 (+ 3) (+ 4))<br />
8</p>
<p>Woudn't it be more readable to use empty? false? instead of seq boolean. I would create a more general trim utils function like (if it's not already in the contrib lib): </p>
<p>(defn trim [s t]<br />
  (-&gt;&gt;<br />
    s<br />
    (drop-while #(= t %))<br />
    reverse<br />
    (drop-while #(= t %))<br />
    reverse))</p>
<p>and use it like:</p>
<p>(defn has-nil-gaps? [s]<br />
  (some nil? (trim s nil)))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stuart Halloway</title>
		<link>http://www.markhneedham.com/blog/2009/11/23/writing-a-java-function-in-clojure/comment-page-1/#comment-27117</link>
		<dc:creator>Stuart Halloway</dc:creator>
		<pubDate>Mon, 23 Nov 2009 13:48:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1868#comment-27117</guid>
		<description>Left the % out of the previous one (iPhone sucks as IDE)

#(not? (nil? %))</description>
		<content:encoded><![CDATA[<p>Left the % out of the previous one (iPhone sucks as IDE)</p>
<p>#(not? (nil? %))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stuart Halloway</title>
		<link>http://www.markhneedham.com/blog/2009/11/23/writing-a-java-function-in-clojure/comment-page-1/#comment-27116</link>
		<dc:creator>Stuart Halloway</dc:creator>
		<pubDate>Mon, 23 Nov 2009 13:45:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1868#comment-27116</guid>
		<description>(defn has-gaps? [s]
  (-&gt;&gt;
   s
   (drop-while nil?)
   (drop-while #(not? (nil?)))
   (drop-while nil?)
   seq
   boolean))</description>
		<content:encoded><![CDATA[<p>(defn has-gaps? [s]<br />
  (-&gt;&gt;<br />
   s<br />
   (drop-while nil?)<br />
   (drop-while #(not? (nil?)))<br />
   (drop-while nil?)<br />
   seq<br />
   boolean))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stuart Halloway</title>
		<link>http://www.markhneedham.com/blog/2009/11/23/writing-a-java-function-in-clojure/comment-page-1/#comment-27114</link>
		<dc:creator>Stuart Halloway</dc:creator>
		<pubDate>Mon, 23 Nov 2009 13:15:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1868#comment-27114</guid>
		<description>Partition by threes and &quot;some&quot; for a (x nil x)</description>
		<content:encoded><![CDATA[<p>Partition by threes and "some" for a (x nil x)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tweets that mention Writing a Java function in Clojure at Mark Needham -- Topsy.com</title>
		<link>http://www.markhneedham.com/blog/2009/11/23/writing-a-java-function-in-clojure/comment-page-1/#comment-27109</link>
		<dc:creator>Tweets that mention Writing a Java function in Clojure at Mark Needham -- Topsy.com</dc:creator>
		<pubDate>Mon, 23 Nov 2009 11:08:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1868#comment-27109</guid>
		<description>[...] This post was mentioned on Twitter by Mark Needham, ajlopez. ajlopez said: RT @markhneedham: a simple java -&gt; clojure function example http://bit.ly/6dZB0N [...]</description>
		<content:encoded><![CDATA[<p>[...] This post was mentioned on Twitter by Mark Needham, ajlopez. ajlopez said: RT @markhneedham: a simple java -&gt; clojure function example <a href="http://bit.ly/6dZB0N" rel="nofollow">http://bit.ly/6dZB0N</a> [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
