<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Higher-Order</title>
	<atom:link href="http://blog.higher-order.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.higher-order.net</link>
	<description>topics: functional programming, concurrency, web-development, REST, dynamic languages</description>
	<lastBuildDate>Sun, 24 Jan 2010 14:21:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>VersionManager</title>
		<link>http://blog.higher-order.net/2010/01/22/version-manager/</link>
		<comments>http://blog.higher-order.net/2010/01/22/version-manager/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 15:10:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[namespacing]]></category>
		<category><![CDATA[with]]></category>

		<guid isPermaLink="false">http://blog.higher-order.net/?p=450</guid>
		<description><![CDATA[[update: First, my apologies to jdalton, my post was not meant to derail Fusebox, merely to show a different approach to similar problems. ]
I read a post on Ajaxian about Fusebox, a JavaScript library which is described as:
[...] The problem is that frameworks / libraries / third-party scripts may overwrite native methods or each other&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>[update: First, my apologies to jdalton, my post was not meant to derail Fusebox, merely to show a different approach to similar problems. ]</p>
<p>I read a <a href="http://ajaxian.com/archives/de-fusing-javascript-natives-with-the-fusebox">post on Ajaxian</a> about <a href="http://github.com/jdalton/fusebox">Fusebox</a>, a JavaScript library which is described as:</p>
<blockquote><p>[...] The problem is that frameworks / libraries / third-party scripts may overwrite native methods or each other&#8217;s custom methods resulting in unpredictable outcomes. Fusebox, a limited version of the sandboxing component found in FuseJS, avoids these issues by creating sandboxed natives which can be extended without affecting the document natives.</p></blockquote>
<p>I think Fusebox is a good project. The code in this blog post shows a different approach which in some situations may be more useful and in others, it may not.</p>
<p>With Fusebox script developers avoid polluting the globals by writing their scripts using FuseBox and its wrappers. E.g, you write code with a &#8220;Fusebox prefix&#8221; like this:<br />
<code>
<pre>
  var fb = Fusebox();
  fb.Array.prototype.hai = function() {
    return fb.String("Oh hai, we have " + this.length + " items.");
  };
  fb.Array(1,2,3).hai(); // "Oh hai, we have 3 items."
  typeof window.Array.prototype.hai; // undefined

// like the native Array constructor the sandboxed constructor will return [ , , ]
  var a = fb.Array(3);
  // equiv to square-bracket notation [3]
  var b = fb.Array.create(3);
  // converting a native array to a sandboxed array
  var c = fb.Array.fromArray([1, 2, 3]);
</pre>
<p></code></p>
<p>That immediately reminded be of some work I&#8217;ve have been doing with colleague Jimmy Junker at Trifork (<tt>jju at trifork com</tt>) motivated by the following problem:</p>
<blockquote><p> In portal environments where multiple portlets want to use different JavaScript libraries or different versions of the same JavaScript libraries, you are very likely to run in to problems since almost all libraries (except later YUI versions) are designed to live in the global namespace.</p></blockquote>
<p>After a brainstorming session we developed a simple <em>prototype</em> (no pun intended), uninspiringly named &#8220;VersionManager&#8221;, with which we succeeded in loading two different versions of the PrototypeJS library. With VersionManager you can write code like this:<br />
<code>
<pre>
with (VersionManager.version("1.6.1")) {
//"1.6.1" refers to prototype which must have been loaded
  console.log("abcdaba".gsub("a","42"));// console.logs '42bcd42b42'
  console.log(typeof Object.extend);// console.logs 'function'
  $A([1,2,3])._each(function(x){
    console.log(x);
  });// console.logs '1','2','3'
}
VersionManager.clear();//otherwise previous version is lingering...
try {
  console.log(typeof "".gsub);
//console.logs 'function' <= this is generic delegating proxy function
  console.log("abcdaba".gsub("a","42"));//throws error
} catch (e) {
  console.log(e);
  //TypeError: "attempt call to delegate with no version defined (see documentation)"
}
console.log(typeof Object.extend);// console.logs 'undefined'
console.log(typeof $A);// console.logs 'undefined'
</pre>
<p></code></p>
<p>So version manager lets you load several libraries on the page, and sandboxes changes made to globals. By telling VersionManager which version you want to use for a particular block you code, you can use each of those libraries, <em>even if they define the same global variables or properties on the prototypes of objects,</em> e.g., <tt>Array.prototype</tt>. </p>
<p> VersionManager also creates sandboxes, but as opposed to Fusebox, what is sandboxed is "changes made to" the built-ins, and global variables defined. Also, the goal is not to avoid extending the prototypes, but almost the opposite: to allow several scripts/libraries that would otherwise conflict to live in the same page without seeing each other, even if they define the same global names or want to extend built-in prototypes in different ways.</p>
<p>With VersionManager you simply write regular user code, but wrap it in a with statement. This means that existing code can easily be rewritten.</p>
<p>The loaded "sandboxed" libraries must adhere to a few syntactic and semantic constraints.<br />
For an example, see a sandboxed version of prototypejs here</p>
<p><a href="http://github.com/krukow/versionmanager/blob/master/test/assets/prototype.js">Transformed prototypejs</a></p>
<p>The transformation applied to prototypejs is very simple and can be done automatically (i.e., it is easy to write a program that performs this script-transformation for you). It is a bit technical, but it results in is adding a declaration with-statement "header" at the beginning and a "footer" and the end. In fact, we are writing a program that transforms any JavaScript program/library into an equivalent one that adheres to these constraints. </p>
<p>An alpha version is on github. It is a proof-of-concept that shows that the fundamental approach seems to work. </p>
<p>jdalton pointed out a couple of things :</p>
<ul>
<li>You may run into problems with minifiers given that your code is wrapped in 'with'. However, you can minify the code first, and then wrap it.</li>
<li>It doesn't track changes to event or elements.</li>
</ul>
<p>So far, we've tested it only in latest Firefox and Safari, but I see no reason why it couldn't work in other recent browsers.  We have sucessfully loaded prototypejs in a sandbox, and managed to run all prototypejs unit tests successfully inside the sandbox.</p>
<p>Github project: <a href="http://github.com/krukow/versionmanager">http://github.com/krukow/versionmanager</a></p>
<p>/Karl</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.higher-order.net/2010/01/22/version-manager/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Joy of Clojure</title>
		<link>http://blog.higher-order.net/2010/01/14/the-joy-of-clojure/</link>
		<comments>http://blog.higher-order.net/2010/01/14/the-joy-of-clojure/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 10:54:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Clojure]]></category>
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.higher-order.net/?p=444</guid>
		<description><![CDATA[In case you haven&#8217;t noticed there is a very interesting Clojure book coming out, titled &#8220;The Joy of Clojure,&#8221;  written by two very interesting authors that anyone hanging out in the Clojure community should know: Chris Houser and Michael Fogus. 
As an appetizer, the first chapter is available for free:
Clojure—A Lisp for the Java [...]]]></description>
			<content:encoded><![CDATA[<p>In case you haven&#8217;t noticed there is a very interesting Clojure book coming out, titled &#8220;<a href="http://www.manning.com/fogus/">The Joy of Clojure</a>,&#8221;  written by two very interesting authors that anyone hanging out in the Clojure community should know: <a href="http://twitter.com/chrishouser">Chris Houser</a> and <a href="http://twitter.com/fogus">Michael Fogus</a>. </p>
<p>As an appetizer, the first chapter is available for free:</p>
<p><a href="http://www.manning.com/fogus/Fogus_MEAP_Ch1.pdf">Clojure—A Lisp for the Java Virtual Machine</a></p>
<p>I&#8217;ve read the first chapter and the book looks very promising! To quote the last paragraph of chapter one:</p>
<blockquote><p>We&#8217;ve talked a little about how this book will go beyond what Clojure is to why it&#8217;s designed the way it is and how that design can be exploited through idioms that will help you think in Clojure. So lets stop talking about what this book will do and get on with the doing.<br />
Fasten your seat belts.</p></blockquote>
<p>I&#8217;ve fastened my seat belt and ordered my copy <img src='http://blog.higher-order.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.higher-order.net/2010/01/14/the-joy-of-clojure/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Please help funding Clojure</title>
		<link>http://blog.higher-order.net/2009/12/15/please-help-funding-clojure/</link>
		<comments>http://blog.higher-order.net/2009/12/15/please-help-funding-clojure/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 05:32:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.higher-order.net/?p=439</guid>
		<description><![CDATA[Rich Hickey, creator of Clojure:
As should be obvious, Clojure is a labor of love on my part. Started as a self-funded sabbatical project, Clojure has come to occupy me far more than full-time. However, Clojure does not have institutional or
corporate sponsorship, and was not, and is not, the by-product of
another profitable endeavor. I have borne [...]]]></description>
			<content:encoded><![CDATA[<p>Rich Hickey, creator of Clojure:</p>
<blockquote><p>As should be obvious, Clojure is a labor of love on my part. Started as a self-funded sabbatical project, Clojure has come to occupy me far more than full-time. However, Clojure does not have institutional or<br />
corporate sponsorship, and was not, and is not, the by-product of<br />
another profitable endeavor. I have borne the costs of developing<br />
Clojure myself, but 2009 is the last year I, or my family, can bear<br />
that. </p></blockquote>
<p>I would be such a shame if development were to slow down or stop completely because of such a small amount of money&#8230; So, please donate to the project. </p>
<p>See details,</p>
<p><a href="http://groups.google.com/group/clojure/t/cc77df25e98ce46b">http://groups.google.com/group/clojure/t/cc77df25e98ce46b</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.higher-order.net/2009/12/15/please-help-funding-clojure/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Review: Ext JS 3.0 Cookbook</title>
		<link>http://blog.higher-order.net/2009/12/09/review-ext-js-3-0-cookbook/</link>
		<comments>http://blog.higher-order.net/2009/12/09/review-ext-js-3-0-cookbook/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 15:14:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.higher-order.net/?p=411</guid>
		<description><![CDATA[Intro and motivation. While my recent blogging activity and interests have been (and are) about Clojure, I am still very much interested in, and actively programming, JavaScript. That is why I immediately accepted when Amit Sharma from Packt Publishing asked me to review the new book Ext JS 3.0 cookbook by Jorge Ramon (find links [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Intro and motivation</strong>. While my recent blogging activity and interests have been (and are) about Clojure, I am still very much interested in, and actively programming, JavaScript. That is why I immediately accepted when Amit Sharma from Packt Publishing asked me to review the new book Ext JS 3.0 cookbook by Jorge Ramon (<a href="#disclaimer">find links below <sup>1</sup></a>).</p>
<p>Historically, I have been known for advocating the Ext JS framework for RIA development in controlled environments since it is very general and customizable, and because it lifts the abstraction level much higher than when developing at the DOM level with many other frameworks. Let me emphasize: You <em>do</em> need to understand the DOM, event models, and browsers, but that you don&#8217;t have to think at this low level constantly when developing (this discussion is the topic for another blog post, based on discussions we had at Trifork).</p>
<p>One of the problems with Ext JS is that is has perhaps the steepest of learning curves among JavaScript frameworks, and while the API documentation is good, it doesn&#8217;t tell you much about the programming model and idioms, or how structure and modularize the combining of components and containers into applications. Fortunately, the Ext JS developers have provide a large number of examples of how to use the various Ext JS functions. Unfortunately the examples are code only: they don&#8217;t come with explanations of why things are coded as they are. So it is your job as a developer to extract this information from the source code, and decide which bits you can and can&#8217;t use in your production code. Depending on you ability and willingness to read the examples and the Ext JS source code itself, you may find this more or less viable learning route.</p>
<p>To me it is obvious that there is need for one or more Ext JS books. In fact, I am contemplating considering starting-to-think-about writing something myself &#8230; <img src='http://blog.higher-order.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><strong>Review</strong>. I won&#8217;t cover the structure of the book other than to say it is organized as a number of recipes, each showing how to build a mini ExtJS-based GUI for a certain use-case. Other reviewers have already <a href="#other_reviews">covered recipe structure in detail</a>. Instead, I will take a step back and give you my opinion about what you&#8217;ll get and what you won&#8217;t get with this book, i.e., it&#8217;s all about expectations.</p>
<p>(Anyway, the best way to get a feel of the form and flow of the book is to read a sample chapter. I found the following online; there are many more topics in the book, but the form is the same:</p>
<p><a href="http://www.packtpub.com/files/8709-ext-js-cookbook-sample-chapter-3-load-validate-and-submit-forms.pdf">http://www.packtpub.com/files/8709-ext-js-cookbook-sample-chapter-3-load-validate-and-submit-forms.pdf</a>)</p>
<p>Ext JS 3.0 markets itself as: &#8220;Quick answers to common problems. 109 great recipes for building impressive rich internet applications using the Ext JS JavaScript library.&#8221; As other reviewers have mentioned, the book successfully does  what it sets out to do: It gives you concrete detailed solutions to a number of problems selected by the author; no less, but also no more. There is code that comes with the book, to you don&#8217;t have to type in the examples from the book. The book is very code-heavy: as you can see from the sample chapter, a 60-80% to 40-20% code-to-text ratio. </p>
<p><b>Aspects I liked</b>.<br />
The book is focused: apart from the preface which is good, there isn&#8217;t a long ramble introduction wasting my time. It is into the meat already from Chapter 1, page 1. Good.</p>
<p>It is fairly complete in that parts of ExtJS that cover making UIs, here I wasn&#8217;t missing anything in particular. </p>
<p>It does what it sets out to do, and it is well organized, well written and consistent. </p>
<p>There are fairly concise sections &#8220;There&#8217;s more&#8230;&#8221; and &#8220;How it works&#8230;&#8221; which discuss aspects of the code just described. </p>
<p>The &#8220;How to do it&#8230;&#8221; sections are is step-by-step, <em>and</em> explaining what each step does.</p>
<p><b>Aspects I didn&#8217;t like so much</b>.<br />
It is not the kind of book I, personally, was looking for: I don&#8217;t want a <em>recipe</em> book, since such a book would often be too focused on too great detail, too much boiler-plate code, and things I could have figured out myself. I would prefer a book that was would focus on concepts, real-world problems, density and concision of code examples, common errors, how to organize and structure large applications, development techniques and best practices (the latter it does to some extent). </p>
<p><b>Conclusion</b>. As mentioned I think this book delivers what it promises.  I am happy to have a copy lying around. I think I will use it, and I do think it is valuable as a guide to the extensive Ext JS example code. </p>
<p>If you are a complete beginner or quite advanced user, I do not think this book is of that much value to you. If you are at an intermediate level, having played around with Ext JS and JavaScript, but not built anything too serious, I recommend it.  </p>
<p>If you are looking for a more conceptual book, obviously this book is not for you. If you a looking for a concrete step-by-step, &#8220;hands-on&#8221; book, this book is for you.</p>
<p>If you would like something to complement the Ext JS Sample code, this book is for you. If you can understand and generalize the Ext JS sample code, this book is not for you.</p>
<p>Hope that helps <img src='http://blog.higher-order.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><a name="disclaimer"><sup>1</sup><b>Disclaimer</b></a>:  I agree with Giles Bowkett that many times blogs aren&#8217;t the best source of truthful, objective information (aka &#8220;<a href="http://gilesbowkett.blogspot.com/2009/12/blogs-are-godless-communist-bullshit.html">Godless Communist Bullshit</a>&#8220;). It is your job as a responsible thinking reader to consider if there are hidden agendas and economical interests that might cause the publisher to not present the truth, the whole truth and nothing but the truth. The people at Packt Publishing are smart, they understand this. They&#8217;ve found a bunch of bloggers and asked them to do reviews (see below).</p>
<p>I want to make it completely visible that I am participating in Packt Publishing&#8217;s affiliate program that gives me a payment, not for the review, but for each purchase originating from this site. </p>
<p>My manifesto here is:  while there is value in money, I value integrity more. I have striven to give as fair and objective a review as I possibly can (I hope you can see that; if not, let me know).</p>
<p><strong>This is the <a href="http://www.packtpub.com/ext-js-3-0-cookbook/mid/011209p0gzfz?utm_source=blog.higher-order.net&#038;utm_medium=affiliate&#038;utm_content=blog&#038;utm_campaign=mdb_001692">Ext JS 3.0 cookbook</a> link to use if you want to support me</strong>. </p>
<p><a href="http://www.packtpub.com/ext-js-3-0-cookbook/mid/011209p0gzfz?utm_source=blog.higher-order.net&#038;utm_medium=affiliate&#038;utm_content=blog&#038;utm_campaign=mdb_001692">http://www.packtpub.com/ext-js-3-0-cookbook/mid/011209p0gzfz?utm_source=blog.higher-order.net&#038;utm_medium=affiliate&#038;utm_content=blog&#038;utm_campaign=mdb_001692<br />
</a></p>
<p><strong>Otherwise use this link</strong>.</p>
<p><a href="http://www.packtpub.com/ext-js-3-0-cookbook">http://www.packtpub.com/ext-js-3-0-cookbook</a></p>
<p><a name="other_reviews"><b>Other reviews.</b></a></p>
<p>Josh Holmes. I agree with everything Josh is saying, and I don&#8217;t want to repeat it here.<br />
<a href="http://www.joshholmes.com/blog/2009/11/19/ReviewOfExtJS30Cookbook.aspx">http://www.joshholmes.com/blog/2009/11/19/ReviewOfExtJS30Cookbook.aspx</a></p>
<p>Arthur Kay. I agree with most of what Arthur says. I don&#8217;t agree with everything Arthur is saying: I don&#8217;t think there is much to learn for experienced ExtJS developers.</p>
<p><a href="http://blog.akawebdesign.com/index.php/2009/11/20/book-review-extjs-3-0-cookbook">http://blog.akawebdesign.com/index.php/2009/11/20/book-review-extjs-3-0-cookbook</a></p>
<p>ExtJS Forum response: It is obviously very positive since it is posted to Ext JS enthusiasts.</p>
<p><a href="http://www.extjs.com/forum/showthread.php?t=79850">http://www.extjs.com/forum/showthread.php?t=79850</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.higher-order.net/2009/12/09/review-ext-js-3-0-cookbook/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clojure circuit breaker</title>
		<link>http://blog.higher-order.net/2009/11/23/clojure-circuit-breaker/</link>
		<comments>http://blog.higher-order.net/2009/11/23/clojure-circuit-breaker/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 06:22:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.higher-order.net/?p=398</guid>
		<description><![CDATA[[Update Jan 1., 2010: A couple of people have been linking and twitting this, so I've made the blog entry match the current Clojure version at github. Code works in the 'new' branch of Clojure: tested with commit 3ae9e8874d43f9fd37e59bb7ea8cce0f85bac101.
There is support for creating several circuit breakers wrapping given functions].
As an exercise in Clojure, I&#8217;ve implemented [...]]]></description>
			<content:encoded><![CDATA[<p>[Update Jan 1., 2010: A couple of people have been linking and twitting this, so I've made the blog entry match the current Clojure version at github. Code works in the 'new' branch of Clojure: tested with commit 3ae9e8874d43f9fd37e59bb7ea8cce0f85bac101.</p>
<p>There is support for creating several circuit breakers wrapping given functions].</p>
<p>As an exercise in Clojure, I&#8217;ve implemented a mostly functional version of Michael Nygaard&#8217;s stability pattern &#8220;Circuit breaker&#8221; (<a title="http://www.pragprog.com/titles/mnee/release-it" href="http://www.pragprog.com/titles/mnee/release-it">http://www.pragprog.com/titles/mnee/release-it</a>).</p>
<p>The implementation uses the new constructs <a href="http://www.assembla.com/wiki/show/clojure/Datatypes">deftype</a> and <a href="http://www.assembla.com/wiki/show/clojure/Protocols">defprotocol</a> (which are looking really interesting to me!). The implementation maintains a single identity named &#8220;state&#8221; which is an atom holding the current state (open, closed, initial-half-open or pending-half-open).</p>
<p>More on deftype and defprotocol can be found <a href="http://groups.google.com/group/clojure/tree/browse_frm/thread/a59165f208f594cb/cf144fd0ab4de13f?hl=en&#038;rnum=21&#038;_done=%2Fgroup%2Fclojure%2Fbrowse_frm%2Fthread%2Fa59165f208f594cb%2F8e60316b5894f36b%3Fhl%3Den%26#doc_330c230e8dc857a9">here</a>.</p>
<p>Here is the code that defines the states and the state transitions (requires JavaScript; otherwise use <a href="http://gist.github.com/267168">this link</a>). Notice how the events &#8216;on-before-call&#8217;, &#8216;on-success&#8217; and &#8216;on-error&#8217; are implemented as a protocol defining state-transition functions. I really like the features Rich is adding to Clojure &#8211; to me it makes modeling so much more natural (with an OO-background), while retaining the benefits of functional programming.</p>
<p><script src="http://gist.github.com/267168.js?file=circuit+breaker+states.clj"></script></p>
<p>Notice how this snipplet defines the transition functions, the four states as well as an &#8220;abstract&#8221; implementation of the state transitions. The abs-transitions can be used as default implementations when extending the protocol to the state-types. In Java, this would correspond to an interface (CircuitBreakerTransitions), an abstract super-class implementing the interface, and four immutable classes (the states). However, Clojures deftype and defprotocol does not create a type-hierarchy, and is much more dynamic (you can always define how a given type extends to a protocol &#8211; it is not fixed at type definition time). Here is how I extended my types to the protocol: </p>
<p><script src="http://gist.github.com/267169.js?file=extending.clj"></script><br />
(<a href="http://gist.github.com/267169">http://gist.github.com/267169</a>)</p>
<p>This defines a completely functional transition-system between the four states. I think this reads really well, for example consider the on-error event in the closed state: this checks to see if the states fail-count is equal to the threshold defined in the policy, if so it transitions to the open state, recording the current time <tt>(OpenState p (System/currentTimeMillis))</tt> (preserving the policy); otherwise it transitions to a closed state with a higher fail-count. </p>
<p>The actual circuit breaker uses these transition functions:</p>
<p><script src="http://gist.github.com/267172.js?file=logic.clj"></script><br />
(<a href="http://gist.github.com/267172">http://gist.github.com/267172</a>)</p>
<p>The state of a circuit breaker is an atom (the only mutable construct in this example). The function wrap takes a function f and returns a &#8220;wrapped&#8221; version of f, which implements the circuit breaker functionality around f. </p>
<p>Notice how dead-simple this is to test:</p>
<p><script src="http://gist.github.com/267173.js?file=test+logic.clj"></script><br />
(<a href="http://gist.github.com/267173">http://gist.github.com/267173</a>)</p>
<p>Full Source:<br />
<a href="http://github.com/krukow/clojure-circuit-breaker">http://github.com/krukow/clojure-circuit-breaker</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.higher-order.net/2009/11/23/clojure-circuit-breaker/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Identity, State and Values</title>
		<link>http://blog.higher-order.net/2009/10/26/identity-state-and-values/</link>
		<comments>http://blog.higher-order.net/2009/10/26/identity-state-and-values/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 11:50:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.higher-order.net/?p=391</guid>
		<description><![CDATA[Please watch this video carefully at least once:
http://www.infoq.com/presentations/Value-Identity-State-Rich-Hickey
It is pretty hard not to agree, isn&#8217;t it&#8230;  Give in now.
]]></description>
			<content:encoded><![CDATA[<p>Please watch this video carefully at least once:</p>
<p><a href="http://www.infoq.com/presentations/Value-Identity-State-Rich-Hickey">http://www.infoq.com/presentations/Value-Identity-State-Rich-Hickey</a></p>
<p>It is pretty hard not to agree, isn&#8217;t it&#8230;  <a href="http://clojure.org">Give in</a> now.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.higher-order.net/2009/10/26/identity-state-and-values/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Understanding Clojure&#8217;s PersistentHashMap (deftwice&#8230;)</title>
		<link>http://blog.higher-order.net/2009/09/08/understanding-clojures-persistenthashmap-deftwice/</link>
		<comments>http://blog.higher-order.net/2009/09/08/understanding-clojures-persistenthashmap-deftwice/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 15:29:55 +0000</pubDate>
		<dc:creator>krukow</dc:creator>
				<category><![CDATA[Clojure]]></category>
		<category><![CDATA[persistent data structures]]></category>
		<category><![CDATA[PersistentHashMap]]></category>

		<guid isPermaLink="false">http://blog.higher-order.net/?p=386</guid>
		<description><![CDATA[[sept. 8th, 21:22: fixed a +/- 1 error]
In a previous post, I gave a high-level description of how Clojure&#8217;s PersistentVector is implemented. While the code has changed, the description was high-level enough that the explanations still hold (although some code snipplets don&#8217;t correspond to what&#8217;s in Git master.) 
In this post, I&#8217;ll try to explain [...]]]></description>
			<content:encoded><![CDATA[<p>[sept. 8th, 21:22: fixed a +/- 1 error]</p>
<p>In a previous post, I gave a high-level description of <a href="http://blog.higher-order.net/?p=233">how Clojure&#8217;s PersistentVector is implemented.</a> While the code has changed, the description was high-level enough that the explanations still hold (although some code snipplets don&#8217;t correspond to what&#8217;s in <a href="http://github.com/richhickey/clojure/tree/master">Git master</a>.) </p>
<p>In this post, I&#8217;ll try to explain (also at a high level) how <code>clojure.lang.PersistentHashMap</code> works internally. Reading the mentioned post on PersistentVector is helpful as some of the concepts are the same (e.g., bit-partitioning). </p>
<p><strong>Persistent</strong><br />
PersistentHashMap is a persistent version of the classical hash table data structure. Persistent means that the data structure is immutable, yet has efficient non-destructive operations that correspond to the operations on the classical hash table. E.g., put(K,V) in hash table corresponds to a side-effect free function assoc(P, K, V) which computes from P a new PersistentHashMap P&#8217; which is like P except that it maps key K to value V. The word &#8220;efficient&#8221; means &#8220;on par&#8221; with their mutating counterparts. For Clojure data structures, Rich tries to make them within 1-4 of the Java data structure operations; and read-only operations can even be faster than Java&#8217;s. Later I will cover &#8216;transients&#8217; which are a new optimization that make &#8220;batch&#8221; operations faster.</p>
<p><strong>Array-mapped hash trie</strong><br />
In his paper <a href="http://lampwww.epfl.ch/papers/idealhashtrees.pdf">Ideal Hash Tries</a> Phil Bagwell describes a data structure &#8220;Hash Array Mapped Trie&#8221; which is an efficient implementation of a Hash Tree, based on a combination of hashing and the <a href="http://en.wikipedia.org/wiki/Trie">trie data structure.</a> Hash Array Mapped Tries, are not persistent or immutable. What Rich did was create a persistent version of Bagwell&#8217;s data structure; <tt>clojure.lang.PersistentHashMap</tt>.</p>
<p><strong>PersistentHashMap basic idea</strong><br />
PersistentHashMap (PHM) maintains a very-wide tree, each node having up to 32 children. Each node is a concrete implementation of a static inner interface, <tt>INode</tt>, and there are five implementations of this interface: EmptyNode, LeafNode, FullNode, HashCollisionNode, BitmapIndexedNode. I&#8217;ll only cover EmptyNode, LeafNode and BitmapIndexedNode; the latter being where most of the interesting stuff happens. </p>
<p>The <tt>INode</tt> interface look like this:</p>
<pre><tt><span class="keyword">static</span><span class="normal"> </span><span class="keyword">interface</span><span class="normal"> </span><span class="classname">INode</span><span class="cbracket">{</span>
<span class="normal">    INode </span><span class="function">assoc</span><span class="symbol">(</span><span class="type">int</span><span class="normal"> shift</span><span class="symbol">,</span><span class="normal"> </span><span class="type">int</span><span class="normal"> hash</span><span class="symbol">,</span><span class="normal"> Object key</span><span class="symbol">,</span><span class="normal"> Object val</span><span class="symbol">,</span><span class="normal"> Box addedLeaf</span><span class="symbol">);</span>
<span class="normal">    LeafNode </span><span class="function">find</span><span class="symbol">(</span><span class="type">int</span><span class="normal"> hash</span><span class="symbol">,</span><span class="normal"> Object key</span><span class="symbol">);</span>
<span class="normal">    </span><span class="comment">//I've left out a few methods</span>
<span class="cbracket">}</span>
</tt></pre>
<p>The <tt>assoc</tt> method &#8220;adds&#8221; a new key-value pair to the map. The <tt>find</tt> method searches for the Leaf-node holding a key.</p>
<p>An EmptyNode simply represents the empty hash map. LeafNodes are also pretty simple; they hold the actual entries stored in map. </p>
<p>The root node of the tree is initially an EmptyNode. When assoc is called on EmptyNode, it returns a new LeafNode, which the key-value pair. So EmptyNode &#8220;becomes&#8221; a LeafNode with assoc. In turn, a LeafNode typically &#8220;becomes&#8221; a BitmapIndexedNode with assoc.  We will go into details with BitmapIndexedNode, but first we need to understand&#8230;</p>
<p><strong>Bit-partitioning of hash-codes</strong><br />
When PHM assocs a key object K with value object V, it first computes the hashCode of K, just as a hash-table would. The hash code of K yields an int, which has a 32-bit representation in Java (as I explained in <a href="http://blog.higher-order.net/?p=233">the post on PersistentVector</a>). Here are some example bit representations of numbers:</p>
<p><img src="http://blog.higher-order.net/files/clj/bitpartitioning1.png" alt="PersistentHashMap ilustration 1" /></p>
<p>The trick that PHM uses is to partition this bit representation in to blocks of 5-bits, represented with colors in the above example. Each block corresponds to a &#8220;level&#8221; in the tree structure; for example, the right-most green block corresponds to root-level, and the orange block corresponds to the children of the root. Exactly what &#8220;corresponds&#8221; means is described below.  Levels are multiples of 5. I.e., the root level is level 0, the children of the root are level 5, the grand-children of the root are level 10, etc. Note that a block of five bits corresponds to a number in the range 0-31.  </p>
<p>The reason that levels are multiples of five is the following: You have a bit-representation of a hash-code and you are interested in a particular block corresponding to a level <tt>n</tt>. You obtain this number in two steps: first move the block of bits to the right, until it is the right-most block. Then null-out all other bits except this right-most block. The is done with two bit-operations: you simply right-shift the bits with the level <tt>n</tt> and then do a bit-wise &#8216;and&#8217; (<tt>&amp;</tt>) with the pattern <tt>00..11111</tt>. For example, suppose you want the block corresponding to level 5 (the orange block) of the number 1258 (binary: <tt>[00001][00111][01010]</tt>). You right shift with the level, 5, which is <tt>[00000][00001][00111]</tt>; then do the null&#8217;ing, yielding <tt>[00111]</tt>, which was exactly the orange block of 1258.</p>
<p>The following function does this.</p>
<pre><tt><span class="keyword">static</span><span class="normal"> </span><span class="type">int</span><span class="normal"> </span><span class="function">mask</span><span class="symbol">(</span><span class="type">int</span><span class="normal"> hash</span><span class="symbol">,</span><span class="normal"> </span><span class="type">int</span><span class="normal"> shift</span><span class="symbol">)</span><span class="cbracket">{</span>
<span class="normal">	</span><span class="keyword">return</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">hash </span><span class="symbol">&gt;&gt;&gt;</span><span class="normal"> shift</span><span class="symbol">)</span><span class="normal"> </span><span class="symbol">&amp;</span><span class="normal"> </span><span class="number">0x01f</span><span class="symbol">;</span>
<span class="cbracket">}</span></tt></pre>
<p><strong>Illustrating the tree structure</strong><br />
I&#8217;ll use the following picture (adapted from one of Rich&#8217;s slides).<br />
<center><br />
<img src="http://blog.higher-order.net/files/clj/persistenthashmap1.png" alt="PersistentHashMap ilustration 1" /><br />
</center></p>
<p>The colored nodes are <tt>BitmapIndexedNode</tt>s and have between 2 and 31 children (should they get a 32nd child, they become <tt>FullNode</tt>s). A naive implementation of <tt>BitmapIndexedNode</tt> might be the following: use an int variable, <tt>level</tt>, to denote the level that this node lives in, and allocate a full 32 element array of INode references for the children. To add a new child: lookup the index via the bit-block corresponding to the level, i.e. given a hashCode <tt>hash</tt> for the child, and given the level, call <tt>mask(hash, level)</tt> to get the index in range [0, 31]. But this strategy wastes a lot of memory: each node has a full 32 element array where most entries are simply <tt>null</tt>, i.e., if there are 4 children there are 28 null references which are just wasting space.</p>
<p>The hard part is to only use as much space as is needed for each <tt>BitmapIndexedNode</tt>, i.e., if a <tt>BitmapIndexedNode</tt> has <tt>N</tt> children it maintains an array of size <tt>N</tt>. But then we can&#8217;t use <tt>mask(hash,shift)</tt> as the index into the array since it returns a number in the range [0,31] and we need a number only in range [0, <tt>N</tt>). </p>
<p><strong>bitpos</strong><br />
So we need a function to map numbers in range [0, 31] to indexes in range [0, <tt>N</tt>). The function has to be fast constant time, since we are using it to find the child of a node from a hash code, which we will do at each level in the tree. The function is a composition of two functions: <tt>bitpos</tt> and <tt>index</tt>. Function <tt>bitpos</tt> maps numbers [0, 31] to powers of two, i.e., numbers that have a binary representation of the form:<br />
<center><tt>{10<sup>n</sup> | n &gt;= 0}</tt>.</center><br />
For example, <tt>bitpos(7)</tt> in binary is 10000000. We always look at <tt>bitpos(x)</tt> in binary form. Function <tt>index</tt> we return to shortly.</p>
<pre><tt><span class="keyword">static</span><span class="normal"> </span><span class="type">int</span><span class="normal"> </span><span class="function">bitpos</span><span class="symbol">(</span><span class="type">int</span><span class="normal"> hash</span><span class="symbol">,</span><span class="normal"> </span><span class="type">int</span><span class="normal"> shift</span><span class="symbol">)</span><span class="cbracket">{</span>
<span class="normal">    </span><span class="keyword">return</span><span class="normal"> </span><span class="number">1</span><span class="normal"> </span><span class="symbol">&lt;&lt;</span><span class="normal"> </span><span class="function">mask</span><span class="symbol">(</span><span class="normal">hash</span><span class="symbol">,</span><span class="normal"> shift</span><span class="symbol">);</span>
<span class="cbracket">}</span></tt></pre>
<p><strong>bitmap</strong><br />
Each <tt>BitmapIndexedNode</tt> also maintains an int variable <tt>bitmap</tt> which we also look at in binary form. The <tt>bitmap</tt> tells us how many children this node has, and also what their indexes are in the child array. All this is encoded into one <tt>int</tt> variable! How? The bit-map has a binary representation, e.g.,<br />
<center><tt>00000000000000010000000010000101</tt></center><br />
The number of children is the number of <tt>1</tt>&#8217;s in the binary representation. If the <tt>n</tt>th bit in <tt>bitmap</tt> is <tt>1</tt> (counting right-to-left, starting with position 0) then there is a child with index <tt>n</tt>. So to check if a child exists for a certain hash-code: first compute <tt>mask(hash,shift)</tt> to get the bit-block and number in range [0, 31]. Then compute <tt>bitpos</tt> of this. You then have a number of form <tt>10<sup>n</sup></tt>. Now match that with the <tt>bitmap</tt> to check if there is a <tt>1</tt> in the <tt>n</tt>&#8216;th position; this match is simply a bit-wise and, &#8216;&amp;&#8217;, with <tt>bitpos</tt>. We&#8217;d better take an example.  </p>
<p>Suppose we are at level 5, and looking up an element with hash-code 1258. Suppose also the bitmap-indexed node has four children, with <tt>bitmap</tt><br />
<tt>bitmap =<sub>binary rep</sub> 00000000000000010000000010000101</tt></p>
<p>Now check if there is a child for hashCode 1258 at this level:</p>
<p><tt>mask(1258,5) = 7</tt> (i.e., binary <tt>00111</tt> as we saw before).</p>
<p><tt>bitpos(7) =<sub>binary rep</sub> 10000000</tt></p>
<p><tt>00000000000000010000000010000101 &amp;</tt><br />
<tt>00000000000000000000000010000000 = 1</tt></p>
<p>Which means that the child exists. Now what is its index? This is  where the <tt>index</tt> function comes into play&#8230;</p>
<p><strong>index</strong><br />
This is the final piece of bit-trickery, I promise <img src='http://blog.higher-order.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  The index of a child is the number of <tt>1</tt>&#8217;s to the right of the child&#8217;s <tt>bitpos</tt> in the bit map. In our example above, the index corresponding to hash code 1258 would be 2, since there are two <tt>1</tt>&#8217;s to the right of <tt>10000000</tt> in the <tt>bitmap</tt>.  Now the trick is that on many processors there is an efficient instruction called CTPOP which counts the number of ones in the bit representation of an integer (CTPOP is &#8220;count (bit) population&#8221;). Note that if we subtract 1 from the bitpos, <tt>10<sup>n</sup></tt>, we get <tt>01<sup>n</sup></tt>, then binary &#8216;and&#8217; with the bit map gives us the same bit map, but where only the <tt>1</tt>&#8217;s to the right of <tt>bitpos</tt> are present. If we do a CTPOP on this, we get the index. Hence, </p>
<pre><tt><span class="keyword">final</span><span class="normal"> </span><span class="type">int</span><span class="normal"> </span><span class="function">index</span><span class="symbol">(</span><span class="type">int</span><span class="normal"> bit</span><span class="symbol">)</span><span class="cbracket">{</span>
<span class="normal">    </span><span class="keyword">return</span><span class="normal"> Integer</span><span class="symbol">.</span><span class="function">bitCount</span><span class="symbol">(</span><span class="normal">bitmap </span><span class="symbol">&amp;</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">bit </span><span class="symbol">-</span><span class="normal"> </span><span class="number">1</span><span class="symbol">));</span>
<span class="cbracket">}</span></tt></pre>
<p><strong>To be continued&#8230;</strong><br />
From this you should be able to understand how find works. In combines all this:</p>
<pre><tt><span class="keyword">final</span><span class="normal"> </span><span class="keyword">static</span><span class="normal"> </span><span class="keyword">class</span><span class="normal"> </span><span class="classname">BitmapIndexedNode</span><span class="normal"> </span><span class="keyword">implements</span><span class="normal"> INode</span><span class="cbracket">{</span>
<span class="normal">    </span><span class="keyword">final</span><span class="normal"> </span><span class="type">int</span><span class="normal"> bitmap</span><span class="symbol">;</span>
<span class="normal">    </span><span class="keyword">final</span><span class="normal"> INode</span><span class="symbol">[]</span><span class="normal"> nodes</span><span class="symbol">;</span>
<span class="normal">    </span><span class="keyword">final</span><span class="normal"> </span><span class="type">int</span><span class="normal"> shift</span><span class="symbol">;</span>
<span class="normal">    </span><span class="comment">//some stuff left out</span>
<span class="normal">    </span><span class="keyword">static</span><span class="normal"> </span><span class="type">int</span><span class="normal"> </span><span class="function">bitpos</span><span class="symbol">(</span><span class="type">int</span><span class="normal"> hash</span><span class="symbol">,</span><span class="normal"> </span><span class="type">int</span><span class="normal"> shift</span><span class="symbol">)</span><span class="cbracket">{</span>
<span class="normal">	</span><span class="keyword">return</span><span class="normal"> </span><span class="number">1</span><span class="normal"> </span><span class="symbol">&lt;&lt;</span><span class="normal"> </span><span class="function">mask</span><span class="symbol">(</span><span class="normal">hash</span><span class="symbol">,</span><span class="normal"> shift</span><span class="symbol">);</span>
<span class="normal">    </span><span class="cbracket">}</span>
<span class="normal">    </span>
<span class="normal">    </span><span class="keyword">final</span><span class="normal"> </span><span class="type">int</span><span class="normal"> </span><span class="function">index</span><span class="symbol">(</span><span class="type">int</span><span class="normal"> bit</span><span class="symbol">)</span><span class="cbracket">{</span>
<span class="normal">	</span><span class="keyword">return</span><span class="normal"> Integer</span><span class="symbol">.</span><span class="function">bitCount</span><span class="symbol">(</span><span class="normal">bitmap </span><span class="symbol">&amp;</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">bit </span><span class="symbol">-</span><span class="normal"> </span><span class="number">1</span><span class="symbol">));</span>
<span class="normal">    </span><span class="cbracket">}</span>
<span class="normal">    </span><span class="comment">//...some methods left out</span>
<span class="normal">    </span>
<span class="normal">   </span><span class="keyword">public</span><span class="normal"> LeafNode </span><span class="function">find</span><span class="symbol">(</span><span class="type">int</span><span class="normal"> hash</span><span class="symbol">,</span><span class="normal"> Object key</span><span class="symbol">)</span><span class="cbracket">{</span>
<span class="normal">       </span><span class="type">int</span><span class="normal"> bit </span><span class="symbol">=</span><span class="normal"> </span><span class="function">bitpos</span><span class="symbol">(</span><span class="normal">hash</span><span class="symbol">,</span><span class="normal"> shift</span><span class="symbol">);</span>
<span class="normal">       </span><span class="keyword">if</span><span class="symbol">((</span><span class="normal">bitmap </span><span class="symbol">&amp;</span><span class="normal"> bit</span><span class="symbol">)</span><span class="normal"> </span><span class="symbol">!=</span><span class="normal"> </span><span class="number">0</span><span class="symbol">)</span>
<span class="normal">	   </span><span class="cbracket">{</span>
<span class="normal">	       </span><span class="keyword">return</span><span class="normal"> nodes</span><span class="symbol">[</span><span class="function">index</span><span class="symbol">(</span><span class="normal">bit</span><span class="symbol">)].</span><span class="function">find</span><span class="symbol">(</span><span class="normal">hash</span><span class="symbol">,</span><span class="normal"> key</span><span class="symbol">);</span>
<span class="normal">	   </span><span class="cbracket">}</span>
<span class="normal">       </span><span class="keyword">else</span>
<span class="normal">	   </span><span class="keyword">return</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">;</span>
<span class="normal">   </span><span class="cbracket">}</span>
<span class="cbracket">}</span>
</tt></pre>
<p>In part 2 we look at how assoc works&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.higher-order.net/2009/09/08/understanding-clojures-persistenthashmap-deftwice/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Clojure talks in Copenhagen and Aarhus &#8211; now with Azul Systems Clojure demo</title>
		<link>http://blog.higher-order.net/2009/08/17/clojure-talks-in-copenhagen-and-aarhus-now-with-azul-systems-clojure-demo/</link>
		<comments>http://blog.higher-order.net/2009/08/17/clojure-talks-in-copenhagen-and-aarhus-now-with-azul-systems-clojure-demo/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 10:45:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Clojure]]></category>
		<category><![CDATA[free events]]></category>
		<category><![CDATA[JAOO]]></category>

		<guid isPermaLink="false">http://blog.higher-order.net/?p=343</guid>
		<description><![CDATA[Upcoming events: I am giving a talk on Clojure in Copenhagen and Aarhus &#8211; this is the first chance for a dcug meetup (though also non-dcug members are invited). The events are after work and free &#8211; there will even be free sandwiches, compliments of Trifork  

Monday, Sept. 7th in Aarhus, location: Trifork. Registration: [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Upcoming events</strong>: I am giving a talk on Clojure in Copenhagen and Aarhus &#8211; this is the first chance for a <a href="http://www.clojure.dk">dcug</a> meetup (though also non-dcug members are invited). The events are after work and free &#8211; there will even be free sandwiches, compliments of Trifork <img src='http://blog.higher-order.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<ul>
<li>Monday, Sept. 7th in Aarhus, location: Trifork. Registration: <a href="https://secure.trifork.com/aarhus-2009/freeevent/register.m?eventOID=2129">https://secure.trifork.com/aarhus-2009/freeevent/register.m?eventOID=2129</a></li>
<li>Wednesday, Sept. 9th in Copenhagen, location: Trifork Cph. Registration: <a href="https://secure.trifork.com/aarhus-2009/freeevent/register.m?eventOID=2130">https://secure.trifork.com/aarhus-2009/freeevent/register.m?eventOID=2130</a>.</li>
<li>Free Clojure workshop at JAOO &#8211; featuring Rich Hickey. October 6, 2009, 17.30 &#8211; 19.30. Registration: <a href="https://secure.trifork.com/aarhus-2009/freeevent/register.m?eventOID=2093">https://secure.trifork.com/aarhus-2009/freeevent/register.m?eventOID=2093</a></li>
</ul>
<p><strong>Abstract for Aarhus/Cph talks.</strong><br />
Clojure is..</p>
<p>&#8230; a new functional, dynamic programming language for Java Virtual Machines. The primary novelty of Clojure is its strong focus on and support for in-process concurrency: a unique concurrency model, combining a notion of persistent (i.e., immutable, fast) data structures, with a lock-free concurrency model. This simplifies concurrent programming greatly and has good scalability properties.<br />
Influenced by LISP and Haskell, Clojure supports pure, lazy functional programming and has a powerful macro system which makes extending the language to support DSLs easy and powerful.</p>
<p>This talk..</p>
<p>&#8230; is split in three parts. In the first part, Clojure is introduced for those who don&#8217;t know the language. There is so much to cover that this will be a fast tour with pointers to more information, but we will emphasize the unique aspects of the language.</p>
<p>In the second part we go into more depth regarding the implementation of persistent (and transient data structures) &#8211; &#8220;the secret sauce of Clojure&#8221; <img src='http://blog.higher-order.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>In the third part we get to see Clojure in action running on some very cool technology &#8211; a unique opportunity! Azul Systems (www.azulsystems.com) has promised to make available one of their large Vega 3 compute appliances (864 core, 368 GB memory, let&#8217;s go concurrent). We will explore how the Clojure concurrency model fares in practice, scaling a demo of a parallel Traveling Sales Problem algorithm. We will also push the implementation to its limits in a high-contention demo. Great fun!</p>
<hr />
Remember: Active until August 31st:<br />
DCUG members can now get a 15% discount on JAOO tickets.<br />
Simply click the banner below, choose &#8220;register here&#8221; and use the promotion code: dcug</p>
<p><a href="http://trifork-affiliate-program.com/scripts/click.php?a_aid=dcug&amp;a_bid=93ef8336&amp;desturl=https%3A%2F%2Fsecure.trifork.com%2Faarhus-2009%2Fregistration%2F"><img title="JAOO Aarhus 2009 - The Conference for the 360 Degree software developer" src="http://trifork-affiliate-program.com/accounts/default1/banners/Jaoo_webbanner234X60_49okt.jpg" alt="JAOO Aarhus 2009 - The Conference for the 360 Degree software developer" width="234" height="60" /></a><img style="border:0" src="http://trifork-affiliate-program.com/scripts/imp.php?a_aid=dcug&amp;a_bid=93ef8336" alt="" width="1" height="1" /></ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.higher-order.net/2009/08/17/clojure-talks-in-copenhagen-and-aarhus-now-with-azul-systems-clojure-demo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JAOO 2009 discount (for Clojure users ;-)</title>
		<link>http://blog.higher-order.net/2009/07/13/jaoo-discount/</link>
		<comments>http://blog.higher-order.net/2009/07/13/jaoo-discount/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 05:25:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Clojure]]></category>

		<guid isPermaLink="false">http://blog.higher-order.net/?p=331</guid>
		<description><![CDATA[I suggested to the JAOO program committee that the JAOO Aarhus 2009 conference should have a concurrency track. Their reply was &#8220;that&#8217;s a good idea &#8211; you are hosting it!&#8221; &#8211; this is how Trifork works  
The good thing is that the track host gets to pick (or at least propose) speakers for the [...]]]></description>
			<content:encoded><![CDATA[<p>I suggested to the JAOO program committee that the <a href="http://trifork-affiliate-program.com/scripts/click.php?a_aid=dcug&amp;a_bid=7441e314&amp;desturl=http%3A%2F%2Fjaoo.dk%2Faarhus-2009%2F">JAOO Aarhus 2009 conference<img style="border:0" src="http://trifork-affiliate-program.com/scripts/imp.php?a_aid=dcug&amp;a_bid=7441e314" alt="" width="1" height="1" /></a> should have a concurrency track. Their reply was &#8220;that&#8217;s a good idea &#8211; you are hosting it!&#8221; &#8211; this is how Trifork works <img src='http://blog.higher-order.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>The good thing is that the track host gets to pick (or at least propose) speakers for the track (the bad thing is that it entails some work!). Given my recent interest in Clojure and since he is such a great speaker, I immediately suggested we invite Rich Hickey. I&#8217;ll write a bit more on the program in an upcoming post, but right now I just want to mention that via the Danish Clojure Users&#8217; Group I am now a JAOO affiliate, and anyone signing up via dcug gets a 15% discount on JAOO tickets.</p>
<p>To sign up, follow this procedure:</p>
<ol>
<li>To join dcug, simply register as a dcug user at </a><a href="http://www.clojure.dk">http://www.clojure.dk.</a></li>
<li>Read about the discount here: <a href="http://clojure.higher-order.net/?p=32">http://clojure.higher-order.net/?p=32</a></li>
</ol>
<p>As an appetizer, check out <a href="http://clojure.higher-order.net/?p=28">this post</a> at dcug.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.higher-order.net/2009/07/13/jaoo-discount/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Monty hall and Bayesian probability theory</title>
		<link>http://blog.higher-order.net/2009/06/23/monty-hall-and-bayesian-probability-theory/</link>
		<comments>http://blog.higher-order.net/2009/06/23/monty-hall-and-bayesian-probability-theory/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 06:26:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[model view controller]]></category>

		<guid isPermaLink="false">http://blog.higher-order.net/?p=316</guid>
		<description><![CDATA[Jeff Atwood discusses the &#8220;Monty hall&#8221; problem. I made a comment about why I believe people&#8217;s intuition is often wrong when presented with the problem: I believe it is due to the way probability theory is taught in schools and universities. The notion of probability simply as an extension of classical logic as presented by [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.codinghorror.com/blog/archives/001278.html">Jeff Atwood discusses the &#8220;Monty hall&#8221; problem</a>. I made a comment about why I believe people&#8217;s intuition is often wrong when presented with the problem: I believe it is due to the way probability theory is taught in schools and universities. The notion of probability simply as an extension of classical logic as presented by Edwin Jaynes matches intuition much more closely. To solve the Monty Hall problem we need three simple principles (which apply to a <strong>wide</strong> range of problems):</p>
<ul>
<li> Probability is about information. Forget notions of &#8220;random&#8221; experiments, e.g., the outcome of throwing a die is about the laws of physics &#8211; there is no magical randomness built into the die causing it to come up with each side equally often &#8220;in the long run&#8221; (what ever that means). If we know the laws of physics and have enough information about the experiment we might assign other probabilities to the outcomes. This means that <em>if new information is obtained the probability changes</em>!</li>
</ul>
<ul>
<li>In the name of science, we shall not make any unwarranted conclusions, and we promise to use all the information at hand, not deliberately discarding information (for what ever reason).</li>
</ul>
<ul>
<li>We use the laws of probability theory.</li>
</ul>
<p>The first point is where the problem lies. In fact the probabilities are just a formalization of the <em>information</em> we have. This is why we always condition the probability on some information e.g., P(A | I) is the probability of proposition A given the information I.</p>
<p>Let&#8217;s solve Monty Hall using the principles presented in Jaynes&#8217; book. Notice that these techniques are completely general and can solve many different problems of this nature; the key in Monty Hall is not to make any unjustified conclusions, but simply <em>consider all the information at hand!</em></p>
<p>Lets name the doors A, B and C, and let us assume that we initially selected door A (the argument applies for any other initial choice as well). Let us write I for the information we have initially (before opening any doors) &#8211; this includes the rules of the game. More precisely I is the conjunction of statements:</p>
<p>* We have chosen door A.</p>
<p>* The host knows where the car is, and may only open a door that does not contain the car.</p>
<p>* The host may not open the door we selected (A) (even if it does not contain the car).</p>
<p>We formalize the information I in probability equations below. Let us consider three mutually exclusive and exhaustive propositions</p>
<p>A = the car is behind door A;</p>
<p>B = the car is behind door B;</p>
<p>C = the car is behind door C</p>
<p>By the principle of indifference, given only the initial information, I, we have</p>
<p>P(A | I) = P(B | I) = P(C | I) = 1/3</p>
<p>Notice also that so far intuition is completely clear.</p>
<p>Let us now assume that the host opens door C. Let H be the statement:</p>
<p>H = the host opened door C</p>
<p>(the argument is similar for any other choice). The important point here is that we are given additional information beyond our prior information, I. Now let us first derive the correct solution, we then analyze where peoples intuition usually goes wrong.</p>
<p>By the rules of probability theory (specifically Bayes theorem) we have</p>
<p>P(A | HI) = P(A|I) P(H | AI)/P(H|I)</p>
<p>The quantity P(A|HI) is what we are interested in: the probability of the car being behind door A given <em>all the information available to us</em>.</p>
<p>We know P(A|I) is 1/3 so we can focus on P(H|AI) and P(H|I) &#8211; notice these are both probabilities about the host&#8217;s actions &#8211; probabilities that are very relevant to the problem (by the equation above), but also probabilities that most people would not consider to analyse (because probability is taught the way it is)! The former is the probability of the host opening door C given the car is behind door A; the latter is the a-priori probability of the host opening door C given only the information I. The former, P(H|AI), is the most simple: given we know that the car is behind door A what is the probability of the host opening door C. Since we have no information about which door the host opens when the car is behind the door we selected, the principle of indifference applies and we have:</p>
<p>P(H|AI) = P(not H|AI) = 1/2</p>
<p>Now consider P(H|I): the a-priori probability of the host opening door C. Since propositions A, B and C are mutually exclusive and exhaustive, the rules of probability theory imply</p>
<p>P(H | I) = P(H | AI)P(A|I) + P(H | BI)P(B | I) + P(H | CI)P(C | I)</p>
<p>We know that P(H | CI) = 0 because by information I, the host may not open door C if the car is behind door C.  We already figured out P(H | AI) and P(A|I) so the first term is 1/2*1/3 = 1/6. Also we know P(B | I) = 1/3. Now we can focus on P(H | BI): the probability of host opening door C when the car is behind door B and we have chosen door A. But here the rules of the game are clear: the host <strong>must</strong> open door C in this case since he may not open A and may not reveal the car. Hence P(H | BI) = 1. We get:</p>
<p>P(H | I) = 1/6 + 1*1/3 = 3/6 = 1/2.</p>
<p>We now have all the quantities needed to calculate P(A | HI):</p>
<p>P(A | HI) = 1/3 * [(1/2)/(1/2)] = 1/3. Hence P(B | HI) = 2/3 and we should switch doors!</p>
<p>The technique is completely mechanical. I have not used any clever arguments or mathematical ingenuity: only the rules of the game, the principle of indifference and the laws of probability theory. All calculations could be performed by a machine with these inputs.</p>
<p>So where does our intuition go wrong? Two places, I believe. First because of schooling our intuition tells us that somehow we can only reason about &#8220;random&#8221; events. Instead we should focus on <em>information</em> e.g., &#8216;the car is placed &#8220;at random&#8221; behind a door&#8217; versus &#8220;we are given the information that there is a car behind one door and sheep behind the two others.&#8221; Once we free ourselves to consider probabilities as expressing the information we have available, it is natural that the probabilities change when we obtain more information. This is crucial. The second, I believe, is a consequence of the first: most people seem to identify the following two statements in the Monty Hall problem:</p>
<p>* the host opens door C</p>
<p>* the car is not behind door C</p>
<p>But these two pieces of information are not equivalent when we know the rules of the game (i.e. given our prior information). Considering them equal would violate our commitment to science, to be objective and to consider <em>all</em> the information at hand <img src='http://blog.higher-order.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>To illustrate let us analyse a variant of Monty Hall where &#8220;H&#8221; means the latter instead.</p>
<p>Given this alternate piece of information, our first step is still to apply Bayes theorem so:</p>
<p>P(A | HI) = P(A|I) P(H | AI)/P(H|I)</p>
<p>We still have P(A|I) = 1/3. P(H|I) is the probability that the car is not behind door C given our initial information. Since H = not C, and since A, B, C are mutually exclusive and exhaustive, the rules of probability theory imply</p>
<p>P(H | I) = P(not C|I) = P(A or B|I) = P(A|I) + P(B|I) = 2/3</p>
<p>Now P(H | AI) is calculated by classical logic: since A implies not C we have P(H | AI) = 1. Hence:</p>
<p>P(A | HI) = 1/3 * 1/[2/3] = 1/2</p>
<p>Which is the false result that most people&#8217;s intuition prefer. This is the correct conclusion, but for a different game than Monty Hall, namely the game without a host where you simply get an additional information about where the car is not.</p>
<p>Notice that we easily analysed both variants of the game using simple probability theory, and in its interpretation as an extension of classical logic, the intuition follows along nicely. The key is to use <em>all the information at hand</em>, not discarding any information that could be of relevance to the problem (i.e. we got the information that host selected C, not that door C had a sheep behind it).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.higher-order.net/2009/06/23/monty-hall-and-bayesian-probability-theory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
