<?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: Using refs in Clojure to Scope State</title>
	<atom:link href="http://etherplex.org/archives/71/feed" rel="self" type="application/rss+xml" />
	<link>http://etherplex.org/archives/71</link>
	<description>Rick Dillon&#039;s home on the net...</description>
	<lastBuildDate>Sun, 06 May 2012 00:20:09 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Erick</title>
		<link>http://etherplex.org/archives/71/comment-page-1#comment-2659</link>
		<dc:creator>Erick</dc:creator>
		<pubDate>Tue, 30 Aug 2011 05:58:24 +0000</pubDate>
		<guid isPermaLink="false">http://etherplex.org/?p=71#comment-2659</guid>
		<description>Sorry, just to clarify, your posting is not the problem (I just realized my comment might make it sound like I am implying that), Your example is perfectly fine and thread safe of course, etc.. but others are linking to it stating things like &quot;see.. Clojure has got a problem with thread safety.. look at the explanation here&quot;. OMG, that is not what the guy said!!! sigh!. Just wanted to provide a more &quot;classic LISPy looking&quot; example to dispel the FUD floating around that &quot;you can do closures in Clojure but it is hard/a hack/forced&quot;.. oh man, it is the only language I know of which FORCES you to have thread safe mutable closures!</description>
		<content:encoded><![CDATA[<p>Sorry, just to clarify, your posting is not the problem (I just realized my comment might make it sound like I am implying that), Your example is perfectly fine and thread safe of course, etc.. but others are linking to it stating things like &#8220;see.. Clojure has got a problem with thread safety.. look at the explanation here&#8221;. OMG, that is not what the guy said!!! sigh!. Just wanted to provide a more &#8220;classic LISPy looking&#8221; example to dispel the FUD floating around that &#8220;you can do closures in Clojure but it is hard/a hack/forced&#8221;.. oh man, it is the only language I know of which FORCES you to have thread safe mutable closures!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Erick</title>
		<link>http://etherplex.org/archives/71/comment-page-1#comment-2658</link>
		<dc:creator>Erick</dc:creator>
		<pubDate>Tue, 30 Aug 2011 05:47:26 +0000</pubDate>
		<guid isPermaLink="false">http://etherplex.org/?p=71#comment-2658</guid>
		<description>I am in a bit of a crusade trying to clarify some points about closures and Clojure (lol!). I ran into a series of posts last night, like this one, which while technically true, sound misleading. What Rich is trying to say, is that allowing a closure to have a mutable value trapped inside is a ticking bomb.. in ANY language.. Clojure forces you to stop and think before providing you with the gun to shoot yourself in the foot (and yes, you can but you have to try hard to do so :-) . So, yes you can have closures, yes they can be closed over a mutable something, but, like with any other mutable state in Clojure it should be done with an atom or ref. Like this:

(defn accumulator
  []
    (let [x (atom 0)]
      (fn []
        (swap! x inc))))

user&gt; (def my-accumulator (accumulator))
#’user/my-accumulator
user&gt; (my-accumulator)
1
user&gt; (my-accumulator)
2
user&gt; (my-accumulator)
3

That is a vanilla 101 closure in Clojure. What is forced or magic about that. I don&#039;t know about your favourite LISP, but if it allows you to define closures over mutable things that are not thread safe, it might be prettier to write, but sure as hell it will be a lot more &quot;fun&quot; to debug ;-)</description>
		<content:encoded><![CDATA[<p>I am in a bit of a crusade trying to clarify some points about closures and Clojure (lol!). I ran into a series of posts last night, like this one, which while technically true, sound misleading. What Rich is trying to say, is that allowing a closure to have a mutable value trapped inside is a ticking bomb.. in ANY language.. Clojure forces you to stop and think before providing you with the gun to shoot yourself in the foot (and yes, you can but you have to try hard to do so :-) . So, yes you can have closures, yes they can be closed over a mutable something, but, like with any other mutable state in Clojure it should be done with an atom or ref. Like this:</p>
<p>(defn accumulator<br />
  []<br />
    (let [x (atom 0)]<br />
      (fn []<br />
        (swap! x inc))))</p>
<p>user&gt; (def my-accumulator (accumulator))<br />
#’user/my-accumulator<br />
user&gt; (my-accumulator)<br />
1<br />
user&gt; (my-accumulator)<br />
2<br />
user&gt; (my-accumulator)<br />
3</p>
<p>That is a vanilla 101 closure in Clojure. What is forced or magic about that. I don&#8217;t know about your favourite LISP, but if it allows you to define closures over mutable things that are not thread safe, it might be prettier to write, but sure as hell it will be a lot more &#8220;fun&#8221; to debug ;-)</p>
]]></content:encoded>
	</item>
</channel>
</rss>

