<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">

	<title type="text">Planet Clojure</title>
	
	<link href="http://planet.clojure.in/" />
	<id>http://planet.clojure.in/atom.xml</id>
	<updated>2012-05-30T18:37:55+00:00</updated>
	<generator uri="http://www.planetplanet.org/">http://intertwingly.net/code/venus/</generator>

	<feedburner:info uri="clojure" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><subtitle type="html">Planet Clojure is a meta blog that collects posts from the blogs of various Clojure hackers and contributors.</subtitle><logo>http://clojure.org/file/view/clojure-icon.gif</logo><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/clojure" /><feedburner:feedFlare href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2Fclojure" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2Fclojure" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare href="http://www.plusmo.com/add?url=http%3A%2F%2Ffeeds.feedburner.com%2Fclojure" src="http://plusmo.com/res/graphics/fbplusmo.gif">Subscribe with Plusmo</feedburner:feedFlare><feedburner:feedFlare href="http://www.thefreedictionary.com/_/hp/AddRSS.aspx?http%3A%2F%2Ffeeds.feedburner.com%2Fclojure" src="http://img.tfd.com/hp/addToTheFreeDictionary.gif">Subscribe with The Free Dictionary</feedburner:feedFlare><feedburner:feedFlare href="http://www.bitty.com/manual/?contenttype=rssfeed&amp;contentvalue=http%3A%2F%2Ffeeds.feedburner.com%2Fclojure" src="http://www.bitty.com/img/bittychicklet_91x17.gif">Subscribe with Bitty Browser</feedburner:feedFlare><feedburner:feedFlare href="http://www.live.com/?add=http%3A%2F%2Ffeeds.feedburner.com%2Fclojure" src="http://tkfiles.storage.msn.com/x1piYkpqHC_35nIp1gLE68-wvzLZO8iXl_JMledmJQXP-XTBOLfmQv4zhj4MhcWEJh_GtoBIiAl1Mjh-ndp9k47If7hTaFno0mxW9_i3p_5qQw">Subscribe with Live.com</feedburner:feedFlare><feedburner:feedFlare href="http://mix.excite.eu/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2Fclojure" src="http://image.excite.co.uk/mix/addtomix.gif">Subscribe with Excite MIX</feedburner:feedFlare><feedburner:feedFlare href="http://www.webwag.com/wwgthis.php?url=http%3A%2F%2Ffeeds.feedburner.com%2Fclojure" src="http://www.webwag.com/images/wwgthis.gif">Subscribe with Webwag</feedburner:feedFlare><feedburner:feedFlare href="http://www.podcastready.com/oneclick_bookmark.php?url=http%3A%2F%2Ffeeds.feedburner.com%2Fclojure" src="http://www.podcastready.com/images/podcastready_button.gif">Subscribe with Podcast Ready</feedburner:feedFlare><feedburner:feedFlare href="http://www.wikio.com/subscribe?url=http%3A%2F%2Ffeeds.feedburner.com%2Fclojure" src="http://www.wikio.com/shared/img/add2wikio.gif">Subscribe with Wikio</feedburner:feedFlare><feedburner:feedFlare href="http://www.dailyrotation.com/index.php?feed=http%3A%2F%2Ffeeds.feedburner.com%2Fclojure" src="http://www.dailyrotation.com/rss-dr2.gif">Subscribe with Daily Rotation</feedburner:feedFlare><entry>
		<title type="html" />
		<link href="http://feedproxy.google.com/~r/clojure/~3/LAteEpd8sAo/literate-programming-in-clojure-table.html" />
		<id>tag:blogger.com,1999:blog-3908276794795362019.post-2045914209941115115</id>
		<updated>2012-05-30T14:00:10+00:00</updated>
		<content type="html">&lt;br /&gt;&lt;div id="content" style="font-family: Times, serif; font-size: 16px;"&gt;&lt;h1 class="title" style="text-align: center;"&gt;  Literate Programming in Clojure&lt;/h1&gt;&lt;hr /&gt;&lt;div id="table-of-contents"&gt;&lt;h2&gt;  Table of Contents&lt;/h2&gt;&lt;div id="text-table-of-contents"&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.blogger.com/blogger.g?blogID=3908276794795362019#sec-1"&gt;1 Literate programming in clojure using org-mode babel&lt;/a&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.blogger.com/blogger.g?blogID=3908276794795362019#sec-1-1"&gt;1.1 Literate programming&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.blogger.com/blogger.g?blogID=3908276794795362019#sec-1-2"&gt;1.2 Org-mode-babel&lt;/a&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.blogger.com/blogger.g?blogID=3908276794795362019#sec-1-2-1"&gt;1.2.1 Setting up org-mode-babel with clojure&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.blogger.com/blogger.g?blogID=3908276794795362019#sec-1-2-2"&gt;1.2.2 Interacting with clojure code.&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.blogger.com/blogger.g?blogID=3908276794795362019#sec-1-2-3"&gt;1.2.3 Exporting to html&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.blogger.com/blogger.g?blogID=3908276794795362019#sec-1-3"&gt;1.3 the org-file&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="outline-2" id="outline-container-1"&gt;&lt;h2 id="sec-1"&gt;  &lt;span class="section-number-2"&gt;1&lt;/span&gt; Literate programming in clojure using org-mode babel&lt;/h2&gt;&lt;div class="outline-text-2" id="text-1"&gt;In this post I'll first show a double setup of org-mode babel-clojure with both inferior-lisp and slime, and then I will show how to use org-babel-clojure for literate programming.&lt;/div&gt;&lt;div class="outline-3" id="outline-container-1-1"&gt;&lt;h3 id="sec-1-1"&gt;  &lt;span class="section-number-3"&gt;1.1&lt;/span&gt; Literate programming&lt;/h3&gt;&lt;div class="outline-text-3" id="text-1-1"&gt;Who doesn't know this situation: You have to modify someone others code but you have no clue what this code should do. Searching around the (often barely documentation) doesn't help much either, because it is often not clear what intention the author had with the code, or why he implemented it that way. &lt;a href="http://de.wikipedia.org/wiki/Literate_programming"&gt;Literate programming&lt;/a&gt; does not only help others reading your code, but it helps you as well,because&lt;br /&gt;&lt;ul&gt;&lt;li&gt;writing down your intention and explaining it makes it easier for you to code it&lt;/li&gt;&lt;li&gt;it helps you to be clear about your design decisions&lt;/li&gt;&lt;li&gt;writing it down intented to be read by others makes you to automatically write code of better quality&lt;/li&gt;&lt;/ul&gt;In Literate programming, you mix the explanation of the programm and the source code in one file. The source code can be automatically extracted. This is called tangling. It is also possible to evaluate the code while you are in the document.&lt;/div&gt;&lt;/div&gt;&lt;div class="outline-3" id="outline-container-1-2"&gt;&lt;h3 id="sec-1-2"&gt;  &lt;span class="section-number-3"&gt;1.2&lt;/span&gt; Org-mode-babel&lt;/h3&gt;&lt;div class="outline-text-3" id="text-1-2"&gt;&lt;a href="http://orgmode.org/worg/org-contrib/babel/"&gt;Babel&lt;/a&gt; is a part of &lt;a href="http://orgmode.org/"&gt;org-mode&lt;/a&gt; that is a full featured literate programming program. Being part of org-mode, it is also able to be exported into a variety of formats including latex and html. I am using it to write my series of 'Porting PAIP to clojure'. Each blog-post is just a .org file which gets exported to html and uploaded on blogger. Here is the setup:&lt;/div&gt;&lt;div class="outline-4" id="outline-container-1-2-1"&gt;&lt;h4 id="sec-1-2-1"&gt;  &lt;span class="section-number-4"&gt;1.2.1&lt;/span&gt; Setting up org-mode-babel with clojure&lt;/h4&gt;&lt;div class="outline-text-4" id="text-1-2-1"&gt;Fortunately, clojure is a supported language of org-mode, but it's documentation is outdated. So add following to your .emacs file:&lt;br /&gt;&lt;pre class="src src-elisp" style="background-color: black; border: 1pt solid rgb(174, 189, 204); color: white; font-family: courier, monospace; font-size: 14px; overflow: auto; padding: 5pt;"&gt;(&lt;span style="color: cyan;"&gt;require&lt;/span&gt; '&lt;span style="color: aquamarine;"&gt;ob&lt;/span&gt;)&lt;br /&gt;(&lt;span style="color: cyan;"&gt;require&lt;/span&gt; '&lt;span style="color: aquamarine;"&gt;ob-tangle&lt;/span&gt;)&lt;br /&gt;(add-to-list 'org-babel-tangle-lang-exts '(&lt;span style="color: lightsalmon;"&gt;"clojure"&lt;/span&gt; . &lt;span style="color: lightsalmon;"&gt;"clj"&lt;/span&gt;))&lt;br /&gt;&lt;br /&gt;(org-babel-do-load-languages&lt;br /&gt; 'org-babel-load-languages&lt;br /&gt; '((emacs-lisp . t)&lt;br /&gt;   (clojure . t)))&lt;br /&gt;(&lt;span style="color: cyan;"&gt;require&lt;/span&gt; '&lt;span style="color: aquamarine;"&gt;ob-clojure&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;(&lt;span style="color: cyan;"&gt;defun&lt;/span&gt; &lt;span style="color: lightskyblue;"&gt;org-babel-execute:clojure&lt;/span&gt; (body params)&lt;br /&gt;  &lt;span style="color: lightsalmon;"&gt;"Evaluate a block of Clojure code with Babel."&lt;/span&gt;&lt;br /&gt;  (concat &lt;span style="color: lightsalmon;"&gt;"=&amp;gt; "&lt;/span&gt;&lt;br /&gt;          (&lt;span style="color: cyan;"&gt;if&lt;/span&gt; (fboundp 'slime-eval)&lt;br /&gt;              (slime-eval `(swank:interactive-eval-region ,body))&lt;br /&gt;           (&lt;span style="color: cyan;"&gt;if&lt;/span&gt; (fboundp 'lisp-eval-string)&lt;br /&gt;             (lisp-eval-string body)&lt;br /&gt;              (&lt;span style="color: pink; font-weight: bold;"&gt;error&lt;/span&gt; &lt;span style="color: lightsalmon;"&gt;"You have to start a clojure repl first!"&lt;/span&gt;)))))&lt;br /&gt;&lt;br /&gt;(setq org-src-fontify-natively t)&lt;br /&gt;(setq org-confirm-babel-evaluate nil)&lt;br /&gt;(setq org-export-babel-evaluate nil)&lt;br /&gt;(setq org-src-window-setup 'current-window)&lt;br /&gt;(setq inferior-lisp-program &lt;span style="color: lightsalmon;"&gt;"lein repl"&lt;/span&gt;)&lt;br /&gt;&lt;/pre&gt;(I assume you have a recent org-mode installed) It will work with either inferior lisp using lein repl, which has the advantage that you can run it without a project.clj file, or with M-x clojure-jack-in, which gives you the goddies of slime with clojure.&lt;br /&gt;I have also written a few lines to make the exported html look better and defined a skeleton to quickly insert the first lines in the .org file. If you type C-S-f4, you will be prompted for the title and the content of the skeleton will be inserted.&lt;br /&gt;&lt;pre class="src src-elisp" style="background-color: black; border: 1pt solid rgb(174, 189, 204); color: white; font-family: courier, monospace; font-size: 14px; overflow: auto; padding: 5pt;"&gt;  (&lt;span style="color: cyan;"&gt;define-skeleton&lt;/span&gt; &lt;span style="color: lightskyblue;"&gt;org-skeleton&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: lightsalmon;"&gt;"Header info for a emacs-org file."&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: lightsalmon;"&gt;"Title: "&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: lightsalmon;"&gt;"#+TITLE:"&lt;/span&gt; str &lt;span style="color: lightsalmon;"&gt;" \n"&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: lightsalmon;"&gt;"#+AUTHOR: Maik Schünemann\n"&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: lightsalmon;"&gt;"#+email: maikschuenemann@gmail.com\n"&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: lightsalmon;"&gt;"#+STARTUP:showall\n"&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: lightsalmon;"&gt;"-----"&lt;/span&gt;&lt;br /&gt; )&lt;br /&gt;(global-set-key [C-S-f4] 'org-skeleton)&lt;br /&gt;&lt;br /&gt;(setq org-export-html-style-extra &lt;span style="color: lightsalmon;"&gt;"&amp;lt;style type=\"text/css\"&amp;gt;pre {\n    border: 1pt solid #AEBDCC;\n   color:white;\n background-color: #000000;\n     padding: 5pt;\n font-family: courier, monospace;\n        font-size: 90%;\n        overflow:auto;\n  } &amp;lt;/style&amp;gt;"&lt;/span&gt;)&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="outline-4" id="outline-container-1-2-2"&gt;&lt;h4 id="sec-1-2-2"&gt;  &lt;span class="section-number-4"&gt;1.2.2&lt;/span&gt; Interacting with clojure code.&lt;/h4&gt;&lt;div class="outline-text-4" id="text-1-2-2"&gt;Start a repl first. Either via M-x run-lisp or with M-x clojure-jack-in. Note, if you use the former, the result of the code won't get inserted in the .org file after evaluation.&lt;br /&gt;To write some clojure-code, type the following (may be good to define a kbd-macro to speed this up)&lt;br /&gt;&lt;pre class="example" style="background-color: black; border: 1pt solid rgb(174, 189, 204); color: white; font-family: courier, monospace; font-size: 14px; overflow: auto; padding: 5pt;"&gt;#+begin_src clojure :results output :exports both&lt;br /&gt;(def six (+ 1 2 3))&lt;br /&gt;#+end_src&lt;br /&gt;&lt;/pre&gt;If you place your cursor between the begin&lt;sub&gt;src&lt;/sub&gt; and end&lt;sub&gt;src&lt;/sub&gt; and type C-c C-c, you will see the following:&lt;br /&gt;&lt;pre class="example" style="background-color: black; border: 1pt solid rgb(174, 189, 204); color: white; font-family: courier, monospace; font-size: 14px; overflow: auto; padding: 5pt;"&gt;#+begin_src clojure :results output :exports both&lt;br /&gt; (def six (+ 1 2 3))&lt;br /&gt; #+end_src&lt;br /&gt;&lt;br /&gt;#+RESULTS:&lt;br /&gt;: =&amp;gt; #'user/six&lt;br /&gt;&lt;/pre&gt;Note that the code got evaluated and is now defined in the repl. So if you evaluate the following (either in the file, or in the repl, you will see:&lt;br /&gt;&lt;pre class="example" style="background-color: black; border: 1pt solid rgb(174, 189, 204); color: white; font-family: courier, monospace; font-size: 14px; overflow: auto; padding: 5pt;"&gt;#+begin_src clojure :results output :exports both&lt;br /&gt;six&lt;br /&gt;#+end_src &lt;br /&gt;&lt;br /&gt;#+RESULTS:&lt;br /&gt;: =&amp;gt; 6&lt;br /&gt;&lt;/pre&gt;So you loose nothing of the interactive development you love when coding clojure.&lt;/div&gt;&lt;/div&gt;&lt;div class="outline-4" id="outline-container-1-2-3"&gt;&lt;h4 id="sec-1-2-3"&gt;  &lt;span class="section-number-4"&gt;1.2.3&lt;/span&gt; Exporting to html&lt;/h4&gt;&lt;div class="outline-text-4" id="text-1-2-3"&gt;When you are done, you can export the file to html by typing C-c C-e h or C-c C-e b to see the exported html in your standart browser. If you want the source code to be colorized like you see it in clojure-mode, you need to install the htmlize package (via elpa) The clojure code shown above will export to the following:&lt;br /&gt;&lt;pre class="src src-clojure" style="background-color: black; border: 1pt solid rgb(174, 189, 204); color: white; font-family: courier, monospace; font-size: 14px; overflow: auto; padding: 5pt;"&gt;(&lt;span style="color: cyan;"&gt;def&lt;/span&gt; &lt;span style="color: lightskyblue;"&gt;six&lt;/span&gt; (&lt;span style="color: #eedd82;"&gt;+&lt;/span&gt; 1 2 3))&lt;br /&gt;&lt;/pre&gt;&lt;pre class="example" style="background-color: black; border: 1pt solid rgb(174, 189, 204); color: white; font-family: courier, monospace; font-size: 14px; overflow: auto; padding: 5pt;"&gt;=&amp;gt; #'user/six&lt;br /&gt;&lt;/pre&gt;Cool, nicely colored clojure code in your html-documentation or your blog-post. So This should be enough to get you started using org-mode-babel with clojure for Literate Programming. It is interactive like writing normal clojure code and it helps you to think more clearly about your code.&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="outline-3" id="outline-container-1-3"&gt;&lt;h3 id="sec-1-3"&gt;  &lt;span class="section-number-3"&gt;1.3&lt;/span&gt; the org-file&lt;/h3&gt;&lt;div class="outline-text-3" id="text-1-3"&gt;Here is the org-file that you see right now:&lt;br /&gt;&lt;br /&gt;#+TITLE:Literate Programming in Clojure&lt;br /&gt;#+AUTHOR: Maik Schünemann&lt;br /&gt;#+email: maikschuenemann@gmail.com&lt;br /&gt;#+STARTUP:showall&lt;br /&gt;-----&lt;br /&gt;* Literate programming in clojure using org-mode babel&lt;br /&gt;  In my previous post ... I showed a setup of clojure with org-mode babel using inferior lisp.&lt;br /&gt;  In this post I'll first show a double setup with both inferior-lisp and slime, and then I will&lt;br /&gt;  show how to use org-babel-clojure for literate programming.&lt;br /&gt;** Literate programming&lt;br /&gt;   Who doesn't know this situation:&lt;br /&gt;   You have to modify someone others code but you have no clue what this code should do. Searching&lt;br /&gt;   around the (often barely documentation) doesn't help much either, because it is often not clear&lt;br /&gt;   what intention the author had with the code, or why he implemented it that way.&lt;br /&gt;   [[http://de.wikipedia.org/wiki/Literate_programming][Literate programming]] does not only help others reading your code, but it helps you as well,because&lt;br /&gt;   - writing down your intention and explaining it makes it easier for you to code it&lt;br /&gt;   - it helps you to be clear about your design decisions&lt;br /&gt;   - writing it down intented to be read by others makes you to automatically write code of better quality&lt;br /&gt;   In Literate programming, you mix the explanation of the programm and the source code in one file.&lt;br /&gt;   The source code can be automatically extracted. This is called tangling. It is also possible to evaluate&lt;br /&gt;   the code while you are in the document.&lt;br /&gt;** Org-mode-babel&lt;br /&gt;   [[http://orgmode.org/worg/org-contrib/babel/][Babel]] is a part of [[http://orgmode.org/][org-mode]] that is a full featured literate programming program. Being part of org-mode,&lt;br /&gt;   it is also able to be exported into a variety of formats including latex and html. I am using it to write&lt;br /&gt;   my series of 'Porting PAIP to clojure'. Each blog-post is just a .org file which gets exported to html and&lt;br /&gt;   uploaded on blogger. Here is the setup:&lt;br /&gt;*** Setting up org-mode-babel with clojure&lt;br /&gt;    Fortunately, clojure is a supported language of org-mode, but it's documentation is outdated. So add following&lt;br /&gt;    to your .emacs file:&lt;br /&gt;    #+begin_src elisp&lt;br /&gt;    (require 'ob)&lt;br /&gt;    (require 'ob-tangle)&lt;br /&gt;    (add-to-list 'org-babel-tangle-lang-exts '("clojure" . "clj"))&lt;br /&gt;  &lt;br /&gt;    (org-babel-do-load-languages&lt;br /&gt;     'org-babel-load-languages&lt;br /&gt;     '((emacs-lisp . t)&lt;br /&gt;       (clojure . t)))&lt;br /&gt;    (require 'ob-clojure)&lt;br /&gt;  &lt;br /&gt;    (defun org-babel-execute:clojure (body params)&lt;br /&gt;      "Evaluate a block of Clojure code with Babel."&lt;br /&gt;      (concat "=&amp;gt; "&lt;br /&gt;              (if (fboundp 'slime-eval)&lt;br /&gt;                  (slime-eval `(swank:interactive-eval-region ,body))&lt;br /&gt;               (if (fboundp 'lisp-eval-string)&lt;br /&gt;                 (lisp-eval-string body)&lt;br /&gt;                  (error "You have to start a clojure repl first!")))))&lt;br /&gt;  &lt;br /&gt;    (setq org-src-fontify-natively t)&lt;br /&gt;    (setq org-confirm-babel-evaluate nil)&lt;br /&gt;    (setq org-export-babel-evaluate nil)&lt;br /&gt;    (setq org-src-window-setup 'current-window)&lt;br /&gt;    (setq inferior-lisp-program "lein repl")&lt;br /&gt;    #+end_src&lt;br /&gt;    (I assume you have a recent org-mode installed)&lt;br /&gt;    It will work with either inferior lisp using lein repl, which has the advantage that you can run it without&lt;br /&gt;    a project.clj file, or with M-x clojure-jack-in, which gives you the goddies of slime with clojure.&lt;br /&gt;&lt;br /&gt;    I have also written a few lines to make the exported html look better and defined a skeleton to quickly insert&lt;br /&gt;    the first lines in the .org file. If you type C-S-f4, you will be prompted for the title and the content of the&lt;br /&gt;    skeleton will be inserted.&lt;br /&gt;    #+begin_src elisp&lt;br /&gt;    (define-skeleton org-skeleton&lt;br /&gt;    "Header info for a emacs-org file."&lt;br /&gt;    "Title: "&lt;br /&gt;    "#+TITLE:" str " \n"&lt;br /&gt;    "#+AUTHOR: Maik Schünemann\n"&lt;br /&gt;    "#+email: maikschuenemann@gmail.com\n"&lt;br /&gt;    "#+STARTUP:showall\n"&lt;br /&gt;    "-----"&lt;br /&gt;   )&lt;br /&gt;  (global-set-key [C-S-f4] 'org-skeleton)&lt;br /&gt;&lt;br /&gt;  (setq org-export-html-style-extra "&amp;lt;style type=\"text/css\"&amp;gt;pre {\n    border: 1pt solid #AEBDCC;\n&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;color:white;\n background-color: #000000;\n&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;padding: 5pt;\n&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;font-family: courier, monospace;\n        font-size: 90%;\n        overflow:auto;\n  } &amp;lt;/style&amp;gt;")&lt;br /&gt;    #+end_src&lt;br /&gt;  &lt;br /&gt;*** Interacting with clojure code.&lt;br /&gt;    Start a repl first. Either via M-x run-lisp or with M-x clojure-jack-in. Note, if you use the former, the&lt;br /&gt;    result of the code won't get inserted in the .org file after evaluation.&lt;br /&gt;&lt;br /&gt;    To write some clojure-code, type the following (may be good to define a kbd-macro to speed this up)&lt;br /&gt;    #+begin_example&lt;br /&gt;    #+begin_src clojure :results output :exports both&lt;br /&gt;    (def six (+ 1 2 3))&lt;br /&gt;    #+end_src&lt;br /&gt;    #+end_example&lt;br /&gt;    If you place your cursor between the begin_src and end_src and type C-c C-c, you will see the following:&lt;br /&gt;    #+begin_example&lt;br /&gt;    #+begin_src clojure :results output :exports both&lt;br /&gt;     (def six (+ 1 2 3))&lt;br /&gt;     #+end_src&lt;br /&gt;&lt;br /&gt;    #+RESULTS:&lt;br /&gt;    : =&amp;gt; #'user/six&lt;br /&gt;    #+end_example&lt;br /&gt;    Note that the code got evaluated and is now defined in the repl. So if you evaluate the following (either in&lt;br /&gt;    the file, or in the repl, you will see:&lt;br /&gt;    #+begin_example&lt;br /&gt;    #+begin_src clojure :results output :exports both&lt;br /&gt;    six&lt;br /&gt;    #+end_src&lt;br /&gt;&lt;br /&gt;    #+RESULTS:&lt;br /&gt;    : =&amp;gt; 6&lt;br /&gt;    #+end_example&lt;br /&gt;    So you loose nothing of the interactive development you love when coding clojure.&lt;br /&gt;&lt;br /&gt;*** Exporting to html&lt;br /&gt;    When you are done, you can export the file to html by typing C-c C-e h or C-c C-e b to see the exported&lt;br /&gt;    html in your standart browser.&lt;br /&gt;    If you want the source code to be colorized like you see it in clojure-mode, you need to install the&lt;br /&gt;    htmlize package (via elpa)&lt;br /&gt;    The clojure code shown above will export to the following:&lt;br /&gt;&lt;br /&gt;    #+begin_src clojure :results output :exports both&lt;br /&gt;     (def six (+ 1 2 3))&lt;br /&gt;     #+end_src&lt;br /&gt;&lt;br /&gt;    #+RESULTS:&lt;br /&gt;    : =&amp;gt; #'user/six&lt;br /&gt;    Cool, nicely colored clojure code in your html-documentation or your blog-post.&lt;br /&gt;    So This should be enough to get you started using org-mode-babel with clojure for Literate Programming.&lt;br /&gt;    It is interactive like writing normal clojure code and it helps you to think more clearly about your code.&lt;br /&gt;&lt;br /&gt;** the org-file&lt;br /&gt;   Here is the org-file that you see right now:&lt;br /&gt;   (leaving this part out to avoid infinite file size...)&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div id="postamble" style="font-family: Times, serif; font-size: 16px;"&gt;&lt;div class="date"&gt;Date: 2012-05-30T11:17+0200&lt;/div&gt;&lt;div class="author"&gt;Author: Maik Schünemann&lt;/div&gt;&lt;div class="creator"&gt;Org version 7.8.09 with Emacs version 23&lt;/div&gt;&lt;a href="http://validator.w3.org/check?uri=referer"&gt;Validate XHTML 1.0&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img alt="" height="1" src="https://blogger.googleusercontent.com/tracker/3908276794795362019-2045914209941115115?l=kimavcrp.blogspot.com" width="1" /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=LAteEpd8sAo:xiel2AqVCEw:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=LAteEpd8sAo:xiel2AqVCEw:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/LAteEpd8sAo" height="1" width="1"/&gt;</content>
		<author>
			<name>Maik Schünemann</name>
			<email>noreply@blogger.com</email>
			<uri>http://kimavcrp.blogspot.com/search/label/clojure</uri>
		</author>
		<source>
			<title type="html">Exploring the programming world</title>
			<subtitle type="html">Everytime I come across something that is interesting or cool, I will post it , for you to read and for me as self-reference.</subtitle>
			<link rel="self" href="http://www.blogger.com/feeds/3908276794795362019/posts/default/-/clojure" />
			<id>tag:blogger.com,1999:blog-3908276794795362019</id>
		</source>
	<feedburner:origLink>http://kimavcrp.blogspot.com/2012/05/literate-programming-in-clojure-table.html</feedburner:origLink></entry>

	<entry>
		<title type="html" />
		<link href="http://feedproxy.google.com/~r/clojure/~3/r-ZYJJeyp1A/setting-up-org-mode-babel-with-clojure.html" />
		<id>tag:blogger.com,1999:blog-3908276794795362019.post-5689836547276123388</id>
		<updated>2012-05-30T10:56:30+00:00</updated>
		<content type="html">setting up org-mode babel with clojure           &lt;br /&gt;&lt;div id="preamble"&gt;&lt;/div&gt;&lt;div id="content"&gt;&lt;h2 style="text-align: center;"&gt;  &lt;span style="font-size: x-large;"&gt;Setting up org-mode babel with clojure&lt;/span&gt;&lt;/h2&gt;&lt;div id="table-of-contents"&gt;&lt;h2&gt;  Table of Contents&lt;/h2&gt;&lt;div id="text-table-of-contents"&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.blogger.com/blogger.g?blogID=3908276794795362019#sec-1"&gt;1 Setting up org-mode babel with clojure&lt;/a&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.blogger.com/blogger.g?blogID=3908276794795362019#sec-1-1"&gt;1.1 Setting up babel to work with clojure&lt;/a&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.blogger.com/blogger.g?blogID=3908276794795362019#sec-1-1-1"&gt;1.1.1 A partial Solution&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.blogger.com/blogger.g?blogID=3908276794795362019#sec-1-1-2"&gt;1.1.2 Missing features&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.blogger.com/blogger.g?blogID=3908276794795362019#sec-1-2"&gt;1.2 Final thoughts&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="outline-2" id="outline-container-1"&gt;&lt;h2 id="sec-1"&gt;  &lt;span class="section-number-2"&gt;1&lt;/span&gt; Setting up org-mode babel with clojure&lt;/h2&gt;&lt;div class="outline-text-2" id="text-1"&gt;For my new series 'Porting PAIP to clojure' I plan to write my blogposts as literate programming files   using emacs org-mode with babel set up for clojure. This file can be exportet to html using org-publish-as-html   and posted on my blog.   I was glad to notice that clojure is &lt;a href="http://orgmode.org/worg/org-contrib/babel/languages.html"&gt;one of the supported languages&lt;/a&gt; of babel &lt;/div&gt;&lt;div class="outline-3" id="outline-container-1-1"&gt;&lt;h3 id="sec-1-1"&gt;  &lt;span class="section-number-3"&gt;1.1&lt;/span&gt; Setting up babel to work with clojure&lt;/h3&gt;&lt;div class="outline-text-3" id="text-1-1"&gt;There is a &lt;a href="http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-clojure.html"&gt;Instruction page&lt;/a&gt; for setting up Org-babel-clojure.    However, It is outdated (It &lt;a href="http://lists.gnu.org/archive/html/emacs-orgmode/2012-01/msg00507.html"&gt;depends on the deprecated swank-clojure&lt;/a&gt; and doesn't work with the normal    clojure + emacs setup described &lt;a href="http://dev.clojure.org/display/doc/Getting+Started+with+Emacs"&gt;here&lt;/a&gt;. &lt;/div&gt;&lt;div class="outline-4" id="outline-container-1-1-1"&gt;&lt;h4 id="sec-1-1-1"&gt;  &lt;span class="section-number-4"&gt;1.1.1&lt;/span&gt; A partial Solution&lt;/h4&gt;&lt;div class="outline-text-4" id="text-1-1-1"&gt;After googling a bit I found out that you seem to need &lt;a href="http://nakkaya.com/2010/12/12/using-clojure-with-org-babel-and-inferior-lisp/"&gt;this code&lt;/a&gt; to set it up: &lt;br /&gt;&lt;pre class="example"&gt;(require 'ob)&lt;br /&gt;&lt;br /&gt;(add-to-list 'org-babel-tangle-lang-exts '("clojure" . "clj"))&lt;br /&gt;&lt;br /&gt;(defvar org-babel-default-header-args:clojure &lt;br /&gt;'((:results . "silent") (:tangle . "yes")))&lt;br /&gt;&lt;br /&gt;(defun org-babel-execute:clojure (body params)&lt;br /&gt;"Evaluate a block of Clojure code with Babel."&lt;br /&gt;(lisp-eval-string body)&lt;br /&gt;"Done!")&lt;br /&gt;&lt;br /&gt;(provide 'ob-clojure)&lt;br /&gt;&lt;/pre&gt;There is only one problem: It doesn't work with a clojure-slime session started.     It gives a  Symbol's function definition is void: lisp-eval-string Error.     This seemed very strange to me because apparently no one but me had this error.     I spend a bit time searching where the function (lisp-eval-string) is defined.      The solution (which seems now very naturally to me but costed my half an hour to find out) is that you have     to use clojure with Inferior-lisp instead of slime.     So add the following line to your .emacs &lt;br /&gt;&lt;pre class="example"&gt;(setq inferior-lisp-program "lein repl")&lt;br /&gt;&lt;/pre&gt;Then, running M-x run-lisp starts a repl with the correct classpath set up for you. &lt;br /&gt;When you followed the steps, running C-c C-c in a clojure source blog sends the s-exp to your &lt;b&gt;inferior-lisp&lt;/b&gt;    buffer where it is evaluated. &lt;br /&gt;With this I have a miminally usable set up for org-mode-babel and clojure and are ready to start using it for     porting PAIP to clojure. &lt;/div&gt;&lt;/div&gt;&lt;div class="outline-4" id="outline-container-1-1-2"&gt;&lt;h4 id="sec-1-1-2"&gt;  &lt;span class="section-number-4"&gt;1.1.2&lt;/span&gt; Missing features&lt;/h4&gt;&lt;div class="outline-text-4" id="text-1-1-2"&gt;It turns out that only the most basic functionality is available with this setup.     According to the &lt;a href="http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-clojure.html"&gt;instruction page&lt;/a&gt; org-babel supports sessions and you can specify whether the result is shown     in the org-mode buffer when evaluated.  &lt;br /&gt;&lt;ul&gt;&lt;li id="sec-1-1-2-1"&gt;Results&lt;br /&gt;     As example, insert this code blog in a .org file    &lt;pre class="example"&gt;#+name: basic-session-clojure-table-results&lt;br /&gt;#+begin_src clojure :session s1 :results value&lt;br /&gt;   [ 1 2 3 4]&lt;br /&gt;#+end_src&lt;br /&gt;&lt;/pre&gt;and evaluate C-c C-c whith the point within the source block.      the instruction page says that the following block should have been inserted: &lt;br /&gt;   &lt;pre class="example"&gt;#+resname: basic-session-clojure-table-results&lt;br /&gt;| 1 | 2 | 3 | 4 |&lt;br /&gt;&lt;/pre&gt;(the vector has been automagically converted to an org-mode table) &lt;br /&gt; This doesn't work with this setup, because (lisp-eval-string text) returns nil. The result is only       shown in the &lt;b&gt;inferior-lisp&lt;/b&gt; buffer and I don't know if there is a way getting the result back. &lt;br /&gt; But with emacs, I was able to automate the process of getting the results from the &lt;b&gt;inferior-lisp&lt;/b&gt; buffer using      a keyboard-macro. The macro consists of the following steps: &lt;br /&gt;&lt;ol&gt;&lt;li&gt;Execute C-c C-c &lt;/li&gt;&lt;li&gt;M-x b to the &lt;b&gt;inferior-lisp&lt;/b&gt; buffer &lt;/li&gt;&lt;/ol&gt;the s-exp has now been evaluated and a new user&amp;gt; line was printed.  &lt;br /&gt;&lt;ol&gt;&lt;li&gt;Go one line up and copy everything starting after user&amp;gt; to get the result &lt;/li&gt;&lt;li&gt;Switch to the org-buffer again &lt;/li&gt;&lt;li&gt;Copy the result - I insert following text: ;=&amp;gt; result  &lt;/li&gt;&lt;li&gt;Switch to the &lt;b&gt;inferior-lisp&lt;/b&gt; buffer again &lt;/li&gt;&lt;li&gt;place cursor at it's original position that is at the end of the buffer &lt;/li&gt;&lt;li&gt;Switch to the org-bugger &lt;/li&gt;&lt;/ol&gt;It is a rather lengthy kbd-macro but it does it's job. I recommend that you name it so that you don't have to       define it again and again :) (emacs supports the lazy one) &lt;br /&gt; I think it would be better to implement that as a elisp function but I don't know enough emacs-lis to do this.       Any help would be appreciated &lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li id="sec-1-1-2-2"&gt;Sessions&lt;br /&gt;     Org-mode-babel has also support for multiple sessions which run independend from another.      Consider following example (also from the instruction page)    &lt;pre class="example"&gt;#+name: set-clojure-session-var-s1&lt;br /&gt;#+begin_src clojure :session s1 :results value&lt;br /&gt;(def *var* [1 2 3])&lt;br /&gt;#+end_src&lt;br /&gt;     &lt;br /&gt;#+name: set-clojure-session-var-s2&lt;br /&gt;#+begin_src clojure :session s2 :results value&lt;br /&gt;(def *var* [3 4 5 6 7 8 9])&lt;br /&gt;#+end_src&lt;br /&gt;     &lt;br /&gt;#+name: get-clojure-session-var-s1&lt;br /&gt;#+begin_src clojure :session s1 :results value&lt;br /&gt;(count *var*)&lt;br /&gt;#+end_src&lt;br /&gt;     &lt;br /&gt;#+name: get-clojure-session-var-s2&lt;br /&gt;#+begin_src clojure :session s2 :results value&lt;br /&gt;(count *var*)&lt;br /&gt;#+end_src&lt;br /&gt;&lt;/pre&gt;This should open 2 slime-sessions and insert the results after the src-blocks.      It doesn't work too. org-babel clojure isn't able to start a slime-session.      I have not implemented a workaround for this because I think I won't need it right now, but      here are my thoughts of how to implement sessions: &lt;br /&gt; When org-babel clojure should start a session it first checks whether a Buffer with the session name      already exists. If not, it runs the run-lisp command and renames the &lt;b&gt;inferior-lisp&lt;/b&gt; buffer to the session's name.      If it exists it sets the buffer to the actual inferior lisp buffer according to the comment &lt;a href="http://www.audacity-forum.de/download/edgar/nyquist/nyquist-doc/examples/emacs/sources/inferior-lisp.html"&gt;here&lt;/a&gt;.      After this it runs a function to get the result from the buffer and inserts it after the src blog      (see the section results above) &lt;br /&gt; &lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="outline-3" id="outline-container-1-2"&gt;&lt;h3 id="sec-1-2"&gt;  &lt;span class="section-number-3"&gt;1.2&lt;/span&gt; Final thoughts&lt;/h3&gt;&lt;div class="outline-text-3" id="text-1-2"&gt;org-mode + babel is a great tool for literate programming.    Althoug the described setup is outdated and doesn't work know, with the setup descripbed above you can use the    basic features of org-babel-clojure. The not language agnostic functions are working of course! &lt;br /&gt;I am thankfull for any comment/recommendation regarding the setup and for advice/help how to implement this in    emacs lisp and contributing it back to org-babel. &lt;br /&gt;Is there any function in swank-clojure which can be used to send code to the SLIME buffer and returns the result?&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div id="postamble"&gt;&lt;div class="date"&gt;Date: 2012-05-27T23:06+0200&lt;/div&gt;&lt;div class="author"&gt;Author: kima&lt;/div&gt;&lt;div class="creator"&gt;Org version 7.8.09 with Emacs version 23&lt;/div&gt;&lt;a href="http://validator.w3.org/check?uri=referer"&gt;Validate XHTML 1.0&lt;/a&gt; &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img alt="" height="1" src="https://blogger.googleusercontent.com/tracker/3908276794795362019-5689836547276123388?l=kimavcrp.blogspot.com" width="1" /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=r-ZYJJeyp1A:ybovqkwRxUc:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=r-ZYJJeyp1A:ybovqkwRxUc:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/r-ZYJJeyp1A" height="1" width="1"/&gt;</content>
		<author>
			<name>Maik Schünemann</name>
			<email>noreply@blogger.com</email>
			<uri>http://kimavcrp.blogspot.com/search/label/clojure</uri>
		</author>
		<source>
			<title type="html">Exploring the programming world</title>
			<subtitle type="html">Everytime I come across something that is interesting or cool, I will post it , for you to read and for me as self-reference.</subtitle>
			<link rel="self" href="http://www.blogger.com/feeds/3908276794795362019/posts/default/-/clojure" />
			<id>tag:blogger.com,1999:blog-3908276794795362019</id>
		</source>
	<feedburner:origLink>http://kimavcrp.blogspot.com/2012/05/setting-up-org-mode-babel-with-clojure.html</feedburner:origLink></entry>

	<entry>
		<title type="html">Emacs commands for Clojure development</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/xn3D8cI_hUg/emacs-commands-for-clojure-development.html" />
		<id>tag:blogger.com,1999:blog-6318205100073298070.post-741752647856966545</id>
		<updated>2012-05-30T08:28:14+00:00</updated>
		<content type="html">&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://files.fosswire.com/2010/06/emacs_logo.png" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" src="http://files.fosswire.com/2010/06/emacs_logo.png" /&gt;&lt;/a&gt;&lt;/div&gt;At the London Clojure dojo we use the amazing environment of Emacs to write and run our tests and code.  Emacs is a very powerful environment, more than just the editor it seems at first glance and using a tool written in Lisp is very fitting considering we are learning Clojure, a dialect of Lisp.&lt;br /&gt;&lt;br /&gt;As we have emacs set up to be driven by keyboard shortcuts (as we only get 10 minutes each to code) I have made a crib sheet for the most common keyboard shortcuts and commands.&lt;br /&gt;&lt;br /&gt;&lt;b&gt; &lt;/b&gt;&lt;br /&gt;&lt;b&gt;Emacs crib sheet&lt;/b&gt;&lt;br /&gt;A quick crib sheet for Clojure development using Emacs (see &lt;a href="http://clojure.jr0cket.co.uk/tool-support/emacs-leiningen-swank"&gt;setup guide)&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;table border="0" cellpadding="8" cellspacing="0" style="border-collapse: collapse; border-color: rgb(136, 136, 136); border-width: 1px;"&gt;&lt;tbody&gt;&lt;tr&gt; &lt;td style="height: 16px; width: 118px;"&gt;&lt;span style="font-size: small;"&gt;&lt;b&gt; File Management&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; &lt;td style="height: 16px; width: 148px;"&gt;&lt;br /&gt;&lt;/td&gt; &lt;td style="height: 16px; width: 36px;"&gt;&lt;br /&gt;&lt;/td&gt; &lt;td style="height: 16px; width: 151px;"&gt;&lt;span style="font-size: small;"&gt;&lt;b&gt; Buffer Management&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt; &lt;td style="height: 16px; width: 125px;"&gt;&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt; &lt;td style="height: 16px; width: 118px;"&gt; &lt;b&gt;Open&lt;/b&gt; &lt;/td&gt; &lt;td style="height: 16px; width: 148px;"&gt; Ctrl-X, Ctrl-F &lt;/td&gt; &lt;td style="height: 16px; width: 36px;"&gt;&lt;br /&gt;&lt;/td&gt; &lt;td style="height: 16px; width: 151px;"&gt; Close Window/Buffer &lt;/td&gt; &lt;td style="height: 16px; width: 125px;"&gt; Ctrl-X, K &lt;/td&gt; &lt;/tr&gt;&lt;tr&gt; &lt;td style="height: 16px; width: 118px;"&gt; Save &lt;/td&gt; &lt;td style="height: 16px; width: 148px;"&gt; Ctrl-X, Ctrl-S &lt;/td&gt; &lt;td style="height: 16px; width: 36px;"&gt;&lt;br /&gt;&lt;/td&gt; &lt;td style="height: 16px; width: 151px;"&gt; Quit &lt;/td&gt; &lt;td style="height: 16px; width: 125px;"&gt; Ctrl-X, Ctrl-C &lt;/td&gt; &lt;/tr&gt;&lt;tr&gt; &lt;td style="height: 16px; width: 118px;"&gt; Save As &lt;/td&gt; &lt;td style="height: 16px; width: 148px;"&gt; Ctrl-X, Ctrl-W&lt;/td&gt; &lt;td style="height: 16px; width: 36px;"&gt;&lt;br /&gt;&lt;/td&gt; &lt;td style="height: 16px; width: 151px;"&gt; Scroll through buffers&lt;/td&gt; &lt;td style="height: 16px; width: 125px;"&gt; Ctrl-X, B&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt; &lt;td style="height: 20px; width: 118px;"&gt; Save All &lt;/td&gt; &lt;td style="height: 20px; width: 148px;"&gt; Ctrl-X, S &lt;/td&gt; &lt;td style="height: 20px; width: 36px;"&gt;&lt;br /&gt;&lt;/td&gt; &lt;td style="height: 20px; width: 151px;"&gt; &lt;b&gt;List buffers in window&lt;/b&gt;&lt;/td&gt; &lt;td style="height: 20px; width: 125px;"&gt; Ctrl-X, Ctrl-B &lt;/td&gt; &lt;/tr&gt;&lt;tr&gt; &lt;td style="height: 16px; width: 118px;"&gt; Revert to File &lt;/td&gt; &lt;td style="height: 16px; width: 148px;"&gt; Ctrl-X, Ctrl-V &lt;/td&gt; &lt;td style="height: 16px; width: 36px;"&gt;&lt;br /&gt;&lt;/td&gt; &lt;td style="height: 16px; width: 151px;"&gt; Maximise&lt;/td&gt; &lt;td style="height: 16px; width: 125px;"&gt; Ctrl-X, 1 &lt;br /&gt;&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt; &lt;td style="height: 16px; width: 118px;"&gt; Revert Buffer &lt;/td&gt; &lt;td style="height: 16px; width: 148px;"&gt; Meta-X, revert-buffer &lt;/td&gt; &lt;td style="height: 16px; width: 36px;"&gt;&lt;br /&gt;&lt;/td&gt; &lt;td style="height: 16px; width: 151px;"&gt; Split Horizontally&lt;br /&gt;&lt;br /&gt;&lt;/td&gt; &lt;td style="height: 16px; width: 125px;"&gt; Ctrl-X, 2 &lt;br /&gt;&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt; &lt;td style="height: 16px; width: 118px;"&gt;&lt;br /&gt;&lt;/td&gt; &lt;td style="height: 16px; width: 148px;"&gt;&lt;br /&gt;&lt;/td&gt; &lt;td style="height: 16px; width: 36px;"&gt;&lt;br /&gt;&lt;/td&gt; &lt;td style="height: 16px; width: 151px;"&gt;&lt;b&gt; Split Vertically&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt; &lt;td style="height: 16px; width: 125px;"&gt; Ctrl-X, 3 &lt;/td&gt; &lt;/tr&gt;&lt;tr&gt; &lt;td&gt;&lt;span style="font-size: small;"&gt;&lt;b&gt; Text management&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt; &lt;td&gt;&lt;br /&gt;&lt;/td&gt; &lt;td&gt;&lt;br /&gt;&lt;/td&gt; &lt;td&gt; &lt;b&gt;Switch focus between windows&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt; &lt;td&gt; Ctrl-X, o &lt;/td&gt; &lt;/tr&gt;&lt;tr&gt; &lt;td&gt; Cut Line&lt;/td&gt; &lt;td&gt; Ctrl-k&lt;/td&gt; &lt;td&gt;&lt;br /&gt;&lt;/td&gt; &lt;td&gt;Close current buffer &lt;br /&gt;&lt;br /&gt;&lt;/td&gt; &lt;td&gt;Ctrl-X, 0 (zero)  &lt;br /&gt;&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt; &lt;td&gt; Paste&lt;/td&gt; &lt;td&gt; Ctrl-y&lt;/td&gt; &lt;td&gt;&lt;br /&gt;&lt;/td&gt; &lt;td&gt;&lt;br /&gt;&lt;/td&gt; &lt;td&gt;&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt; &lt;td&gt; Undo&lt;/td&gt; &lt;td&gt; Ctrl-_ &lt;br /&gt;&lt;br /&gt;&lt;/td&gt; &lt;td&gt;&lt;br /&gt;&lt;/td&gt; &lt;td&gt; &lt;span style="font-size: small;"&gt;&lt;b&gt;Build management&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/td&gt; &lt;td&gt;  &lt;br /&gt;&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt; &lt;td&gt;Cut selection &lt;br /&gt;&lt;br /&gt;&lt;/td&gt; &lt;td&gt; Ctrl-w&lt;/td&gt; &lt;td&gt;&lt;br /&gt;&lt;/td&gt; &lt;td&gt;Compile code &lt;br /&gt;&lt;br /&gt;&lt;/td&gt; &lt;td&gt; Ctrl-c, Ctrl-k&lt;br /&gt;&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt;&lt;/tbody&gt; &lt;/table&gt;&lt;br /&gt;&lt;b&gt;Notes&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;When opening a file, use the &lt;b&gt;backscape&lt;/b&gt; key to navigate to parent folder&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Running the Clork project&lt;/b&gt;&lt;br /&gt;Once you have Emacs and Leiningen set up and have downloaded the clork code, you can use the project using these steps&lt;br /&gt;&lt;br /&gt;In a terminal window, change to the root of the clork project.  Run the leiningen command to run Swank&lt;br /&gt;&lt;br /&gt;&lt;b&gt;lein swank&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;You will get a message to saying you are connected to the Swank server&lt;br /&gt;&lt;br /&gt;Open emacs from the root of the clork project and enter the following command to connect to the Swank server&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Meta-X slime connect&lt;/b&gt;&lt;div class="blogger-post-footer"&gt;&lt;img alt="" height="1" src="https://blogger.googleusercontent.com/tracker/6318205100073298070-741752647856966545?l=blog.jr0cket.co.uk" width="1" /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=xn3D8cI_hUg:OIRBmu51GK8:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=xn3D8cI_hUg:OIRBmu51GK8:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/xn3D8cI_hUg" height="1" width="1"/&gt;</content>
		<author>
			<name>John Stevenson</name>
			<email>noreply@blogger.com</email>
			<uri>http://blog.jr0cket.co.uk/search/label/PlanetClojure</uri>
		</author>
		<source>
			<title type="html">jr0cket - community developer</title>
			<link rel="self" href="http://www.blogger.com/feeds/6318205100073298070/posts/default/-/PlanetClojure" />
			<id>tag:blogger.com,1999:blog-6318205100073298070</id>
		</source>
	<feedburner:origLink>http://blog.jr0cket.co.uk/2011/01/emacs-commands-for-clojure-development.html</feedburner:origLink></entry>

	<entry>
		<title type="html">London Clojure dojo - 27th September 2011</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/IccdOEo4Mow/london-clojure-dojo-27th-september-2011.html" />
		<id>tag:blogger.com,1999:blog-6318205100073298070.post-1859740604136129566</id>
		<updated>2012-05-30T08:27:14+00:00</updated>
		<content type="html">&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://ldncljdojo.eventwax.com/uploaded/logo//early-may-2011-london-clojure-dojo/20110419095837-ldncljdojo.png?1303207117" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="115" src="https://ldncljdojo.eventwax.com/uploaded/logo//early-may-2011-london-clojure-dojo/20110419095837-ldncljdojo.png?1303207117" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;As always the dojo started with a feast of pizza and drinks courtesy of ThoughWorks, the perennial favorite it seems with developers (I use it at my Scala dojos for the same effect).  A good turn out tonight meant the pizza went down quickly and we got onto the intros, with the monthly mystery question "If your names' not Bruce, what would it be" nicely stolen from Monty Python.&lt;br /&gt;&lt;br /&gt;Tonight's challenge was a children's classic - 20 Questions.  We set up a server to hold a expert system style data structure to help the teams play the game.  The challenge was two fold in playing the game in the first place and then adding to the question/answer data structure.&lt;br /&gt;&lt;br /&gt;With enough people for 5 teams we split up into our groups and cracked on with the challenge.  Team two were using my trusty Lenovo laptop running Ubuntu, with the timeless classic emacs editor.  Emacs had the obligatory starter kick installed and the project was set up with Lein for the dependency management and Swank for the REPL.&lt;br /&gt;&lt;br /&gt;Once we hooked up Emacs to the local swank server we were off...  well once we figured out what on earth to do first.&lt;br /&gt;&lt;br /&gt;The challenges of a dojo are the blank project, what do we do first.  You either pontificate for a while, come up with 5 different opinions or if you are very lucky decide to jump at the first idea you have and crack on with it - knowing you will refactor it with in about 5 minutes - but thats the fun of the dojo...&lt;br /&gt;&lt;br /&gt;Change is good... fast feedback is good... putting stuff in the REPL is a life saver...&lt;br /&gt;&lt;br /&gt;To connect to the 20 Questions server we used the CLJ-HTTP library, pretty easy to use with simple get and put commands and a standard require statement for the library.  Adding the library to the project.clj and running lein deps brought down the relevant libraries and dependencies (just like a mini maven, but without half the Internet).&lt;br /&gt;&lt;br /&gt;A few of different routes were quickly tried out but we quickly settled on an atom based data structure - as we were going to do updates to it.  We could have done something more elegant though this route was good enough for what we needed.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;br /&gt;Working in a tight knit group for about two hours working on a challenge is a very effective ways of exploring and getting a handle on a new language.  With a group of people who all have different ideas and experiences you take away a lot of things to think about.  I can see why people are driven to do more straight after a dojo and re-do the challenge in some of the different ways discussed.  I always get a great confidence boost for my clojure efforts, even though (or maybe because) I am far from proficient.&lt;br /&gt;&lt;br /&gt;The code is up on GitHub for the world to see and its interesting to understand what a random group with a little bit of knowledge and &lt;a href="http://clojuredocs.org/"&gt;clojuredocs.org&lt;/a&gt; can achieve in under two hours...&lt;div class="blogger-post-footer"&gt;&lt;img alt="" height="1" src="https://blogger.googleusercontent.com/tracker/6318205100073298070-1859740604136129566?l=blog.jr0cket.co.uk" width="1" /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=IccdOEo4Mow:wxD8DD0ijDI:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=IccdOEo4Mow:wxD8DD0ijDI:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/IccdOEo4Mow" height="1" width="1"/&gt;</content>
		<author>
			<name>John Stevenson</name>
			<email>noreply@blogger.com</email>
			<uri>http://blog.jr0cket.co.uk/search/label/PlanetClojure</uri>
		</author>
		<source>
			<title type="html">jr0cket - community developer</title>
			<link rel="self" href="http://www.blogger.com/feeds/6318205100073298070/posts/default/-/PlanetClojure" />
			<id>tag:blogger.com,1999:blog-6318205100073298070</id>
		</source>
	<feedburner:origLink>http://blog.jr0cket.co.uk/2011/09/london-clojure-dojo-27th-september-2011.html</feedburner:origLink></entry>

	<entry>
		<title type="html">Beanstalk + Clojure = Love (and 20x better performance)</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/giwSoDNVccw/24005251212" />
		<id>http://www.colinsteele.org/post/24005251212</id>
		<updated>2012-05-29T17:50:50+00:00</updated>
		<content type="html">&lt;p&gt;&lt;a class="tumblr_blog" href="http://blog.beanstalkapp.com/post/23998022427/beanstalk-clojure-love-and-20x-better-performance" rel="nofollow" target="_blank"&gt;beanstalkapp&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;I try to only post on the Beanstalk blog when I have something cool to post about and today is the perfect occasion. Yesterday we deployed to production a rewrite of Beanstalk’s caching system written in &lt;a href="http://clojure.org/" rel="nofollow" target="_blank"&gt;Clojure&lt;/a&gt;. It is &lt;strong&gt;20 times faster&lt;/strong&gt; than the previous version that was written in Ruby and allowed us to bring the latency between committing a change to a repo and seeing the update in Beanstalk’s UI to an average of &lt;strong&gt;20 ms&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Here I’ll try to explain how and why we did it. But first let me explain the Beanstalk caching architecture.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blog.beanstalkapp.com/post/23998022427/beanstalk-clojure-love-and-20x-better-performance" rel="nofollow" target="_blank"&gt;Read More&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=giwSoDNVccw:We6r0PSoirU:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=giwSoDNVccw:We6r0PSoirU:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/giwSoDNVccw" height="1" width="1"/&gt;</content>
		<author>
			<name>Colin Steele</name>
			<uri>http://pipes.yahoo.com/pipes/pipe.info?_id=5e3eec1b6c35e33e84d36bdcc597541f</uri>
		</author>
		<source>
			<title type="html">Colin Steele</title>
			<subtitle type="html">Pipes Output</subtitle>
			<link rel="self" href="http://pipes.yahoo.com/pipes/pipe.run?_id=5e3eec1b6c35e33e84d36bdcc597541f&amp;_render=rss" />
			<id>http://pipes.yahoo.com/pipes/pipe.info?_id=5e3eec1b6c35e33e84d36bdcc597541f</id>
		</source>
	<feedburner:origLink>http://www.colinsteele.org/post/24005251212</feedburner:origLink></entry>

	<entry>
		<title type="html">Presentation:  Why Prismatic Goes Faster With Clojure</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/p8tKWrWPs8k/Why-Prismatic-Goes-Faster-With-Clojure" />
		<id>http://www.infoq.com/presentations/Why-Prismatic-Goes-Faster-With-Clojure</id>
		<updated>2012-05-29T15:10:00+00:00</updated>
		<content type="html">Bradford Cross recommends creating custom libraries containing composable abstractions instead of monolithic frameworks, exemplifying with Flop, Store, Graph, and Newsfeeds, all written in Clojure. &lt;i&gt;By Bradford Cross&lt;/i&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=p8tKWrWPs8k:WRnBJY_fxEg:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=p8tKWrWPs8k:WRnBJY_fxEg:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/p8tKWrWPs8k" height="1" width="1"/&gt;</content>
		<author>
			<name>Clojure at InfoQ</name>
			<uri>http://pipes.yahoo.com/pipes/pipe.info?_id=be83c0b5b0d92b259682cb8021e14d2a</uri>
		</author>
		<source>
			<title type="html">InfoQ Clojure-related materials</title>
			<subtitle type="html">Pipes Output</subtitle>
			<link rel="self" href="http://pipes.yahoo.com/pipes/pipe.run?_id=be83c0b5b0d92b259682cb8021e14d2a&amp;_render=rss" />
			<id>http://pipes.yahoo.com/pipes/pipe.info?_id=be83c0b5b0d92b259682cb8021e14d2a</id>
		</source>
	<feedburner:origLink>http://www.infoq.com/presentations/Why-Prismatic-Goes-Faster-With-Clojure</feedburner:origLink></entry>

	<entry>
		<title type="html">Beanstalk + Clojure = Love (and 20x better performance)</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/a7UsyvOVst0/23998022427" />
		<id>http://blog.beanstalkapp.com/post/23998022427</id>
		<updated>2012-05-29T14:57:29+00:00</updated>
		<content type="html">&lt;p&gt;I try to only post on the Beanstalk blog when I have something cool to post about and today is the perfect occasion. Yesterday we deployed to production a rewrite of Beanstalk’s caching system written in &lt;a href="http://clojure.org/" rel="nofollow" target="_blank"&gt;Clojure&lt;/a&gt;. It is &lt;b&gt;20 times faster&lt;/b&gt; than the previous version that was written in Ruby and allowed us to bring the latency between committing a change to a repo and seeing the update in Beanstalk’s UI to an average of &lt;b&gt;20 ms&lt;/b&gt;. &lt;/p&gt;

&lt;p&gt;Here I’ll try to explain how and why we did it. But first let me explain the Beanstalk caching architecture.&lt;/p&gt;



&lt;h3&gt;Beanstalk Caching Architecture&lt;/h3&gt;

&lt;p&gt;When a commit or a push is made to a repository hosted on Beanstalk it first goes directly to the repository on our high availability storage servers. This way we make sure that your commits are safe and that if any error happens, your version control client will let you know immediately. &lt;/p&gt;

&lt;p&gt;The next step is commit caching, when we take the commit information from the repo and put in the database. This is to make sure we don’t need to hit the disks every time we need a tiny bit of information about your files or commits. This greatly improves your general Beanstalk experience — from the web UI to email notifications to deployments.&lt;/p&gt;

&lt;p&gt;After the commit is cached it is then transferred further to trigger email notifications, various integrated services, automated deployments and update various stats in your account.&lt;/p&gt;

&lt;p&gt;To fetch commit information from the repos in Beanstalk we use several different APIs — for each of the version control systems we support:&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;Official Subversion Ruby bindings (which bind Ruby with Subversion’s C library)&lt;/li&gt;
  &lt;li&gt;&lt;a href="https://github.com/mojombo/grit" rel="nofollow" target="_blank"&gt;Grit&lt;/a&gt; for Git (which is a mix of pure Ruby code with bits of Git command line client output parsing)&lt;/li&gt;
  &lt;li&gt;Our own &lt;a href="https://github.com/isabanin/mercurial-ruby" rel="nofollow" target="_blank"&gt;Ruby gem for Mercurial&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;h3&gt;So What’s The Problem?&lt;/h3&gt;

&lt;p&gt;The problem was that commit caching was frequently quite slow. For Subversion repositories big commits could easily take 30 seconds to cache. If a new Subversion repository was imported into Beanstalk, it could take up to 10 minutes to cache.
&lt;/p&gt;
&lt;p&gt;For Git the situation was even worse, since each push can potentially represent thousands of commits it could easily take 30 minutes to cache it. If your Git repo has a lot of branches, then it could take even more time. Now if you imagine that we have to process thousands commits every hour, this could easily become a problem for our servers and sometimes it was.&lt;/p&gt;

&lt;p&gt;I probably need to explain why Git is much slower for us — it’s because of the way we represent Git activity timeline. We think that all commits to different branches should be viewable together in a single timeline, so we have to perform an extra bit of caching to get additional information about branches structure and what commit was pushed to which branch first (even though Git doesn’t provide this information easily).&lt;/p&gt;

&lt;p&gt;Basically, our problem was caused by the fact that we relied on some not very efficient algorithms to build our caches (due to the API restrictions of SVN bindings and Grit library) and the fact that we used Ruby in such a critical place for Beanstalk’s performance.&lt;/p&gt;

&lt;h3&gt;Clojure to the Rescue&lt;/h3&gt;

&lt;p&gt;I’ve been looking for an excuse to use Clojure in a production environment for a while. If you don’t know what Clojure is — it’s a Lisp dialect that runs on a &lt;a href="http://en.wikipedia.org/wiki/Java_virtual_machine" rel="nofollow" target="_blank" title="Java Virtual Machine"&gt;JVM&lt;/a&gt;. You get the best of the both worlds - amazing power and clarity of a modern Lisp and huge variety of production ready Java libraries out there.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Clojure is an awesome language that brings Lisp into the 21st century.&lt;/b&gt; It provides great support for concurrency out of the box, it’s a functional language with a lot of things done right and it has a very vibrant community with lots of extremely smart people. The fact that it integrates seamlessly with Java allows you to use all the code from the Java world without writing a line of Java.&lt;/p&gt;

&lt;p&gt;So the best thing is that with some optimizations (like optional type hints) Clojure can be made to run almost as fast as native Java. But even without any optimizations Clojure code is easily 30-50 times faster than regular Ruby code on artificial benchmarks, and that sounded like a great plan to me!&lt;/p&gt;

&lt;p&gt;There are also some amazing libraries for version control system for Java that I could use through Clojure right away:&lt;/p&gt; 

&lt;ul&gt;&lt;li&gt;&lt;a href="http://svnkit.com/" rel="nofollow" target="_blank"&gt;SVNKit&lt;/a&gt; for Subversion (Used by Oracle, IBM, Novell, Borland)&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.jgit.org/" rel="nofollow" target="_blank"&gt;JGit&lt;/a&gt; used by Eclipse&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;There’s also plenty of &lt;a href="http://clojure-toolbox.com" rel="nofollow" target="_blank"&gt;great libraries for Clojure&lt;/a&gt; and many more appear each day. All this made Clojure a great candidate for a second language to be added to the Beanstalk team’s toolbox.&lt;/p&gt;

&lt;h3&gt;The Results&lt;/h3&gt;

&lt;p&gt;The rewrite in Clojure resulted in much cleaner, faster code, totaling at only 700 lines of Clojure code (I don’t have a clear comparison with Ruby code here). Some of the features of our new caching daemon are:&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;It’s very fast. &lt;b&gt;Subversion caching is more than 15-20 times faster&lt;/b&gt; than our previous Ruby version. &lt;b&gt;Git caching is 50 times faster&lt;/b&gt; than before.&lt;/li&gt;
&lt;li&gt;It is multi-threaded so it doesn’t spawn processes when new job comes in, so it’s very fast at catching new commits. It’s also more efficient and we’ll be able to process more commits with it.&lt;/li&gt;
&lt;li&gt;It’s deployed as a single JAR file that we can run on any of our machines that are connected to the HA file storage. That will allow us to scale our commit caching capacity in matter of minutes on spare machines.&lt;/li&gt; 
&lt;li&gt;Very low latency - it starts caching new commits before you press that commit button :).&lt;/li&gt;
&lt;/ul&gt;&lt;h3&gt;What Does This Mean To Our Customers?&lt;/h3&gt;

&lt;ul&gt;&lt;li&gt;Commits appearing in timeline nearly instantly.&lt;/li&gt;
&lt;li&gt;Deployments will be triggered faster.&lt;/li&gt;
&lt;li&gt;Generally better caching as Clojure is not having problems with commits that were “too large” to cache for our Ruby version.&lt;/li&gt;
&lt;li&gt;More consistent caching results, no unicode issues even in weird cases.&lt;/li&gt;
&lt;/ul&gt;&lt;h3&gt;Future Plans&lt;/h3&gt;

&lt;p&gt;We plan to improve our caching even more by running the caching daemon on our backup storage servers, which will make commit caching even faster as we would bypass NFS latency.&lt;/p&gt;

&lt;p&gt;Our experience of using Clojure for real world stuff was a very positive one and we look forward to using more Clojure in Beanstalk infrastructure. Who knows, maybe someday we’ll be able to speed up our deployments even further by using Clojure.&lt;/p&gt;


&lt;h3&gt;Interested in Clojure?&lt;/h3&gt;

&lt;p&gt;If you are interested in learning more about Clojure here are some great resources: 
&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://clojure.org/" rel="nofollow" target="_blank"&gt;Official Clojure web site&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blip.tv/clojure" rel="nofollow" target="_blank"&gt;Clojure screencasts and presentations&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://clojuredocs.com" rel="nofollow" target="_blank"&gt;Clojure Docs project&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://4clojure.org" rel="nofollow" target="_blank"&gt;4Clojure&lt;/a&gt; — learning Clojure interactively&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;Here are also some good books on the subject: &lt;a href="http://www.manning.com/rathore/" rel="nofollow" target="_blank"&gt;Clojure in Action&lt;/a&gt; and &lt;a href="http://joyofclojure.com/" rel="nofollow" target="_blank"&gt;Joy of Clojure
&lt;/a&gt; from Manning, &lt;a href="http://www.clojurebook.com/" rel="nofollow" target="_blank"&gt;Clojure Programming&lt;/a&gt; from O’Reilly and &lt;a href="http://pragprog.com/book/shcloj2/programming-clojure" rel="nofollow" target="_blank"&gt;Programming Clojure (2nd edition)&lt;/a&gt; from Pragmatic Programmers.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;TL;DR:&lt;/b&gt; Clojure is awesome, Beanstalk commit caching is now 20-40 times faster.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=a7UsyvOVst0:wgEaG31NWJk:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=a7UsyvOVst0:wgEaG31NWJk:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/a7UsyvOVst0" height="1" width="1"/&gt;</content>
		<author>
			<name>Beanstalk</name>
			<uri>http://pipes.yahoo.com/pipes/pipe.info?_id=83fd94188e529e39e6618f741257f114</uri>
		</author>
		<source>
			<title type="html">Beanstalk</title>
			<subtitle type="html">Pipes Output</subtitle>
			<link rel="self" href="http://pipes.yahoo.com/pipes/pipe.run?_id=83fd94188e529e39e6618f741257f114&amp;_render=rss" />
			<id>http://pipes.yahoo.com/pipes/pipe.info?_id=83fd94188e529e39e6618f741257f114</id>
		</source>
	<feedburner:origLink>http://blog.beanstalkapp.com/post/23998022427</feedburner:origLink></entry>

	<entry>
		<title type="html">Clojure: Freezing Time in expectations</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/1qPdxtI3VPE/clojure-freezing-time-in-expectations.html" />
		<id>tag:blogger.com,1999:blog-12467669.post-113356539059705437</id>
		<updated>2012-05-29T13:00:02+00:00</updated>
		<content type="html">The current version of expectations (1.4.3) contains support for freezing time within an &lt;a href="http://blog.jayfields.com/2011/11/clojure-expectations-scenarios.html"&gt;expectations scenario&lt;/a&gt;. I already put this information out in a &lt;a href="http://blog.jayfields.com/2012/05/clojure-conditionally-importing.html"&gt;previous blog entry&lt;/a&gt;, and I'm going to use the same examples here. &lt;br /&gt;&lt;br /&gt;The following code is a test I was working on at work: &lt;pre&gt;(scenario&lt;br /&gt; (handle-fill (build PartialFill))&lt;br /&gt; (expect {:px 10 :size 33 :time 1335758400000} (first @fills)))&lt;/pre&gt;The test builds a PartialFill domain object, and passes it to handle-fill. The handle-fill fn converts the domain object to a map and conj's the new map onto the fills vector (which is an atom). The above test would fail due to the time not being frozen, and the traditional way to deal with this issue was to change the test to use &lt;a href="http://blog.jayfields.com/2011/11/clojure-expectations-with-values-in.html"&gt;(in ..)&lt;/a&gt; and ignore the :time key-value pair. &lt;br /&gt;&lt;br /&gt;The following code would have resulted in a passing test: &lt;pre&gt;(scenario&lt;br /&gt; (handle-fill (build PartialFill))&lt;br /&gt; (expect {:px 10 :size 33} (in (first @fills))))&lt;/pre&gt;The above code is fine, as long as you're not interested in verifying the time; however, things get a lot uglier if you do want to verify time. The following code freezes (joda) time, allowing for time verification: &lt;pre&gt;(scenario&lt;br /&gt; (DateTimeUtils/setCurrentMillisFixed 100)&lt;br /&gt; (handle-fill (build PartialFill))&lt;br /&gt; (expect {:px 10 :size 33 :time 100} (first @fills))&lt;br /&gt; (DateTimeUtils/setCurrentMillisSystem))&lt;/pre&gt;While the above code does result in a passing test, it would cause unexpected issues if expect ever failed. In expectations a failure throws an exception (to terminate scenario execution) and the time reset would never occur. Even if that wasn't the case, the time related code takes away from the actual focus of the test. &lt;br /&gt;&lt;br /&gt;Therefore, expectations has been modified to take a :freeze-time parameter as part of a scenario definition. The :freeze-time parameter can be a string or a boolean - when specifying a string, anything &lt;a href="http://joda-time.sourceforge.net/api-release/org/joda/time/DateTime.html#parse(java.lang.String)"&gt;parse-able&lt;/a&gt; by Joda will do; if you specify a boolean time will simply be stopped at the moment of execution. &lt;br /&gt;&lt;br /&gt;With :freeze-time available we can rewrite the above test in the following way: &lt;pre&gt;(scenario&lt;br /&gt; :freeze-time "2012-4-30"&lt;br /&gt; (handle-fill (build PartialFill))&lt;br /&gt; (expect {:px 10 :size 33 :time 1335758400000} (first @fills)))&lt;/pre&gt;The resulting code is easier to work with, while still allowing verification of time. &lt;br /&gt;&lt;br /&gt;I believe the domain related code does a better job of demonstrating the point; however, the following examples are available if you'd like something simplified. &lt;pre&gt;(scenario&lt;br /&gt;  :freeze-time true&lt;br /&gt;  (expect (DateTime.) (do (Thread/sleep 10) (DateTime.))))&lt;br /&gt;&lt;br /&gt;(scenario&lt;br /&gt;  :freeze-time "2012-4-30TZ"&lt;br /&gt;  (expect (.getMillis (DateTime.)) 1335744000000))&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;br /&gt;&lt;a href="http://www.jayfields.com"&gt;© Jay Fields - www.jayfields.com&lt;/a&gt;&lt;img alt="" height="1" src="https://blogger.googleusercontent.com/tracker/12467669-113356539059705437?l=blog.jayfields.com" width="1" /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=1qPdxtI3VPE:ZQh53EFPQI0:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=1qPdxtI3VPE:ZQh53EFPQI0:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/1qPdxtI3VPE" height="1" width="1"/&gt;</content>
		<author>
			<name>jaycfields</name>
			<email>noreply@blogger.com</email>
			<uri>http://blog.jayfields.com/search/label/clojure</uri>
		</author>
		<source>
			<title type="html">Jay Fields' Thoughts</title>
			<subtitle type="html">experiences in software development</subtitle>
			<link rel="self" href="http://www.blogger.com/feeds/12467669/posts/default/-/clojure" />
			<id>tag:blogger.com,1999:blog-12467669</id>
		</source>
	<feedburner:origLink>http://blog.jayfields.com/2012/05/clojure-freezing-time-in-expectations.html</feedburner:origLink></entry>

	<entry>
		<title type="html">The Speed Race Is On: Vert.x and Node.js</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/4M3hSQl-H8w/speed-race-vertx-and-nodejs" />
		<id>http://pipes.yahoo.com/pipes/110301 at http://java.dzone.com</id>
		<updated>2012-05-29T04:53:54+00:00</updated>
		<content type="html">Vert.x and Node.js
 are similar in some ways, and different in others.  One such difference
 is that Node.js only allows you to write code in JavaScript whereas 
Vert.x allows you to code in Java, Groovy, JavaScript, Ruby and 
eventually as the Vert.x team expands support for the following is 
planned: Clojure, Scala and Python.
      Preview Text: 
    
            
                   ...&lt;img height="1" src="http://feeds.feedburner.com/~r/javalobby/frontpage/~4/bgOExML0Kb8" width="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=4M3hSQl-H8w:byN8e0XK1DQ:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=4M3hSQl-H8w:byN8e0XK1DQ:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/4M3hSQl-H8w" height="1" width="1"/&gt;</content>
		<author>
			<name>Javalobby</name>
			<uri>http://pipes.yahoo.com/pipes/pipe.info?_id=f8b56ef73099743fdfe6336dd7cd0d5c</uri>
		</author>
		<source>
			<title type="html">Javalobby</title>
			<subtitle type="html">Pipes Output</subtitle>
			<link rel="self" href="http://pipes.yahoo.com/pipes/pipe.run?_id=f8b56ef73099743fdfe6336dd7cd0d5c&amp;_render=rss" />
			<id>http://pipes.yahoo.com/pipes/pipe.info?_id=f8b56ef73099743fdfe6336dd7cd0d5c</id>
		</source>
	<feedburner:origLink>http://feeds.dzone.com/~r/javalobby/frontpage/~3/bgOExML0Kb8/speed-race-vertx-and-nodejs</feedburner:origLink></entry>

	<entry>
		<title type="html" xml:lang="en">EuroClojure 2012 – Part 2</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/gGT-fzVky-w/" />
		<id>http://otfrom.wordpress.com/?p=90</id>
		<updated>2012-05-28T10:44:50+00:00</updated>
		<content type="html" xml:lang="en">&lt;p&gt;&lt;a href="http://euroclojure.com/2012/"&gt;EuroClojure&lt;/a&gt; for me was also about community and diversity.&lt;/p&gt;
&lt;p&gt;The community aspect of EuroClojure was obvious from the start. It was a great selection of friendly and welcoming people, which has always been my experience in the clojure community. During the community talk (from &lt;a href="http://twitter.com/rrees"&gt;Robert Rees&lt;/a&gt; and &lt;a href="http://twitter.com/devn"&gt;Devin Walters&lt;/a&gt;) all of the various community organisers in the room were asked to stand up and give a shout out for their group. It felt like there were a dozen or so community organisers at the event. I also know that after the talk that there are a number of new clojure communities that are going to be formed.&lt;/p&gt;
&lt;p&gt;Diversity overall was a mixed bag. There was good representation in the room from a number of different European countries in addition to the USA and Canada. The talks were from a mixture of professional clojurians and hobbyist clojurians. There was a good mix of ages, though no one under 20 I believe.&lt;/p&gt;
&lt;p&gt;I also felt, and as a programme committee member strived for, a wide variety of talks. Some of the talks were theortical, and a good number were practical. The subjects covered things in the core language, tooling, devops, art, music, maths and logic. If flights from Prague had been easier we would have also had some digital humanities in the form of computational linguistics. I also hope that there was a wide enough variety of skills needed for each of the talks from beginner through to advanced.&lt;/p&gt;
&lt;p&gt;As with many technical conferences we weren’t so good on racial and gender diversity. Most of the audience was white and male, though not exclusively. No women submitted talks this year. I hope to change that next year. I think we can do better and I hope to be able to follow the example of the &lt;a href="http://openhatch.org/"&gt;OpenHatch&lt;/a&gt; project and do more outreach overall. I think we do have a community that welcomes difference and diversity. I think we need to do more to prove it though. &lt;/p&gt;
&lt;p&gt;Overall, the conference was fantastic and thanks to &lt;a href="http://twitter.com/capotribu"&gt;Marco Abis&lt;/a&gt;. I had a great time. I survived my talk (Rich Hickey’s eye based death beams didn’t incinerate me as I had dreamed). I got to plug my startup &lt;a href="https://www.mastodonc.com"&gt;Mastodon C&lt;/a&gt; in my talk. I met a lot of lovely and friendly people (including Rich Hickey, who isn’t nearly so scary in real life). I also came away very enthusiastic and hopeful about the clojure community in Europe and worldwide. I’m now really looking forward to what we are all able to do over the next year.&lt;/p&gt;
&lt;br /&gt;  &lt;a href="http://feeds.wordpress.com/1.0/gocomments/otfrom.wordpress.com/90/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/otfrom.wordpress.com/90/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/godelicious/otfrom.wordpress.com/90/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/otfrom.wordpress.com/90/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/gofacebook/otfrom.wordpress.com/90/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/otfrom.wordpress.com/90/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/gotwitter/otfrom.wordpress.com/90/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/otfrom.wordpress.com/90/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/gostumble/otfrom.wordpress.com/90/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/otfrom.wordpress.com/90/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/godigg/otfrom.wordpress.com/90/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/otfrom.wordpress.com/90/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/goreddit/otfrom.wordpress.com/90/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/otfrom.wordpress.com/90/" /&gt;&lt;/a&gt; &lt;img alt="" border="0" height="1" src="http://stats.wordpress.com/b.gif?host=otfrom.wordpress.com&amp;amp;blog=6096936&amp;amp;post=90&amp;amp;subd=otfrom&amp;amp;ref=&amp;amp;feed=1" width="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=gGT-fzVky-w:-G3mfWQ_Ndw:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=gGT-fzVky-w:-G3mfWQ_Ndw:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/gGT-fzVky-w" height="1" width="1"/&gt;</content>
		<author>
			<name>otfrom</name>
			<uri>http://otfrom.wordpress.com</uri>
		</author>
		<source>
			<title type="html">Wifi and Coffee » clojure</title>
			<subtitle type="html">Hunting around for good coffee and free wifi.</subtitle>
			<link rel="self" href="http://otfrom.wordpress.com/tag/clojure/feed/" />
			<id>http://otfrom.wordpress.com</id>
		</source>
	<feedburner:origLink>http://otfrom.wordpress.com/2012/05/28/euroclojure-2012-part-2/</feedburner:origLink></entry>

	<entry>
		<title type="html">EuroClojure 2012 impressions</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/z0rZ5jurpsk/euroclojure-2012-impressions.html" />
		<id>http://jan.rychter.com/enblog/2012/5/28/euroclojure-2012-impressions.html</id>
		<updated>2012-05-28T09:12:57+00:00</updated>
		<content type="html">&lt;p&gt;I just got back from the EuroClojure 2012 conference. I won't try to summarize all the talks here, just convey some general impressions that I got:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Clojure community is awesome. People are incredibly nice to each other. Ask a question on the mailing list, and you'll get a number of replies from people much smarter and more experienced than you. Same at the conference: you can approach anyone and expect to get great advice even if the competence gap between you and the other person is comparable in size to the Grand Canyon.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A lot of the talks focused on how to approach difficult and complex real-life problems better. Those weren't talks about syntactic sugar, "best practices", or new "features" the language should have. Instead, speakers presented results of months of thinking and experimenting: new architectures, new approaches, new ways to think about problems. If semicolons were discussed, it was a discussion about how to preserve them while doing source-code transformations. This is incredibly important: you can't overestimate the value of listening to smart people talk about ideas they thought hard about and developed for many months. I had several "aha!" moments where I suddenly saw that the architectures I developed were a poor-man's subset of a more general solution.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There was a focus on building real systems. I'd say that hobbyists and academics were in the minority: most people were there to learn how to better build code that makes money. It was also interesing to see the range of sizes of companies that use Clojure: from one-person consultancies through startups and small web-development shops, all the way through large financial institutions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The median age of participants was probably between 35 and 40 years. This is clearly not a bunch of teenagers, but rather a group that gained significant experience in various languages and then moved on to Clojure. I think this has a lot to do with my first point — the community is both incredibly nice and mature, which often go together.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Overall, the conference was a success — more so than I expected. The organization was nearly flawless (not an easy task, I know, so hats off to Marco Abis). And it is now very clear than a European conference about Clojure is necessary. I'm looking forward to EuroClojure 2013!&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=z0rZ5jurpsk:CSGcuTJj0d0:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=z0rZ5jurpsk:CSGcuTJj0d0:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/z0rZ5jurpsk" height="1" width="1"/&gt;</content>
		<author>
			<name>Jan Rychter</name>
			<uri>http://pipes.yahoo.com/pipes/pipe.info?_id=d6dadbbf9c6d16fb50c2e96309c85743</uri>
		</author>
		<source>
			<title type="html">Jan Rychter</title>
			<subtitle type="html">Pipes Output</subtitle>
			<link rel="self" href="http://pipes.yahoo.com/pipes/pipe.run?_id=d6dadbbf9c6d16fb50c2e96309c85743&amp;_render=rss" />
			<id>http://pipes.yahoo.com/pipes/pipe.info?_id=d6dadbbf9c6d16fb50c2e96309c85743</id>
		</source>
	<feedburner:origLink>http://jan.rychter.com/enblog/2012/5/28/euroclojure-2012-impressions.html</feedburner:origLink></entry>

	<entry>
		<title type="html">clojure: type hinting and warn on reflection</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/kDF2ifojlZ8/206.html" />
		<id>http://paulsanwald.com/blog/206.html</id>
		<updated>2012-05-28T04:54:11+00:00</updated>
		<content type="html">&lt;p&gt;
I've been working a bit with the javax.sound.midi libraries, using clojure. I just ran across a problem I hadn't encountered before, so I wanted to share the solution. If you are a clojure veteran, this post won't be interesting, but if you're new to the language like me (or googling the error I got), it might help.
&lt;/p&gt;&lt;p&gt;
Quick MIDI background. A synthesizer is something you can use to generate sound. A Synthesizer has one or more channels, which you use to generate the sound. For a real world analogy, a Synthesizer is like a piano, and a channel is like your left hand.
&lt;/p&gt;&lt;p&gt;
I was executing some fairly basic clojure code:
&lt;/p&gt;
&lt;pre&gt;(import 'javax.sound.midi.Synthesizer 'javax.sound.midi.MidiSystem)
(def synth (doto (MidiSystem/getSynthesizer) .open))
(aget (.getChannels synth) 0)
IllegalArgumentException Can't call public method of non-public class: public javax.sound.midi.MidiChannel[] com.sun.media.sound.AbstractPlayer.getChannels()  clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:87)
&lt;/pre&gt;
&lt;p&gt;
Hey, what's going on here? According to the &lt;a href="http://docs.oracle.com/javase/7/docs/api/javax/sound/midi/Synthesizer.html"&gt;javadoc&lt;/a&gt;, Synthesizer.getChannels() is fair game!
&lt;/p&gt;
&lt;p&gt;The problem is caused by the fact that clojure's java interoperability works by reflection, and in this case, it's getting confused as to what type the class is. Since this is a common problem, clojure provides a mechanism, &lt;a href="http://clojure.org/java_interop#Java%20Interop-Type%20Hints"&gt;type hinting&lt;/a&gt;, to help deal. There is also a flag you can set to be notified of potential errors of this type, &lt;a href="http://clojuredocs.org/clojure_core/clojure.core/*warn-on-reflection*"&gt;warn-on-reflection&lt;/a&gt;. So, all I had to do to fix this, was let clojure know what type it should be using to call .getChannels(), using a type hint:
&lt;/p&gt;
&lt;pre&gt;(aget (.getChannels ^Synthesizer synth) 0)
#
&lt;/pre&gt;

&lt;p&gt;
voila! also, setting *warn-on-reflection* allows us to see what's happening here:
&lt;/p&gt;
&lt;pre&gt;(set! *warn-on-reflection* true)
true
user=&amp;gt; (aget (.getChannels synth) 0)             
Reflection warning, NO_SOURCE_PATH:7 - reference to field getChannels can't be resolved.
&lt;/pre&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=kDF2ifojlZ8:SRznZNhYVOg:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=kDF2ifojlZ8:SRznZNhYVOg:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/kDF2ifojlZ8" height="1" width="1"/&gt;</content>
		<author>
			<name>Paul Sanwald</name>
			<uri>http://paulsanwald.com/blog.html</uri>
		</author>
		<source>
			<title type="html">Paul's Blog</title>
			<subtitle type="html">In which I talk about my life, music, boxing and technology.</subtitle>
			<link rel="self" href="http://paulsanwald.com/blog/category/4.rss" />
			<id>http://paulsanwald.com/blog.html</id>
		</source>
	<feedburner:origLink>http://paulsanwald.com/blog/206.html</feedburner:origLink></entry>

	<entry>
		<title type="html">Ruby Clojure Integration</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/PYKZPP8MJz4/ruby-clojure-integration.html" />
		<id>http://www.element84.com/?p=876</id>
		<updated>2012-05-28T02:10:07+00:00</updated>
		<content type="html">&lt;p&gt;Lately I’ve been looking into the Clojure programming language, a Lisp that’s implemented on top of the JVM. One of the aspects of Clojure that I’m interested in is its ability to integrate into existing projects, especially Ruby projects. Since Clojure runs on the JVM and already &lt;a href="http://clojure.org/java_interop" rel="nofollow" target="_blank"&gt;integrates with Java&lt;/a&gt; it should be easy to integrate into a Ruby project run on JRuby. I discovered the JRuby Clojure Bridge gem, called &lt;a href="https://github.com/kyleburton/jrclj" rel="nofollow" target="_blank"&gt;jrclj&lt;/a&gt;, that does just that.&lt;/p&gt;
&lt;h2&gt;Demonstration&lt;/h2&gt;
&lt;p&gt;I’ve created a test project that demonstrates using jrclj. It’s on &lt;a href="https://github.com/jasongilman/jruby_clojure_integration_demo" rel="nofollow" target="_blank"&gt;github&lt;/a&gt;. Follow the directions in the &lt;a href="https://github.com/jasongilman/jruby_clojure_integration_demo/blob/master/README.md" rel="nofollow" target="_blank"&gt;README&lt;/a&gt; to try it out. It consists of a small Clojure project, powers_of_two, and a Ruby file that demonstrates calling the powers_of_two code. &lt;/p&gt;
&lt;h2&gt;The Clojure Code&lt;/h2&gt;
&lt;p&gt;The main source code for powers_of_two is in one source file, &lt;a href="https://github.com/jasongilman/jruby_clojure_integration_demo/blob/master/powers_of_two/src/powers_of_two/core.clj" rel="nofollow" target="_blank"&gt;core.clj&lt;/a&gt;&lt;/p&gt;
&lt;pre&gt;(ns powers_of_two.core)

(defn powers_of_two
  ([]
    (concat [1 2 4] (powers_of_two 4N)))
  ([last_value]
    (let [next_value (* last_value 2N)]
      (lazy-seq (cons next_value (powers_of_two next_value))))))

(defn powers_of_two_improved []
  (iterate (fn [v] (* v 2N)) 1))
&lt;/pre&gt;
&lt;p&gt;core.clj contains two functions that do the same thing, return a sequence of numbers containing the powers of two.  ie. 2^0, 2^1, 2^2, 2^3,… or 1, 2, 4, 8, …  The sequences are recursively infinite but use &lt;code&gt;lazy-seq&lt;/code&gt; to avoid recursing forever.   Lazy sequences in Clojure give you the power of defining a sequence of things (numbers, database records, dates, etc) recursively and infinitely.  The first &lt;code&gt;powers_of_two&lt;/code&gt; function does it manually using recursion and the &lt;a href="http://clojuredocs.org/clojure_core/clojure.core/lazy-seq" rel="nofollow" target="_blank"&gt;lazy-seq function&lt;/a&gt;.  The &lt;code&gt;powers_of_two_improved&lt;/code&gt; function uses the &lt;code&gt;&lt;a href="http://clojuredocs.org/clojure_core/clojure.core/iterate" rel="nofollow" target="_blank"&gt;iterate&lt;/a&gt;&lt;/code&gt; function, which lets you build a lazy sequence from a function and a starting value.  The upper case &lt;code&gt;N&lt;/code&gt; in the examples after numbers changes them to Clojure big integers.  The powers of two sequence will quickly grow beyond what a normal integer can represent.&lt;/p&gt;
&lt;h2&gt;The Ruby Code&lt;/h2&gt;
&lt;p&gt;The &lt;a href="https://github.com/jasongilman/jruby_clojure_integration_demo/blob/master/use_powers_of_two.rb" rel="nofollow" target="_blank"&gt;use_powers_of_two.rb script&lt;/a&gt; demonstrates calling Clojure from JRuby&lt;/p&gt;
&lt;pre&gt;require 'rubygems'
require 'java'

# Require the clojure jars
require 'powers_of_two/lib/clojure-1.4.0.jar'
require 'powers_of_two/lib/clojure-contrib-1.2.0.jar'

# Require the project jar that we want to use
require 'powers_of_two/powers_of_two-1.0.0-SNAPSHOT.jar'

# Require the jrclj gem that lets us interact with clojure code
require 'jrclj'

# Create a JRClj context.  We can then import clojure namespaces which will make the functions available
clj = JRClj.new
clj._import "powers_of_two.core"

puts "2**500 == " + clj.nth(clj.powers_of_two, 500).to_s
&lt;/pre&gt;
&lt;p&gt;The last line actually makes the call into Clojure.  It calls the Clojure function &lt;code&gt;&lt;a href="http://clojuredocs.org/clojure_core/clojure.core/nth" rel="nofollow" target="_blank"&gt;nth&lt;/a&gt;&lt;/code&gt; which will take the 500th item from the sequence returned by the &lt;code&gt;powers_of_two&lt;/code&gt; function. This prints out 2^500.&lt;/p&gt;
&lt;h2&gt;Repl&lt;/h2&gt;
&lt;p&gt;You can try out a repl with jruby clojure integration using the jrepl script included in the project. Run jrepl from a command line and then try the following bits of code&lt;/p&gt;
&lt;p&gt;&lt;code&gt;./jrepl&lt;br /&gt;
Your .irbrc has loaded&lt;br /&gt;
&amp;gt;&amp;gt; clj.powers_of_two&lt;br /&gt;
=&amp;gt; #&amp;lt;Java::ClojureLang::LazySeq:0x1558473e&amp;gt;&lt;/code&gt;&lt;br /&gt;
powers_of_two just returns a lazy sequence&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;gt;&amp;gt; clj.take( 10, clj.powers_of_two).map(&amp;amp;:to_i)&lt;br /&gt;
=&amp;gt; [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]&lt;/code&gt;&lt;br /&gt;
This takes the first 10 items from the Clojure sequence.  We then use Ruby’s map method to convert all of the results to integers.  The Ruby map method works on lazy sequences from Clojure because one of it’s interfaces is standard Java interface &lt;code&gt;java.util.List&lt;/code&gt;.  JRuby allows &lt;code&gt;java.util.List&lt;/code&gt;s to be treated like Ruby Arrays.  This means the Clojure sequences themselves can be accessed like a Ruby array.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;gt;&amp;gt; clj.powers_of_two.map(&amp;amp;:to_i)&lt;br /&gt;
NativeException: java.lang.OutOfMemoryError: Java heap space&lt;/code&gt;&lt;br /&gt;
The Clojure sequences are infinite.  If you’re not careful you can run out of memory.&lt;/p&gt;
&lt;h2&gt;Why?&lt;/h2&gt;
&lt;p&gt;So why would you want to integrate Clojure with Ruby? It would certainly be simpler to limit your projects to a single language.  Clojure has benefits that are worth exploring.  Clojure makes it very easy to write concurrent code that perform well.  Functions that don’t manipulate state and minimize or have no side effects are easier to understand and test.  Macros (http://clojure.org/macros) are like metaprogramming on steroids.  There are also libraries built in Clojure that would be useful to integrate into a Ruby project.  An example of this is &lt;a href="http://incanter.org/" rel="nofollow" target="_blank" title="Incanter"&gt;Incanter&lt;/a&gt;, a platform for statistical computing and graphics.  The fact that Clojure integrates so easily with JRuby makes it easy to experiment.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=PYKZPP8MJz4:zZ4gcl_OrDY:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=PYKZPP8MJz4:zZ4gcl_OrDY:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/PYKZPP8MJz4" height="1" width="1"/&gt;</content>
		<author>
			<name>Jason Gilman</name>
			<uri>http://pipes.yahoo.com/pipes/pipe.info?_id=c4fc06896b8f6e45b3be8c84dea6ab71</uri>
		</author>
		<source>
			<title type="html">Element 84</title>
			<subtitle type="html">Pipes Output</subtitle>
			<link rel="self" href="http://pipes.yahoo.com/pipes/pipe.run?_id=c4fc06896b8f6e45b3be8c84dea6ab71&amp;_render=rss" />
			<id>http://pipes.yahoo.com/pipes/pipe.info?_id=c4fc06896b8f6e45b3be8c84dea6ab71</id>
		</source>
	<feedburner:origLink>http://www.element84.com/ruby-clojure-integration.html</feedburner:origLink></entry>

	<entry>
		<title type="html" xml:lang="en">EuroClojure Day 2</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/HXrgVLLiYS0/" />
		<id>http://rrees.wordpress.com/?p=829</id>
		<updated>2012-05-27T22:57:40+00:00</updated>
		<content type="html" xml:lang="en">&lt;p&gt;Okay so this post maybe happening a little later than Friday but in my defence there were some excellent conversations to go with the after-conference drinks.&lt;/p&gt;
&lt;p&gt;Day 2 featured two talks by Rich Hickey, I had already seen some of the Datomic stuff from QCon and the web so I found the stuff on the new reducers library more engaging. I have never thought of map having an implicit ordering promise.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://euroclojure.com/2012/speakers/#Meikel_Brandmeyer"&gt;Meikel Brandmeyer&lt;/a&gt; gave a historical review of lazy seq which was really helpful for understanding laziness (something I have a bit of a problem with). One of the real highlights though was Chris Ford’s talk about &lt;a href="https://github.com/ctford/goldberg"&gt;canon music&lt;/a&gt;. It started with a good gag about sheet music being a DSL for using the finite state machine otherwise known as a musician. However the really amazing thing was Chris’s abstraction of the score and subsequent transformations of the abstract score to end up with variations on the base canon he had chosen. Really amazing. Chris’s talk really shouldn’t have been a lightning talk, it is about the only quibble I had with the programming.&lt;/p&gt;
&lt;p&gt;Sam Newman also had an excellent closing line in his lightning talk on Riemann, which was if people want Clojure to be adopted widely then the secret is to create great things with Clojure.&lt;/p&gt;
&lt;br /&gt;  &lt;a href="http://feeds.wordpress.com/1.0/gocomments/rrees.wordpress.com/829/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rrees.wordpress.com/829/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/godelicious/rrees.wordpress.com/829/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rrees.wordpress.com/829/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/gofacebook/rrees.wordpress.com/829/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rrees.wordpress.com/829/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/gotwitter/rrees.wordpress.com/829/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rrees.wordpress.com/829/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/gostumble/rrees.wordpress.com/829/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rrees.wordpress.com/829/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/godigg/rrees.wordpress.com/829/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rrees.wordpress.com/829/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/goreddit/rrees.wordpress.com/829/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rrees.wordpress.com/829/" /&gt;&lt;/a&gt; &lt;img alt="" border="0" height="1" src="http://stats.wordpress.com/b.gif?host=rrees.wordpress.com&amp;amp;blog=181521&amp;amp;post=829&amp;amp;subd=rrees&amp;amp;ref=&amp;amp;feed=1" width="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=HXrgVLLiYS0:5FuW_4Isw-E:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=HXrgVLLiYS0:5FuW_4Isw-E:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/HXrgVLLiYS0" height="1" width="1"/&gt;</content>
		<author>
			<name>rrees</name>
			<uri>http://rrees.wordpress.com</uri>
		</author>
		<source>
			<title type="html">Echo One » clojure</title>
			<subtitle type="html">Sequentially arranged sentences composed of words (and punctuation)</subtitle>
			<link rel="self" href="http://rrees.wordpress.com/tag/clojure/feed/" />
			<id>http://rrees.wordpress.com</id>
		</source>
	<feedburner:origLink>http://rrees.wordpress.com/2012/05/27/euroclojure-day-2/</feedburner:origLink></entry>

	<entry>
		<title type="html" xml:lang="en">Reflections on Euroclojure</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/Tmvj8o15RiU/" />
		<id>http://simonholgate.wordpress.com/?p=33</id>
		<updated>2012-05-27T19:58:41+00:00</updated>
		<content type="html" xml:lang="en">&lt;p&gt;I spent Thursday and Friday last week attending the first &lt;a href="http://www.clojure.org/" target="_blank" title="The Clojure website"&gt;Clojure&lt;/a&gt; conference outside of the US – &lt;a href="http://euroclojure.com/2012/" target="_blank" title="Euroclojure 2012"&gt;Euroclojure&lt;/a&gt; – in London. I’ve got to say that I’ve come back feeling really excited by what I saw there.&lt;/p&gt;
&lt;p&gt;I’ve been to many conferences before and this one was quite small in comparison with those. However, with 200 enthusiastic coders from the UK, Europe, the US and Canada, it was a really great and friendly place to be. More importantly there were plenty of great ideas talked about as well.&lt;/p&gt;
&lt;p&gt;Clojure is a really exciting young language. It’s embracement of the Java and the JVM has allowed many at the conference to bring in elegant solutions to existing legacy (Java) software without wholesale rewrites. In every case this has been achieved with less code and faster results. That has to be great news!&lt;/p&gt;
&lt;p&gt;Better still was hearing about the things that are really fresh and new such as experimenting with dynamic programming of music in &lt;a href="http://overtone.github.com/" target="_blank" title="Overtone -  Making music in Clojure"&gt;Overtone&lt;/a&gt; (like modifying waveforms in real time to see how the sound is affected) or demonstrating JS Bach’s Canons in Overtone or dynamic algorithmic &lt;a href="http://www.cassiel.com/" target="_blank" title="Nick Rothwell's art with Clojure"&gt;art displays&lt;/a&gt; using Clojure. Not that programming is just about art! There were also great talks on logic programming, solving concurrency issues in databases with &lt;a href="http://datomic.com/" target="_blank"&gt;Datomic&lt;/a&gt;, automating deployments in the Cloud with &lt;a href="http://palletops.com/" target="_blank"&gt;Pallet&lt;/a&gt;, and data processing in Hadoop with &lt;a href="http://nathanmarz.com/blog/introducing-cascalog-a-clojure-based-query-language-for-hado.html" target="_blank" title="Cascalog for data processing on Hadoop with Clojure"&gt;Cascalog&lt;/a&gt; to name a few.&lt;/p&gt;
&lt;p&gt;So many talks in such a small amount of time was pretty mind blowing, especially given the heat, but meeting so many great people was fantastic. Roll on Euroclojure 2013!&lt;/p&gt;
&lt;br /&gt;  &lt;a href="http://feeds.wordpress.com/1.0/gocomments/simonholgate.wordpress.com/33/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/simonholgate.wordpress.com/33/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/godelicious/simonholgate.wordpress.com/33/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/simonholgate.wordpress.com/33/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/gofacebook/simonholgate.wordpress.com/33/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/simonholgate.wordpress.com/33/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/gotwitter/simonholgate.wordpress.com/33/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/simonholgate.wordpress.com/33/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/gostumble/simonholgate.wordpress.com/33/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/simonholgate.wordpress.com/33/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/godigg/simonholgate.wordpress.com/33/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/simonholgate.wordpress.com/33/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/goreddit/simonholgate.wordpress.com/33/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/simonholgate.wordpress.com/33/" /&gt;&lt;/a&gt; &lt;img alt="" border="0" height="1" src="http://stats.wordpress.com/b.gif?host=simonholgate.wordpress.com&amp;amp;blog=10488004&amp;amp;post=33&amp;amp;subd=simonholgate&amp;amp;ref=&amp;amp;feed=1" width="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=Tmvj8o15RiU:rCMa_Z-zMbY:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=Tmvj8o15RiU:rCMa_Z-zMbY:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/Tmvj8o15RiU" height="1" width="1"/&gt;</content>
		<author>
			<name>simonholgate</name>
			<uri>http://simonholgate.wordpress.com</uri>
		</author>
		<source>
			<title type="html">Simon Holgate's Blog » Clojure</title>
			<subtitle type="html">Discussions related to sea level science</subtitle>
			<link rel="self" href="http://simonholgate.wordpress.com/category/clojure/feed/" />
			<id>http://simonholgate.wordpress.com</id>
		</source>
	<feedburner:origLink>http://simonholgate.wordpress.com/2012/05/27/reflections-on-euroclojure/</feedburner:origLink></entry>

	<entry>
		<title type="html" xml:lang="en">Project Euler in Clojure – Problem 3</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/qwGaLionXig/" />
		<id>http://proctorit.wordpress.com/?p=144</id>
		<updated>2012-05-27T19:37:28+00:00</updated>
		<content type="html" xml:lang="en">&lt;p&gt;In trying to learn Clojure and wrap my head around good functional programming, and hoping to learn more idiomatic Clojure, I have started working through the Project Euler problems. In doing this, I have also setup a repository on &lt;a href="http://www.github.com"&gt;github.com&lt;/a&gt; to keep track of my progress, which can be found at &lt;a href="https://github.com/stevenproctor/project-euler-clojure"&gt;https://github.com/stevenproctor/project-euler-clojure&lt;/a&gt;.  My approach to Problem 2 can be found &lt;a href="http://proctorit.wordpress.com/2012/05/27/project-euler-in-clojure-problem-2/" title="Project Euler in Clojure – Problem 2"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://projecteuler.net/problem=3"&gt;Problem 3&lt;/a&gt; of Project Euler is described as:&lt;/p&gt;
&lt;pre&gt;What is the largest prime factor of the number 600851475143 ?&lt;/pre&gt;
&lt;p&gt;For this problem, I needed to generate the prime factors of a number.  In order to generate the prime factors, I decided to pul out the Uncle Bob’s (found &lt;a href="https://twitter.com/unclebobmartin"&gt;here&lt;/a&gt;, &lt;a href="http://blog.8thlight.com/uncle-bob/archive.html"&gt;here&lt;/a&gt;, &lt;a href="http://blog.objectmentor.com/articles/category/uncle-bobs-blatherings"&gt;here&lt;/a&gt;, and &lt;a href="http://butunclebob.com/ArticleS.UncleBob"&gt;here&lt;/a&gt;) &lt;a href="http://www.viddler.com/v/17023668"&gt;Prime Factors Kata&lt;/a&gt; and apply it to Clojure.  By doing this kata, I test drove the result, and decided I would give &lt;a href="http://www.exampler.com/blog/"&gt;Brian Marick’s&lt;/a&gt; &lt;a href="https://github.com/marick/Midje"&gt;Midje&lt;/a&gt; a shot and play with that some as well.  The resulting tests are as follows.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;pre class="brush: clojure;"&gt;(ns project-euler.prime-factors-test
  (:use clojure.test
        midje.sweet
        project-euler.core))

(defn mersenne [n]
  (int (dec (Math/pow 2 n))))

(fact
  (prime-factors-of 1) =&amp;gt; []
  (prime-factors-of 2) =&amp;gt; [2]
  (prime-factors-of 3) =&amp;gt; [3]
  (prime-factors-of 4) =&amp;gt; [2 2]
  (prime-factors-of 5) =&amp;gt; [5]
  (prime-factors-of 6) =&amp;gt; [2 3]
  (prime-factors-of 7) =&amp;gt; [7]
  (prime-factors-of 8) =&amp;gt; [2 2 2]
  (prime-factors-of 9) =&amp;gt; [3 3]
  (prime-factors-of 10) =&amp;gt; [2 5]
  (prime-factors-of 11) =&amp;gt; [11]
  (prime-factors-of 12) =&amp;gt; [2 2 3]
  (prime-factors-of 16) =&amp;gt; [2 2 2 2]
  (prime-factors-of 25) =&amp;gt; [5 5]
  (prime-factors-of (* 2 3 5 7 11 17 37)) =&amp;gt; [2 3 5 7 11 17 37]
  (prime-factors-of (mersenne 17)) =&amp;gt; [(mersenne 17)])
&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The total solution to problem 3 is as follows, with the test driven function for generating the prime factors, is:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;pre class="brush: clojure;"&gt;(defn factors-starting-at [f n]
  (cond (= n 1) []
        (zero? (rem n f)) (cons f (factors-starting-at f (/ n f)))
        :else (recur (inc f) n)))

(defn prime-factors-of [n]
  (factors-starting-at 2 n))

(defn problem3 []
  (reduce max (prime-factors-of 600851475143)))
&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The resulting function for prime-factors-of calls the recursive function factors-starting-at with the first factor of 2, and the number itself.  The factors-starting-at returns an empty vector when n is one.  When the factor is actually a factor of the number (zero? (rem n f)) the returned result is the factor cons’ed onto the result of calling factors-starting-at again with the same factor, and the number divided by that factor.  Otherwise, we return the result of recur-ing with the same number and the factor incremented again.&lt;/p&gt;
&lt;p&gt;The solution to problem 3 is actually very simple in Clojure after one generates the prime factors for a number.  All that one has to do is reduce the sequence of prime factors with the function max to find the largest prime factor for the number 600851475143.&lt;/p&gt;
&lt;p&gt;I would love comments and suggestions on my solution to this problem, and if there are tweaks to make it more Clojure-ish.&lt;/p&gt;
&lt;p&gt;–Proctor&lt;/p&gt;
&lt;br /&gt;Filed under: &lt;a href="http://proctorit.wordpress.com/category/clojure/"&gt;Clojure&lt;/a&gt;, &lt;a href="http://proctorit.wordpress.com/category/deliberate-practice/"&gt;Deliberate Practice&lt;/a&gt;, &lt;a href="http://proctorit.wordpress.com/category/lisp/"&gt;Lisp&lt;/a&gt;, &lt;a href="http://proctorit.wordpress.com/category/project-euler/"&gt;Project Euler&lt;/a&gt; Tagged: &lt;a href="http://proctorit.wordpress.com/tag/clojure/"&gt;Clojure&lt;/a&gt;, &lt;a href="http://proctorit.wordpress.com/tag/deliberate-practice/"&gt;Deliberate Practice&lt;/a&gt;, &lt;a href="http://proctorit.wordpress.com/tag/project-euler/"&gt;Project Euler&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/gocomments/proctorit.wordpress.com/144/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/proctorit.wordpress.com/144/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/godelicious/proctorit.wordpress.com/144/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/proctorit.wordpress.com/144/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/gofacebook/proctorit.wordpress.com/144/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/proctorit.wordpress.com/144/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/gotwitter/proctorit.wordpress.com/144/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/proctorit.wordpress.com/144/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/gostumble/proctorit.wordpress.com/144/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/proctorit.wordpress.com/144/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/godigg/proctorit.wordpress.com/144/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/proctorit.wordpress.com/144/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/goreddit/proctorit.wordpress.com/144/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/proctorit.wordpress.com/144/" /&gt;&lt;/a&gt; &lt;img alt="" border="0" height="1" src="http://stats.wordpress.com/b.gif?host=proctorit.wordpress.com&amp;amp;blog=16765922&amp;amp;post=144&amp;amp;subd=proctorit&amp;amp;ref=&amp;amp;feed=1" width="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=qwGaLionXig:LM-7Kpbxs7A:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=qwGaLionXig:LM-7Kpbxs7A:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/qwGaLionXig" height="1" width="1"/&gt;</content>
		<author>
			<name>Proctor</name>
			<uri>http://proctorit.wordpress.com</uri>
		</author>
		<source>
			<title type="html">Proctor It » Clojure</title>
			<link rel="self" href="http://proctorit.wordpress.com/category/clojure/feed/" />
			<id>http://proctorit.wordpress.com</id>
		</source>
	<feedburner:origLink>http://proctorit.wordpress.com/2012/05/27/project-euler-in-clojure-problem-3/</feedburner:origLink></entry>

	<entry>
		<title type="html" xml:lang="en">Project Euler in Clojure – Problem 2</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/EhxbvMAJ9FE/" />
		<id>http://proctorit.wordpress.com/?p=137</id>
		<updated>2012-05-27T19:04:05+00:00</updated>
		<content type="html" xml:lang="en">&lt;p&gt;In trying to learn Clojure and wrap my head around good functional programming, and hoping to learn more idiomatic Clojure, I have started working through the Project Euler problems. In doing this, I have also setup a repository on &lt;a href="http://www.github.com"&gt;github.com&lt;/a&gt; to keep track of my progress, which can be found at &lt;a href="https://github.com/stevenproctor/project-euler-clojure"&gt;https://github.com/stevenproctor/project-euler-clojure&lt;/a&gt;.  My approach to Problem 1 can be found &lt;a href="http://proctorit.wordpress.com/2012/05/27/project-euler-in-clojure-problem-1/" title="Project Euler in Clojure – Problem 1"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://projecteuler.net/problem=2"&gt;Problem 2&lt;/a&gt; of Project Euler is described as:&lt;/p&gt;
&lt;pre&gt;By considering the terms in the Fibonacci sequence whose values do
not exceed four million, find the sum of the even-valued terms.&lt;/pre&gt;
&lt;p&gt;The solution I came up with is:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;pre class="brush: clojure;"&gt;(defn skip-n [n s]
  (cond
    (&amp;lt;= n 0) s
    :else (recur (dec n) (rest s))))

(defn fib
  ([] (concat [0N 1N] (fib 0N 1N)))
  ([a b] (let [c (+ a b)]
          (lazy-seq
            (cons c (fib b c))))))

(defn problem2 []
  (reduce + (filter #(even? %) (take-while #(&amp;lt; % 4000000N) (skip-n 2 (fib))))))
&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;
&lt;p&gt;As a didn’t see a skip function, which would keep a sequence, but skip over a given number of inputs, I created the function skip-n.  The skip function calls the function rest on the sequence n number of times by using recur, and decrementing n.&lt;/p&gt;
&lt;p&gt;The function fib generates the Fibonacci sequence lazily by using the function lazy-seq to create a lazily evaluated sequence, as I want the numbers generated until the time that I decide I do not need them anymore.  Instead of trying to determine how many that will be before I generate them, I just decided to make them generated lazily.&lt;/p&gt;
&lt;p&gt;The previous two functions were a helper function, and the function to generate the Fibonacci sequence (huh, sequence is even in the name).  The work to determine the results of the problem are found in the function problem2.  This function uses the skip-n function to skip the first two results, as Project Euler shows the Fibonacci sequence starting as 1, 2, 3, … instead of the starting as 0, 1, 1, 2, 3, … so I skip the first two in the sequence.  I then use the take-while function to take only those items which are less than 4 million, which I then feed to the filter function to take only those items from the Fibonacci sequence that are even.  The last step is to use the reduce function to sum all of those items together to get the final result.&lt;/p&gt;
&lt;p&gt;I would love comments and suggestions on my solution to this problem, and if there are tweaks to make it more Clojure-ish.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;**Updated**&lt;/strong&gt;&lt;br /&gt;
Here is my approach to &lt;a href="http://proctorit.wordpress.com/2012/05/27/project-euler-in-clojure-problem-3/" title="Project Euler in Clojure – Problem 3"&gt;Problem 3 in Clojure.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;–Proctor&lt;/p&gt;
&lt;br /&gt;Filed under: &lt;a href="http://proctorit.wordpress.com/category/clojure/"&gt;Clojure&lt;/a&gt;, &lt;a href="http://proctorit.wordpress.com/category/deliberate-practice/"&gt;Deliberate Practice&lt;/a&gt;, &lt;a href="http://proctorit.wordpress.com/category/lisp/"&gt;Lisp&lt;/a&gt;, &lt;a href="http://proctorit.wordpress.com/category/project-euler/"&gt;Project Euler&lt;/a&gt; Tagged: &lt;a href="http://proctorit.wordpress.com/tag/clojure/"&gt;Clojure&lt;/a&gt;, &lt;a href="http://proctorit.wordpress.com/tag/deliberate-practice/"&gt;Deliberate Practice&lt;/a&gt;, &lt;a href="http://proctorit.wordpress.com/tag/project-euler/"&gt;Project Euler&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/gocomments/proctorit.wordpress.com/137/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/proctorit.wordpress.com/137/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/godelicious/proctorit.wordpress.com/137/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/proctorit.wordpress.com/137/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/gofacebook/proctorit.wordpress.com/137/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/proctorit.wordpress.com/137/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/gotwitter/proctorit.wordpress.com/137/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/proctorit.wordpress.com/137/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/gostumble/proctorit.wordpress.com/137/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/proctorit.wordpress.com/137/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/godigg/proctorit.wordpress.com/137/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/proctorit.wordpress.com/137/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/goreddit/proctorit.wordpress.com/137/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/proctorit.wordpress.com/137/" /&gt;&lt;/a&gt; &lt;img alt="" border="0" height="1" src="http://stats.wordpress.com/b.gif?host=proctorit.wordpress.com&amp;amp;blog=16765922&amp;amp;post=137&amp;amp;subd=proctorit&amp;amp;ref=&amp;amp;feed=1" width="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=EhxbvMAJ9FE:pf4vwu6A5pg:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=EhxbvMAJ9FE:pf4vwu6A5pg:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/EhxbvMAJ9FE" height="1" width="1"/&gt;</content>
		<author>
			<name>Proctor</name>
			<uri>http://proctorit.wordpress.com</uri>
		</author>
		<source>
			<title type="html">Proctor It » Clojure</title>
			<link rel="self" href="http://proctorit.wordpress.com/category/clojure/feed/" />
			<id>http://proctorit.wordpress.com</id>
		</source>
	<feedburner:origLink>http://proctorit.wordpress.com/2012/05/27/project-euler-in-clojure-problem-2/</feedburner:origLink></entry>

	<entry>
		<title type="html" xml:lang="en">EuroClojure 2012 – Part 1</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/Pkl6cKJFs4o/" />
		<id>http://otfrom.wordpress.com/?p=74</id>
		<updated>2012-05-27T19:01:09+00:00</updated>
		<content type="html" xml:lang="en">&lt;p&gt;At the end of a very busy week was the highlight for me. &lt;a href="http://euroclojure.com/2012/"&gt;EuroClojure&lt;/a&gt; 2012 was a chance to gather about 250 clojurians from Europe and further afield. There were keynotes from Stuart Halloway and Rich Hickey. Due to one speaker not being able to make it there was an extra talk from Rich Hickey so we heard more about the new &lt;a href="http://clojure.com/blog/2012/05/15/anatomy-of-reducer.html" title="Reducers"&gt;Reducers&lt;/a&gt; library and &lt;a href="http://datomic.com/" title="Datomic"&gt;Datomic&lt;/a&gt;. I gave a talk on &lt;a href="https://github.com/liebke/incanter" title="Incanter"&gt;Incanter&lt;/a&gt;. The code and presentation for that can be found on my &lt;a href="https://github.com/otfrom/quiddswic"&gt;github repo&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;Here are a few of the highlights for me.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://twitter.com/#!/sthuebner"&gt;Stefan Hübner&lt;/a&gt; gave a great talk on &lt;a href="https://github.com/nathanmarz/cascalog/wiki"&gt;Cascalog&lt;/a&gt;. I love the idea of having a query language for local data, random bits of data and things on disk and in memory all the way up to a hadoop cluster. While Datomic looks really cool to play with once you have your data together, Cascalog looks like a great way of getting that data into a reasonable format.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://twitter.com/pingles"&gt;Paul Ingles&lt;/a&gt; talk on Users as Data fit into this. What I took away was how lossy data warehouses are. Keeping as much data about user events (similar to the CQRS/eve(nt) talk from &lt;a href="http://euroclojure.com/2012/speakers/#Max_Weber"&gt;Max Weber&lt;/a&gt;). I’d love to have everything in Datomic, but I know I live in a messier world than that, so I’ll always end up using something like Cascalog. Events were again central to &lt;a href="http://euroclojure.com/2012/speakers/#Zach_Tellman"&gt;Zach Tellman’s&lt;/a&gt; talk on &lt;a href="https://github.com/ztellman/lamina"&gt;lamina&lt;/a&gt;.&lt;/p&gt;
&lt;br /&gt;  &lt;a href="http://feeds.wordpress.com/1.0/gocomments/otfrom.wordpress.com/74/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/otfrom.wordpress.com/74/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/godelicious/otfrom.wordpress.com/74/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/otfrom.wordpress.com/74/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/gofacebook/otfrom.wordpress.com/74/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/otfrom.wordpress.com/74/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/gotwitter/otfrom.wordpress.com/74/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/otfrom.wordpress.com/74/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/gostumble/otfrom.wordpress.com/74/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/otfrom.wordpress.com/74/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/godigg/otfrom.wordpress.com/74/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/otfrom.wordpress.com/74/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/goreddit/otfrom.wordpress.com/74/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/otfrom.wordpress.com/74/" /&gt;&lt;/a&gt; &lt;img alt="" border="0" height="1" src="http://stats.wordpress.com/b.gif?host=otfrom.wordpress.com&amp;amp;blog=6096936&amp;amp;post=74&amp;amp;subd=otfrom&amp;amp;ref=&amp;amp;feed=1" width="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=Pkl6cKJFs4o:B1vnYst6AYM:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=Pkl6cKJFs4o:B1vnYst6AYM:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/Pkl6cKJFs4o" height="1" width="1"/&gt;</content>
		<author>
			<name>otfrom</name>
			<uri>http://otfrom.wordpress.com</uri>
		</author>
		<source>
			<title type="html">Wifi and Coffee » clojure</title>
			<subtitle type="html">Hunting around for good coffee and free wifi.</subtitle>
			<link rel="self" href="http://otfrom.wordpress.com/tag/clojure/feed/" />
			<id>http://otfrom.wordpress.com</id>
		</source>
	<feedburner:origLink>http://otfrom.wordpress.com/2012/05/27/euroclojure-2012-overview-and-day-one/</feedburner:origLink></entry>

	<entry>
		<title type="html">EuroClojure 2012</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/Iiz-u-jUYDw/euroclojure-2012.html" />
		<id>tag:blogger.com,1999:blog-6523621596553394172.post-2033428459682868759</id>
		<updated>2012-05-27T13:59:20+00:00</updated>
		<content type="html">&lt;span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;WOW... &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;a href="http://euroclojure.com/2012/" target="_blank"&gt;EuroClojure 2012&lt;/a&gt; ended Friday and what an excellent conference it was. As &lt;a href="http://twitter.com/#!/stuarthalloway" target="_blank"&gt;Stuart Halloway&lt;/a&gt; said: the hottest conference in Europe. Lots of interesting talks, lots of performances and even more interesting people. I talked to people from all over Europe and there were even quite a few people from the US, not just the &lt;a href="http://thinkrelevance.com/" target="_blank"&gt;Relevance&lt;/a&gt; folks. A few things that stuck:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;Thanks to HOF one can burn 400 of the 600 pages of the GoF book&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;Keep track of events, not states&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;a href="https://github.com/overtone" target="_blank"&gt;Overtone&lt;/a&gt; is extremely cool&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;a href="https://github.com/ctford/goldberg" target="_blank"&gt;Bach&lt;/a&gt; was a functional programmer ;)&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;I really should try the new reducer framework&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;More Clojure in general&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;We are definitely going to start a Hampshire Clojurians group&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;Rich Hickey is a really nice guy (Just like all the other Clojurians)&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;I hope to see everyone again next year!!!&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;"&gt;ps. and Marco is an excellent event organiser, thank you.&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img alt="" height="1" src="https://blogger.googleusercontent.com/tracker/6523621596553394172-2033428459682868759?l=clojure-and-me.blogspot.com" width="1" /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=Iiz-u-jUYDw:jJx38ZcYAfo:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=Iiz-u-jUYDw:jJx38ZcYAfo:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/Iiz-u-jUYDw" height="1" width="1"/&gt;</content>
		<author>
			<name>Tom</name>
			<email>noreply@blogger.com</email>
			<uri>http://clojure-and-me.blogspot.com/</uri>
		</author>
		<source>
			<title type="html">(+ Clojure me)</title>
			<subtitle type="html">Me talking about my experiences with Clojure.</subtitle>
			<link rel="self" href="http://www.blogger.com/feeds/6523621596553394172/posts/default" />
			<id>tag:blogger.com,1999:blog-6523621596553394172</id>
		</source>
	<feedburner:origLink>http://clojure-and-me.blogspot.com/2012/05/euroclojure-2012.html</feedburner:origLink></entry>

	<entry>
		<title type="html">My first Clojure macro</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/38pEPo48yho/23859237480" />
		<id>http://sastanin.tumblr.com/post/23859237480</id>
		<updated>2012-05-27T13:13:00+00:00</updated>
		<content type="html">&lt;p&gt;is &lt;code&gt;macro?&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;(defmacro macro? [form]
    "Return true if form is a macro."
    `(:macro (meta #'~form) false))
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Use case: I am new to the language, and don’t know yet when to quote arguments. With &lt;code&gt;macro?&lt;/code&gt; and the REPL it’s quick to learn. Example:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;user=&amp;gt; (macro? macro?)
true
user=&amp;gt; (macro? next)
false
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It’s funny that to operate on macros you need a (read-time) macro.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=38pEPo48yho:1oztPL-rjdU:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=38pEPo48yho:1oztPL-rjdU:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/38pEPo48yho" height="1" width="1"/&gt;</content>
		<author>
			<name>Sergey Astanin</name>
			<uri>http://sastanin.tumblr.com/</uri>
		</author>
		<source>
			<title type="html">140+</title>
			<subtitle type="html">Known as @sastanin on Twitter.</subtitle>
			<link rel="self" href="http://sastanin.tumblr.com/tagged/clojure/rss" />
			<id>http://sastanin.tumblr.com/</id>
		</source>
	<feedburner:origLink>http://sastanin.tumblr.com/post/23859237480</feedburner:origLink></entry>

	<entry>
		<title type="html">No such pipe, or this pipe has been deleted</title>
		<link href="" />
		<id>http://pipes.yahoo.com/pipes/21c2a96208e329bcffb14a3d4c4f6002_91db4ebf78324471a67792487feb8098</id>
		<updated>2012-05-27T05:19:18+00:00</updated>
		<content type="html">This data comes from pipes.yahoo.com but the Pipe does not exist or has been deleted.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=Ro2eosQjYao:rhfMXPWh33k:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=Ro2eosQjYao:rhfMXPWh33k:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<author>
			<name>Paul Gross</name>
			<uri>http://pipes.yahoo.com/pipes/pipe.info?_id=21c2a96208e329bcffb14a3d4c4f6002</uri>
		</author>
		<source>
			<title type="html">Pipes Output</title>
			<subtitle type="html">Pipes Output</subtitle>
			<link rel="self" href="http://pipes.yahoo.com/pipes/pipe.run?_id=21c2a96208e329bcffb14a3d4c4f6002&amp;_render=rss" />
			<id>http://pipes.yahoo.com/pipes/pipe.info?_id=21c2a96208e329bcffb14a3d4c4f6002</id>
		</source>
	</entry>

	<entry>
		<title type="html">No such pipe, or this pipe has been deleted</title>
		<link href="" />
		<id>http://pipes.yahoo.com/pipes/2055776f94cf79727174c44546724ee0_db565e3a84a1bbf305edffcf5ff9737f</id>
		<updated>2012-05-27T05:16:39+00:00</updated>
		<content type="html">This data comes from pipes.yahoo.com but the Pipe does not exist or has been deleted.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=Ro2eosQjYao:NPscWKkLZck:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=Ro2eosQjYao:NPscWKkLZck:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<author>
			<name>Dhananjay Nene</name>
			<uri>http://pipes.yahoo.com/pipes/pipe.info?_id=2055776f94cf79727174c44546724ee0</uri>
		</author>
		<source>
			<title type="html">Pipes Output</title>
			<subtitle type="html">Pipes Output</subtitle>
			<link rel="self" href="http://pipes.yahoo.com/pipes/pipe.run?_id=2055776f94cf79727174c44546724ee0&amp;_render=rss" />
			<id>http://pipes.yahoo.com/pipes/pipe.info?_id=2055776f94cf79727174c44546724ee0</id>
		</source>
	</entry>

	<entry>
		<title type="html">No such pipe, or this pipe has been deleted</title>
		<link href="" />
		<id>http://pipes.yahoo.com/pipes/1a0cc5a5b729058f58307f00a728dc72_e08cb91fd57f96eec1e1a779813e01ac</id>
		<updated>2012-05-27T05:15:18+00:00</updated>
		<content type="html">This data comes from pipes.yahoo.com but the Pipe does not exist or has been deleted.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=Ro2eosQjYao:qAtxPMuP3Eg:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=Ro2eosQjYao:qAtxPMuP3Eg:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<author>
			<name>Asymmetrical View</name>
			<uri>http://pipes.yahoo.com/pipes/pipe.info?_id=1a0cc5a5b729058f58307f00a728dc72</uri>
		</author>
		<source>
			<title type="html">Pipes Output</title>
			<subtitle type="html">Pipes Output</subtitle>
			<link rel="self" href="http://pipes.yahoo.com/pipes/pipe.run?_id=1a0cc5a5b729058f58307f00a728dc72&amp;_render=rss" />
			<id>http://pipes.yahoo.com/pipes/pipe.info?_id=1a0cc5a5b729058f58307f00a728dc72</id>
		</source>
	</entry>

	<entry>
		<title type="html">No such pipe, or this pipe has been deleted</title>
		<link href="" />
		<id>http://pipes.yahoo.com/pipes/558531c1af53cd942ca89854c501ef2b_f9d7e244861d69e6d313a2456a9c5ad3</id>
		<updated>2012-05-27T05:12:46+00:00</updated>
		<content type="html">This data comes from pipes.yahoo.com but the Pipe does not exist or has been deleted.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=Ro2eosQjYao:uUxTIBDR9PM:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=Ro2eosQjYao:uUxTIBDR9PM:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<author>
			<name>Two Negatives Blog</name>
			<uri>http://pipes.yahoo.com/pipes/pipe.info?_id=558531c1af53cd942ca89854c501ef2b</uri>
		</author>
		<source>
			<title type="html">Pipes Output</title>
			<subtitle type="html">Pipes Output</subtitle>
			<link rel="self" href="http://pipes.yahoo.com/pipes/pipe.run?_id=558531c1af53cd942ca89854c501ef2b&amp;_render=rss" />
			<id>http://pipes.yahoo.com/pipes/pipe.info?_id=558531c1af53cd942ca89854c501ef2b</id>
		</source>
	</entry>

	<entry>
		<title type="html">No such pipe, or this pipe has been deleted</title>
		<link href="" />
		<id>http://pipes.yahoo.com/pipes/b502b5f586e3cf34b6cb55420e489fd9_65a1ace07d83bd238e27a444d0351f35</id>
		<updated>2012-05-27T05:07:34+00:00</updated>
		<content type="html">This data comes from pipes.yahoo.com but the Pipe does not exist or has been deleted.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=Ro2eosQjYao:NyGJQY2I6_U:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=Ro2eosQjYao:NyGJQY2I6_U:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<author>
			<name>Patrick Stein</name>
			<uri>http://pipes.yahoo.com/pipes/pipe.info?_id=b502b5f586e3cf34b6cb55420e489fd9</uri>
		</author>
		<source>
			<title type="html">Pipes Output</title>
			<subtitle type="html">Pipes Output</subtitle>
			<link rel="self" href="http://pipes.yahoo.com/pipes/pipe.run?_id=b502b5f586e3cf34b6cb55420e489fd9&amp;_render=rss" />
			<id>http://pipes.yahoo.com/pipes/pipe.info?_id=b502b5f586e3cf34b6cb55420e489fd9</id>
		</source>
	</entry>

	<entry>
		<title type="html" xml:lang="en">EuroClojure Wrapup</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/1ZaaBnHq3WQ/" />
		<id>http://cataclysmicmutation.com/?p=336</id>
		<updated>2012-05-26T13:57:00+00:00</updated>
		<content type="html">[Edit: So I accidentally published this a bit early, and I've only now had time to get home and add a bit of polish and details that were lacking, so if you read an earlier version, the content is very slightly different now.]   I’m just back from the first European Clojure conference in London, [...]&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=1ZaaBnHq3WQ:EROi9ec2iE8:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=1ZaaBnHq3WQ:EROi9ec2iE8:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/1ZaaBnHq3WQ" height="1" width="1"/&gt;</content>
		<author>
			<name>deong</name>
			<uri>http://cataclysmicmutation.com</uri>
		</author>
		<source>
			<title type="html">Cataclysmic Mutation » clojure</title>
			<subtitle type="html">Random musings about Iceland, AI, and Tölvunarfræði (that's Computer Science to you).</subtitle>
			<link rel="self" href="http://cataclysmicmutation.com/category/clojure/feed/" />
			<id>http://cataclysmicmutation.com</id>
		</source>
	<feedburner:origLink>http://cataclysmicmutation.com/2012/05/euroclojure-wrapup/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=euroclojure-wrapup</feedburner:origLink></entry>

	<entry>
		<title type="html">Pitch and Frequency</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/Ir5dJKdTqSw/pitch-and-frequency" />
		<id>http://rhebus.posterous.com/pitch-and-frequency</id>
		<updated>2012-05-26T10:39:00+00:00</updated>
		<content type="html">&lt;p&gt;
	&lt;/p&gt;&lt;p&gt;I’ve just come back from
&lt;a href="http://euroclojure.com/2012/"&gt;EuroClojure 2012&lt;/a&gt;, where there were a
number of Overtone talks and a number of tweets asking for music
theory resources aimed at computer scientists. This will hopefully
blog number 1 in a series on that theme.&lt;/p&gt;

&lt;p&gt;Note that the code examples are designed to be pasted into a Clojure
repl, so that you can take the code and play with it yourself.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;The basic atoms of synthesizing sounds in Overtone are
oscillators. An oscillator takes a frequency and makes a noise. Here
are some examples:&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;(use 'overtone.live)
(demo (sin-osc 440))  ; sine wave
(demo (saw 440))      ; saw-tooth wave
(demo (square 440))   ; square wave&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;In each of these, we’re making an oscillator and giving it a frequency
of 440 Hz — or equivalently, 440 cycles per second (cps). The problem
we find is that most music isn’t defined in terms of frequency, it’s
defined in terms of notes of the scale: C D E F G A B C and all the
sharps and flats in between. How do we play a tune on a sine wave
generator when the tune is made of notes rather than frequencies?&lt;/p&gt;

&lt;p&gt;First, let’s write some helpers to play a sequence of frequencies
through a sine wave:&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;(definst sine-wave [freq 440]
   (sin-osc freq))
;=&amp;gt; #&amp;lt;instrument: sine-wave&amp;gt;
(defn play-freqs
      ([freqs] (play-freqs freqs (now) (sine-wave (first freqs))))
      ([freqs time inst]
        (if-let [freqs (seq freqs)]
          (do (at time (ctl (:id inst) :freq (first freqs)))
              (apply-at (+ time 300) #'play-freqs [(rest freqs) (+ time 300) inst]))
          (at time (kill (:id inst))))))
;=&amp;gt; #'user/play-freqs
(play-freqs [440 660 330 440 220 880 220])
; *beautiful melody*
;=&amp;gt; #&amp;lt;ScheduledJob id: 76, created-at: Sat 09:32:26s, initial-delay: 0, desc: "Overtone delayed fn", scheduled? false&amp;gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;We define a simple intrument, &lt;code&gt;sine-wave&lt;/code&gt;, which has one parameter,
&lt;code&gt;freq&lt;/code&gt;. We can start the instrument with a particular frequency by
writing &lt;code&gt;(sine-wave 440)&lt;/code&gt;; this returns a map of data about the
particular oscillator instance which is generating the note. We can
change the freq parameter of a running instrument by using
&lt;code&gt;(ctl (:id inst) :freq 660)&lt;/code&gt;. Finally, we can stop a running inst with
&lt;code&gt;(kill (:id inst))&lt;/code&gt;. (And if it all goes horribly wrong, we can stop
absolutely everything with &lt;code&gt;(stop)&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Our goal is to be able to use &lt;code&gt;play-freqs&lt;/code&gt; to play tunes made of
keywords rather than frequencies: &lt;code&gt;[:c4 :d4 :e4 :d4 :c4]&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;Frequency of notes from first principles&lt;/h2&gt;

&lt;p&gt;You can calculate frequency from pitch using only four fundamental
axioms:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;When an orchestra tunes up at the start of a rehearsal, they tune to
A. A is normally defined to be 440 Hz.&lt;/li&gt;
&lt;li&gt;Going up one octave is the same as doubling the frequency. That
is, one octave above tuning A is 880 Hz, and one octave below is
220 Hz.&lt;/li&gt;
&lt;li&gt;There are twelve semitones in an octave.&lt;/li&gt;
&lt;li&gt;All semitones are equally sized.&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;If going up an octave doubles the frequency, then going up twelve
semitones must also double the frequency. This means we must find the
number &lt;code&gt;semitone&lt;/code&gt;, where:&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;(nth (iterate #(* semitone %) 440) 12)
;=&amp;gt; 880&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;In other words, we want &lt;code&gt;semitone^12 == 2&lt;/code&gt;, so semitone must be the
twelfth root of 2:&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;; from the contrib library [org.clojure/math.numeric-tower "0.0.1"]
(require '([clojure.math.numeric-tower :as 'math]))
;=&amp;gt; nil
(def semitone (math/expt 2 1/12))
;=&amp;gt; #'user/semitone
(nth (iterate #(* semitone %) 440) 12)
;=&amp;gt; 880.0000000000003
; or alternatively:
(* (math/expt semitone 12) 440)
;=&amp;gt; 880.0000000000003&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;We can now define a function to find a frequency a given number of
semitones from tuning A:&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;(defn semitones-from-a [semis]
  (* (math/expt semitone semis) 440))
;=&amp;gt; #'user/semitones-from-a
(semitones-from-a 0)
;=&amp;gt; 440.0
(semitones-from-a 12)
;=&amp;gt; 880.0000000000003
(semitones-from-a 3)
;=&amp;gt; 523.2511306011974
(semitones-from-a -9)
;=&amp;gt; 261.6255653005985&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Normally, however, we use MIDI notes as a numerical representation of
notes, rather than displacement from tuning A. In the MIDI note
system, tuning A is defined to be 69, and going up or down one
semitone increases or decreases the note value by one. So, for
example, middle C is 60. We can get from midi notes to frequencies
like this:&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;(defn midi-to-hz [midi-note]
  (semitones-from-a (- midi-note 69)))
;=&amp;gt; #'user/midi-to-hz
(midi-to-hz 69)
;=&amp;gt; 440.0
(midi-to-hz 81)
;=&amp;gt; 880.0000000000003
(midi-to-hz 72)
;=&amp;gt; 523.2511306011974
(midi-to-hz 60)
;=&amp;gt; 261.6255653005985&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;In fact, Overtone provides a function &lt;code&gt;midi-&amp;gt;hz&lt;/code&gt; to do exactly this
transformation:&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;(midi-&amp;gt;hz 69)
;=&amp;gt; 440.0
(midi-&amp;gt;hz 81)
;=&amp;gt; 880.0
(midi-&amp;gt;hz 72)
;=&amp;gt; 523.2511306011972
(midi-&amp;gt;hz 60)
;=&amp;gt; 261.6255653005986&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;So with a melody as MIDI notes, we can play it as follows:&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;(play-freqs (map midi-&amp;gt;hz [60 62 64 62 60 72 67 60]))&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;hr /&gt;

&lt;p&gt;If you’ve got this far, the maths is over. The last mile is to be able
to use keywords instead of raw MIDI values. Overtone provides a
function for this called &lt;code&gt;note&lt;/code&gt;:&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;(note :a4)
;=&amp;gt; 69
(note :a5)
;=&amp;gt; 81
(note :c5)
;=&amp;gt; 72
(note :c4)
;=&amp;gt; 60&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;So we can play our tune by chaining this with &lt;code&gt;midi-&amp;gt;hz&lt;/code&gt;:&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;(play-freqs (map (comp midi-&amp;gt;hz note)
    [:c4 :c5 :e4 :f4 :g4 :f4 :e4 :d4 :c4 :c4]))
; *beautiful music*&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
	
&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://rhebus.posterous.com/pitch-and-frequency"&gt;Permalink&lt;/a&gt; 

	| &lt;a href="http://rhebus.posterous.com/pitch-and-frequency#comment"&gt;Leave a comment  »&lt;/a&gt;

&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=Ir5dJKdTqSw:kxeOE35331k:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=Ir5dJKdTqSw:kxeOE35331k:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/Ir5dJKdTqSw" height="1" width="1"/&gt;</content>
		<author>
			<name>Philip Potter</name>
			<uri>http://rhebus.posterous.com</uri>
		</author>
		<source>
			<title type="html">Philip Potter's Blog</title>
			<subtitle type="html">Most recent posts at Philip Potter's Blog</subtitle>
			<link rel="self" href="http://rhebus.posterous.com/rss.xml" />
			<id>http://rhebus.posterous.com</id>
		</source>
	<feedburner:origLink>http://rhebus.posterous.com/pitch-and-frequency</feedburner:origLink></entry>

	<entry>
		<title type="html">Navigate to Definition or F3 in Eclipse counterclockwise</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/IYxDMnJdceM/" />
		<id>http://blog.japila.pl/?p=1005</id>
		<updated>2012-05-25T22:44:46+00:00</updated>
		<content type="html">&lt;p&gt;I believe I lost many people’s attention during my live coding sessions with &lt;a href="http://clojure.org" rel="nofollow" target="_blank"&gt;Clojure&lt;/a&gt; and the Eclipse plugin for Clojure development – &lt;a href="http://code.google.com/p/counterclockwise/" rel="nofollow" target="_blank"&gt;counterclockwise&lt;/a&gt; as I used to not get the feature &lt;strong&gt;Navigate to Definition&lt;/strong&gt; or just hovering over a symbol with the Cmd key working in Eclipse.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blog.japila.pl/wp-content/uploads/2012/05/eclipse-clojure-navigate-to-definition.png" rel="nofollow" target="_blank"&gt;&lt;img alt="" class="aligncenter size-full wp-image-1006" height="234" src="http://blog.japila.pl/wp-content/uploads/2012/05/eclipse-clojure-navigate-to-definition.png" title="eclipse-clojure-navigate-to-definition" width="436" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I didn’t care much as Eclipse was an IDE that I didn’t spend much time with while developing applications in Clojure. It was Clojure’s REPL where I spent most of the time. On the other hand, I was asked to show the IDE support for Clojure and Eclipse was presented.&lt;/p&gt;
&lt;p&gt;Whenever I hovered over a symbol the error message &lt;strong&gt;“You need a running Clojure VM”&lt;/strong&gt; was shown.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blog.japila.pl/wp-content/uploads/2012/05/eclipse-clojure-you-need-a-running-clojure-vm.png" rel="nofollow" target="_blank"&gt;&lt;img alt="" class="aligncenter size-full wp-image-1007" height="30" src="http://blog.japila.pl/wp-content/uploads/2012/05/eclipse-clojure-you-need-a-running-clojure-vm.png" title="eclipse-clojure-you-need-a-running-clojure-vm" width="329" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I couldn’t fix it for  long time until today.&lt;/p&gt;
&lt;p&gt;Have all the dependencies of your Clojure project defined in Eclipse. I use &lt;a href="http://leiningen.org" rel="nofollow" target="_blank"&gt;leiningen 2&lt;/a&gt; which used to download the dependencies into &lt;strong&gt;lib&lt;/strong&gt; and &lt;strong&gt;lib/dev&lt;/strong&gt; directories (in the version 1), but it doesn’t anymore so I had to use the &lt;strong&gt;pom&lt;/strong&gt; task which &lt;em&gt;“Writes a pom.xml file to disk for Maven interoperability.”&lt;/em&gt; (from &lt;strong&gt;lein2 help pom&lt;/strong&gt;).&lt;/p&gt;
&lt;p&gt;Once &lt;strong&gt;pom.xml&lt;/strong&gt; is generated, import the project into Eclipse using &lt;strong&gt;Import &amp;gt; Maven &amp;gt; Existing Maven Projects&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blog.japila.pl/wp-content/uploads/2012/05/eclipse-clojure-import-existing-maven-project.png" rel="nofollow" target="_blank"&gt;&lt;img alt="" class="aligncenter size-full wp-image-1010" height="550" src="http://blog.japila.pl/wp-content/uploads/2012/05/eclipse-clojure-import-existing-maven-project.png" title="eclipse-clojure-import-existing-maven-project" width="525" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;After a while, when the compilation is done, from the context menu (under the right mouse button) of the project, select &lt;strong&gt;Run As &amp;gt; Clojure Application&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blog.japila.pl/wp-content/uploads/2012/05/eclipse-clojure-run-as-clojure-application.png" rel="nofollow" target="_blank"&gt;&lt;img alt="" class="aligncenter size-full wp-image-1014" height="312" src="http://blog.japila.pl/wp-content/uploads/2012/05/eclipse-clojure-run-as-clojure-application.png" title="eclipse-clojure-run-as-clojure-application" width="312" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If no problems are encountered, the nREPL view is displayed and symbols are easily resolvable with the feature “Navigate to Definition”. Alternatively, you can use the key &lt;strong&gt;F3&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blog.japila.pl/wp-content/uploads/2012/05/eclipse-clojure-nrepl-view.png" rel="nofollow" target="_blank"&gt;&lt;img alt="" class="aligncenter size-full wp-image-1011" height="193" src="http://blog.japila.pl/wp-content/uploads/2012/05/eclipse-clojure-nrepl-view.png" title="eclipse-clojure-nrepl-view" width="600" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Check it out and report how it works for you.&lt;/p&gt;
&lt;img height="1" src="http://feeds.feedburner.com/~r/blog-japila-pl/~4/XluwgE3-3rE" width="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=IYxDMnJdceM:jdrpCwY0hUo:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=IYxDMnJdceM:jdrpCwY0hUo:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/IYxDMnJdceM" height="1" width="1"/&gt;</content>
		<author>
			<name>Jacek Laskowski</name>
			<uri>http://pipes.yahoo.com/pipes/pipe.info?_id=1d37e15aab3f0c5d82f165e65aa0c034</uri>
		</author>
		<source>
			<title type="html">Jacek Laskowski</title>
			<subtitle type="html">Pipes Output</subtitle>
			<link rel="self" href="http://pipes.yahoo.com/pipes/pipe.run?_id=1d37e15aab3f0c5d82f165e65aa0c034&amp;_render=rss" />
			<id>http://pipes.yahoo.com/pipes/pipe.info?_id=1d37e15aab3f0c5d82f165e65aa0c034</id>
		</source>
	<feedburner:origLink>http://feedproxy.google.com/~r/blog-japila-pl/~3/XluwgE3-3rE/</feedburner:origLink></entry>

	<entry>
		<title type="html">On Lisp in Clojure chapter 11 (section 11.1)</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/pvwDoujpc0w/on-lisp-in-clojure-chapter-11-section.html" />
		<id>tag:blogger.com,1999:blog-5953796462512646386.post-7190706190748617946</id>
		<updated>2012-05-25T19:13:00+00:00</updated>
		<content type="html">&lt;p&gt;I am continuing to translate the examples from &lt;a href="http://www.bookshelf.jp/texi/onlisp/onlisp_toc.html#SEC_Contents" rel="nofollow" target="_blank"&gt;On Lisp&lt;/a&gt; by Paul Graham into Clojure.  The examples and links to the rest of the series can be found on &lt;a href="https://github.com/rickhall2000/OnLisp" rel="nofollow" target="_blank"&gt; github&lt;/a&gt;.  &lt;/p&gt; &lt;p&gt;Normally I would cover more than just 1 section in a post, but I thought material in this section could stand to be in its own discussion.  In addition, the next section has so much in it that it will need its own post.   &lt;/p&gt; &lt;p&gt;&lt;/p&gt;&lt;h3&gt;&lt;a href="http://www.bookshelf.jp/texi/onlisp/onlisp_12.html#SEC83" rel="nofollow" target="_blank"&gt;Section 11.1&lt;/a&gt; Creating Context&lt;/h3&gt;The call to let is included for completeness.  I thought the definition of our-let was pretty neat.  I think it shows pretty clearly what Graham means when he talks about using a macro to create a context.  &lt;p&gt;&lt;/p&gt; &lt;pre&gt;&lt;br /&gt;(let [x 'b] (list x))&lt;br /&gt;&lt;br /&gt;(defmacro our-let [binds &amp;amp; body]&lt;br /&gt;  `((fn [~@(take-nth 2 binds)]&lt;br /&gt;       (do ~@body)) ~@(take-nth 2 (rest binds))))&lt;br /&gt;&lt;br /&gt;(macroexpand-1 '(our-let [x 1 y 2] (+ x y)))&lt;br /&gt;;; ((clojure.core/fn [x y] (do (+ x y))) 1 2)&lt;br /&gt;&lt;br /&gt;(our-let [x 1 y 2] (+ x y))&lt;br /&gt;;; 3&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;It seems like we get to see the when macro every chapter.  It looked to me like the when-bind* was dropping all its variables, so clearly I don't understand it to translate it.  In Clojure, gensym is done by appending # to any variable that you name in a macro.   &lt;/p&gt; &lt;pre&gt;&lt;br /&gt;(defmacro when-bind [[var expr] &amp;amp; body]&lt;br /&gt;  `(let [~var ~expr]&lt;br /&gt;     (when ~var&lt;br /&gt;       ~@body)))&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Graham showed us a cond-let function that accepted a sequence of pairs containing a boolean expression followed by a let binding.  In Graham's implementation he had two helper functions and one macro.  I wrote it with one helper function that recursively walks through the boolean expressions until it finds one that is true.  &lt;/p&gt;&lt;pre&gt;&lt;br /&gt;(defn condlet-bind [bindings]&lt;br /&gt;  (loop [binds bindings]&lt;br /&gt;    (cond (empty? binds) []&lt;br /&gt;          (first binds) (first (rest binds))&lt;br /&gt;          :default (recur (rest (rest binds))))))&lt;br /&gt;&lt;br /&gt;(defmacro condlet [clauses &amp;amp; body]&lt;br /&gt;  `(let ~(condlet-bind clauses)&lt;br /&gt;     ~@body))&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;I want to point out the difference between this `condlet` function and Clojure.core's `if-let` function.  condlet takes a list containing booleans and bindings, and will apply the first binding for which the boolean is true.  if-let says if an expression is true, bind it to a symbol and execute one branch of code; if it is not true don't bind anything, and take a different branch. &lt;/p&gt;&lt;p&gt;In the following pseudo code, if some-expression returns a value other than false or nil, x gets bound to the result  and do-something is called.  If some-expression evaluates to false or nil, x does not get bound to anything and do-something-else gets called, just like a normal if. &lt;/p&gt; &lt;pre&gt;&lt;br /&gt;#_(if-let [x (some-expression)]&lt;br /&gt;  (do-something x)&lt;br /&gt;  (do-something-else))&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img alt="" height="1" src="https://blogger.googleusercontent.com/tracker/5953796462512646386-7190706190748617946?l=onbeyondlambda.blogspot.com" width="1" /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=pvwDoujpc0w:F9q_mzQNLR4:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=pvwDoujpc0w:F9q_mzQNLR4:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/pvwDoujpc0w" height="1" width="1"/&gt;</content>
		<author>
			<name>Rick</name>
			<uri>http://pipes.yahoo.com/pipes/pipe.info?_id=ec6f43fcafdaa65dbd76221d1fe07e27</uri>
		</author>
		<source>
			<title type="html">On Beyond Lambda</title>
			<subtitle type="html">Pipes Output</subtitle>
			<link rel="self" href="http://pipes.yahoo.com/pipes/pipe.run?_id=ec6f43fcafdaa65dbd76221d1fe07e27&amp;_render=rss" />
			<id>http://pipes.yahoo.com/pipes/pipe.info?_id=ec6f43fcafdaa65dbd76221d1fe07e27</id>
		</source>
	<feedburner:origLink>http://onbeyondlambda.blogspot.com/2012/05/on-lisp-in-clojure-chapter-11-section.html</feedburner:origLink></entry>

	<entry>
		<title type="html" xml:lang="en">EuroClojure 2012 Day 1</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/np2ygdGPSFc/" />
		<id>http://rrees.wordpress.com/?p=819</id>
		<updated>2012-05-25T07:03:38+00:00</updated>
		<content type="html" xml:lang="en">&lt;p&gt;So there were definitely two big themes in the talks on the first day of the conference.&lt;/p&gt;
&lt;p&gt;The first has been about how to use event-based systems to create flexible aggregate data models. All speakers seem to have settled on a reduce or foldLeft approach for creating the aggregate but there have been two models put forward already CQRS and a kind of Aggregate query bus but really it seems that responsibility for accepting event data and allow querying and access to aggregated views seem to be responsibilities in the same system.&lt;/p&gt;
&lt;p&gt;The other thing has been creating query systems using logical predicates. The were no less than three generic query systems put forward: core.logic for low-level flexible implementations that identify either data or results and two general query libraries: one from Datomic and the other from Cascalog.&lt;/p&gt;
&lt;br /&gt;  &lt;a href="http://feeds.wordpress.com/1.0/gocomments/rrees.wordpress.com/819/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rrees.wordpress.com/819/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/godelicious/rrees.wordpress.com/819/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rrees.wordpress.com/819/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/gofacebook/rrees.wordpress.com/819/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rrees.wordpress.com/819/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/gotwitter/rrees.wordpress.com/819/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rrees.wordpress.com/819/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/gostumble/rrees.wordpress.com/819/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rrees.wordpress.com/819/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/godigg/rrees.wordpress.com/819/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rrees.wordpress.com/819/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/goreddit/rrees.wordpress.com/819/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rrees.wordpress.com/819/" /&gt;&lt;/a&gt; &lt;img alt="" border="0" height="1" src="http://stats.wordpress.com/b.gif?host=rrees.wordpress.com&amp;amp;blog=181521&amp;amp;post=819&amp;amp;subd=rrees&amp;amp;ref=&amp;amp;feed=1" width="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=np2ygdGPSFc:_-KVSMP4xGg:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=np2ygdGPSFc:_-KVSMP4xGg:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/np2ygdGPSFc" height="1" width="1"/&gt;</content>
		<author>
			<name>rrees</name>
			<uri>http://rrees.wordpress.com</uri>
		</author>
		<source>
			<title type="html">Echo One » clojure</title>
			<subtitle type="html">Sequentially arranged sentences composed of words (and punctuation)</subtitle>
			<link rel="self" href="http://rrees.wordpress.com/tag/clojure/feed/" />
			<id>http://rrees.wordpress.com</id>
		</source>
	<feedburner:origLink>http://rrees.wordpress.com/2012/05/25/euroclojure-2012-day-1/</feedburner:origLink></entry>

	<entry>
		<title type="html">understanding clojure concurrency, part 2</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/fNYsq8bueVA/understanding-clojure-concurrency-part-2.html" />
		<id>http://blakesmith.me/2012/05/25/understanding-clojure-concurrency-part-2</id>
		<updated>2012-05-25T05:00:00+00:00</updated>
		<content type="html">&lt;p&gt;&lt;em&gt;This is part 2 of a 2 part series I’m writing about Clojure concurrency. Check out the first post &lt;a rel="nofollow"&gt;here&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h3 id="concurrency_primitives"&gt;concurrency primitives&lt;/h3&gt;

&lt;p&gt;Clojure provides a grab-bag of concurrency primitives and functions that give meaning and control to your multi-threaded code. Most programming languages leave these constructs up to the library writers - Clojure takes a different stance.&lt;/p&gt;

&lt;h3 id="atoms"&gt;atoms&lt;/h3&gt;

&lt;p&gt;First, I’d like to talk about atoms. The concept of atomicity might not be new to you, but let’s recap just to solidify the idea. Atomicity implies that even in an environment with multiple actors (threads) working on the same piece of data, you can guarantee that updates to that data either happen entirely, or don’t happen at all. In practice, this is used when multiple threads are reading and writing to one data structure to share its contents. Here’s how you create an atom in Clojure:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;user=&amp;gt; (atom 1)
#&amp;lt;Atom@15c313da: 1&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This will create an atom that houses the Java Integer 1 inside of it. To fetch the value of the atom, you use the deref function.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;user=&amp;gt; (def a (atom 1))
#'user/a
user=&amp;gt; a
#&amp;lt;Atom@3f78e13f: 1&amp;gt;
user=&amp;gt; (deref a)
1
user=&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You can also deref an atom using the ’@’ shortcut:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;user=&amp;gt; (def a (atom 1))
#'user/a
user=&amp;gt; @a
1
user=&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To change the value of a atom, you use the swap! function.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;user=&amp;gt; a
#&amp;lt;Atom@30394ffa: 1&amp;gt;
user=&amp;gt; (swap! a inc)
2
user=&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The swap! function takes the atom as its first argument, and a function to apply to the value in the atom. In this case, we applied the ‘inc’ function, which increments the integer by 1.&lt;/p&gt;

&lt;p&gt;Under the covers, the swap! function is doing a compare-and-set! operation, which means that if two threads are in a race to apply their function to the atom, the loser will retry their swap if the value has changed since they began the swap. Therefore, it’s very important that ‘swap!’ procedures be completely free of side-effects. No log writing, database updating or anything else - otherwise you’ll get unpredictable behavior in your I/O layers.&lt;/p&gt;

&lt;p&gt;Atoms also allow you to specify a :validator function. This function will be executed whenever the atom is attempting to change state:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;user=&amp;gt; (def a (atom 1 :validator #(&amp;lt; % 10)))
#'user/a
user=&amp;gt; a
#&amp;lt;Atom@476dc5c9: 1&amp;gt;
user=&amp;gt; (swap! a (partial + 8))
9
user=&amp;gt; a
#&amp;lt;Atom@476dc5c9: 9&amp;gt;
user=&amp;gt; (swap! a inc)
java.lang.IllegalStateException: Invalid reference state (NO_SOURCE_FILE:0)
user=&amp;gt; &lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In the example, we created an Integer that cannot be greater than 10. The first time we apply a swap function, the atom successfuly changes. When we try to increment the atom one more time up to 10, an IllegalStateException is thrown. This is really useful in cases where retrying a swap operation might put the atom in an illegal state, especially during thread races.&lt;/p&gt;

&lt;p&gt;What I love about atoms is how simple they are. You take an immutable persistent data type and you can make it atomic, without having to remake your entire processing pipeline or the underlying data structure. You get a tool that helps create data that is shared, synchronous, and independent in state. How do you know when it’s the right decision to use an atom? The general rule of thumb is that if you only have to manipulate one data item concurrently and synchronously, you should use an atom. A good example of this might be a counter that counts how many items have been sold in an online store - there might be multiple webserver trying to increment and decrement this number at once, but the count will always be guaranteed to be in a single state at any given moment in time.&lt;/p&gt;

&lt;p&gt;When you start needing to coordinate a group of data items that need to mutate together, you should start to think about Refs.&lt;/p&gt;

&lt;h3 id="refs"&gt;refs&lt;/h3&gt;

&lt;p&gt;Because Clojure has immutable data structures, Refs provide a mechanism to track the same fact idea (identity) over a period of time. Let’s look at an example of this.&lt;/p&gt;

&lt;p&gt;Here are some facts I know to be true:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;On July 22, 2011 - Bob Anderson lived in Chicago.&lt;/li&gt;

&lt;li&gt;On September 14, 2011 - Bob Anderson lived in San Francisco&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In most programming languages, you might have a variable called ‘userLocation’ that you would update when Bob moves from Chicago to San Francisco. As far as your program is concerned, when you update the ‘userLocation’ variable, your program loses awareness that Bob ever lived in Chicago. Once you rewrite that variable, Bob’s previous location is lost forever. Now just because you updated the ‘userLocation’ to San Francisco doesn’t change the fact that at an earlier point in time, Bob lived in Chicago. What’s worse, is that any other thread that was holding on to the ‘userLocation’ variable would have its value change out from under it. This is where the nasty dragons live.&lt;/p&gt;

&lt;p&gt;What a Clojure Ref does is track a series of facts over time. So in the Clojure world, conceptually, a Ref looks like this:&lt;/p&gt;

&lt;p&gt;Question: “Where does Bob live at this point in time?”&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;On July 22, 2011 - Bob Anderson lived in Chicago.&lt;/li&gt;

&lt;li&gt;On September 14, 2011 - Bob Anderson lived in San Francisco&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So in Clojure, you would have a Ref called user-location, and if Bob moves to a new location, you update the Ref to point to the newest fact (Bob living in San Francisco). Again, what a Ref does is tracks values over time. Before Bob moved, the Ref pointed to the fact that Bob lived in Chicago. When Bob moves, on September 14, 2011, the Ref points to the fact that Bob now lives in San Francisco. Anyone holding on to the previous value of ‘Chicago’ would still retain that value until it updated its state from the Ref.&lt;/p&gt;

&lt;p&gt;But that’s not the main use case for Refs.&lt;/p&gt;

&lt;p&gt;If atoms are for managing the fact changes of a single data structure, then Refs are for managing changes of multiple data structures together, atomically. Put simply, Refs give you in memory transactions using a software transactional memory system. I’m not going to get into the details of software transactional memory systems, but if you’re curious I’d recommend doing some reading on them. Let’s take our example with Bob and elaborate on it more.&lt;/p&gt;

&lt;p&gt;Bob’s company stores 2 facts about him, where he lives and how much his salary is. Both of these pieces of data always move together in a coordinated fashion to adjust for cost of living. When Bob moves from Chicago to San Francisco, his salary also needs to increase at the exact same time. Because these two facts are bound together, they either both change, or neither of them change. Let’s setup our two Refs and get started:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def &lt;/span&gt;&lt;span class="nv"&gt;location&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;ref &lt;/span&gt;&lt;span class="s"&gt;"Chicago"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def &lt;/span&gt;&lt;span class="nv"&gt;salary&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;ref &lt;/span&gt;&lt;span class="mi"&gt;30000&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;You access Ref values the same way you access atom values, using the deref function (or the @ prefix):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;user=&amp;gt; @location
"Chicago"
user=&amp;gt; @salary
30000&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;We come to September 14, 2011 - time for Bob to move and get a salary bump at the exact same time. For this to happen as one atomic change, we need a transaction. Note that it is impossible for you to change the value of a Ref without a transaction. Clojure provides the ‘dosync’ macro that wraps an expression in a transaction for Ref changes.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;dosync&lt;/span&gt;
	  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;ref-set &lt;/span&gt;&lt;span class="nv"&gt;location&lt;/span&gt; &lt;span class="s"&gt;"San Francisco"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
	  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;alter &lt;/span&gt;&lt;span class="nv"&gt;salary&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;partial &lt;/span&gt;&lt;span class="nv"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;15000&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The first Ref we altered by simply changing its value to a completely new value. Again, Bob’s location used to be Chicago, but now it’s San Francisco. We achieved this change using the ‘ref-set’ function, which allows you to alter the value of a Ref outright. At the same time Bob moves to San Francisco, he gets a $15,000 pay increase. We represent this pay increase by applying the ‘alter’ operation to the salary Ref. Similar to the ‘swap!’ operation of the Atom, the alter command takes the Ref and a function to apply to the current Ref value - in our case we’re applying a plus operation to his salary. As far as other threads are concerned, both of these changes will happen at the same point in time. After we alter the values, we get the new expected values by derefing:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;user=&amp;gt; @location
"San Francisco"
user=&amp;gt; @salary
45000&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Refs give you the amazing power to coordinate several data structures, forcing their changes to occur together as one atomic group. Similar to atoms, if two threads attempt to change the value of a Ref at the same time, one of them will succeed and the other will fail. When the second one fails, it will be automatically retried. So, just like with Atoms, Ref transactions must be completely free of side effects.&lt;/p&gt;

&lt;p&gt;Keep in mind that the more data structures you group together into a transaction, the more transaction retries you will experience under heavy write load, and the more your performance will degrade. The less your data structures have to coordinate, the better. Think about it like trying to schedule a meeting with someone else. It’s not too hard to have the two of you find a common time to meet, but what happens when you have to schedule a meeting with ten busy people? It becomes much harder to get everyone in the same room at the same time. People often end up not showing up or the meeting gets moved or cancelled due to last minute scheduling conflicts. The same goes for manipulating many data structures in a single transaction. Remember this concept when doing coordinated Ref manipulation: the faster the transactions, and the less the participants, the better. Less coordination helps computers scale horizontally and go faster by doing more at once.&lt;/p&gt;

&lt;h3 id="futures"&gt;futures&lt;/h3&gt;

&lt;p&gt;Futures are one of my favorite Clojure concurrency primitives. They offer a simple and flexible way to dispatch operations into another thread and then retrieve the results of that computation from the existing thread. Put more simply, they’re terrific at producing a request/response operation that occurs between two threads.&lt;/p&gt;

&lt;p&gt;To start off, let’s start playing around a bit:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;future&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;Thread/sleep&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;prn &lt;/span&gt;&lt;span class="s"&gt;"Hello futures!"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;When you execute this in your REPL, you’ll notice that it returns immediately, and 1 second later a print message sent to standard out. This use of futures doesn’t give us much over newing up a Thread and telling it to print to the screen. Futures give us the ability deref and retrieve the value the Thread returns in the exact same way we deref Atoms and Refs. Let’s do that now using a simple factorial function:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn &lt;/span&gt;&lt;span class="nv"&gt;factorial&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;n&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
	  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;apply &lt;/span&gt;&lt;span class="nv"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;map &lt;/span&gt;&lt;span class="nv"&gt;bigint&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;range &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;inc &lt;/span&gt;&lt;span class="nv"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)))))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;If we want to find the factorial of a very large number, we can perform this computation in another thread and then retrieve the computed value using our handy friend deref:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def &lt;/span&gt;&lt;span class="nv"&gt;result&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;future&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;factorial&lt;/span&gt; &lt;span class="mi"&gt;10000&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
	&lt;span class="o"&gt;...&lt;/span&gt; &lt;span class="nv"&gt;do&lt;/span&gt; &lt;span class="nv"&gt;some&lt;/span&gt; &lt;span class="nv"&gt;other&lt;/span&gt; &lt;span class="nv"&gt;things&lt;/span&gt; &lt;span class="nv"&gt;here&lt;/span&gt; &lt;span class="o"&gt;...&lt;/span&gt;
	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;deref &lt;/span&gt;&lt;span class="nv"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Following the same pattern, deref will return the result immediately if the future has already completed, otherwise it will block until the future is done. In this case, we dispatched a really expensive action to another thread, so our main thread could continue execution. Then, when our main thread is ready to consume the result of the future, it simply derefs it like we’ve seen before. I like to think of this like a request/response pattern that spans multiple threads instead of two servers. You can offload the heavy lifting to something else, and keep on doing what you’re doing.&lt;/p&gt;

&lt;p&gt;Now let’s step it up another notch and do something non-trivial. A user on my website uploads a photo album, and I want to back all of the images up to Amazon S3. I could iterate through each photo and upload them one at a time, but that would be slow and would waste a lot of CPU cycles simply waiting for a response from Amazon. Why don’t we instead use a collection of futures to fan out the images simultaneously? Let me show you how this is done.&lt;/p&gt;

&lt;p&gt;First, let’s assume the user has just submitted all the files to the server, and they’re sitting in memory as a collection of java BufferedImages. To simulate this, I’m just going to read the same image 10 times:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;import &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;javax&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;imageio&lt;/span&gt; &lt;span class="nv"&gt;ImageIO&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
	
	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def &lt;/span&gt;&lt;span class="nv"&gt;images&lt;/span&gt;
	  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;take &lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;
	        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;repeatedly&lt;/span&gt;
	         &lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;ImageIO/read&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;clojure&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;java&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;io/input-stream&lt;/span&gt;
				 &lt;span class="s"&gt;"/Users/blake/Pictures/blake_signature.jpg"&lt;/span&gt;&lt;span class="p"&gt;)))))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Utilizing the ‘repeatedly’ function to generate an infinite sequence of BufferedImages, we only realized 10 of them using the ‘take’ function. We have a collection of BufferedImages, now let’s upload all 10 of them concurrently to S3. To do this, I’m going to use the ‘clj-aws-s3’ library. First, let’s write our function that will upload the image to S3 itself:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;require&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;aws&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;sdk&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;s3&lt;/span&gt; &lt;span class="nv"&gt;:as&lt;/span&gt; &lt;span class="nv"&gt;s3&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
	
	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def &lt;/span&gt;&lt;span class="nv"&gt;credentials&lt;/span&gt;
	  &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;:access-key&lt;/span&gt; &lt;span class="s"&gt;"my s3 access key"&lt;/span&gt;
	   &lt;span class="nv"&gt;:secret-key&lt;/span&gt; &lt;span class="s"&gt;"super secret key"&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
	   
	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def &lt;/span&gt;&lt;span class="nv"&gt;bucket-name&lt;/span&gt; &lt;span class="s"&gt;"user-images"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   
	
	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn &lt;/span&gt;&lt;span class="nv"&gt;save-image&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;image&lt;/span&gt; &lt;span class="nv"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
	  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;with-open &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;os&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;ByteArrayOutputStream&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
	    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;ImageIO/write&lt;/span&gt; &lt;span class="nv"&gt;image&lt;/span&gt; &lt;span class="s"&gt;"jpg"&lt;/span&gt; &lt;span class="nv"&gt;os&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
	    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;request&lt;/span&gt;
	          &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;s3/put-object&lt;/span&gt; &lt;span class="nv"&gt;credentials&lt;/span&gt; &lt;span class="nv"&gt;bucket-name&lt;/span&gt; &lt;span class="nv"&gt;filename&lt;/span&gt;
	                         &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;clojure&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;java&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;io/input-stream&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;toByteArray&lt;/span&gt; &lt;span class="nv"&gt;os&lt;/span&gt;&lt;span class="p"&gt;)))]&lt;/span&gt;
	      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;:finished&lt;/span&gt; &lt;span class="nv"&gt;true&lt;/span&gt; &lt;span class="nv"&gt;:request&lt;/span&gt; &lt;span class="nv"&gt;request&lt;/span&gt;&lt;span class="p"&gt;})))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;That looks like a lot, but it’s not so bad. First we set up some of our boilerplate code. We import the s3 library and then define our S3 credentials using a hash map and set our S3 bucket name. Our ‘upload-image’ function takes a BufferedImage as input, and a desired filename for the image in our S3 bucket. From there, we open a new ByteArrayOutputStream. This is where we’re going to write the raw bytes from our image to in preparation for uploading them. After that, we build a request and invoke the ‘s3/put-object’ with our credentials, filename and an InputStream from our ByteArrayOutputStream. We basically wrote out the bytes into memory and then read them out again to upload to S3. That returns a s3 request object which we inspect to write out to our hash map along with an easy to access :finished key which all gets returned from the function. Conceptually, all this function is really doing is reading the raw bytes out of the BufferedImage and then shuttling them off to S3.&lt;/p&gt;

&lt;p&gt;Now, let’s write one more function that’s takes our entire BufferedImage collection as input and utilizes futures to fan multiple threads out to S3 all simultaneously:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn &lt;/span&gt;&lt;span class="nv"&gt;upload-images&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;images&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
	  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;doall&lt;/span&gt;
	    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;map-indexed&lt;/span&gt;
	     &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;fn &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;image&lt;/span&gt; &lt;span class="nv"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
	       &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;future&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;upload-image&lt;/span&gt; &lt;span class="nv"&gt;image&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt; &lt;span class="s"&gt;"myimage-%s.jpg"&lt;/span&gt; &lt;span class="nv"&gt;i&lt;/span&gt;&lt;span class="p"&gt;))))&lt;/span&gt;
	     &lt;span class="nv"&gt;images&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We’re mapping over our collection of images, and for each image we’re generating a future thats body content will upload the image to S3. When we invoke this function, we’ll get back a collection of futures, each one representing one image that’ll get uploaded by one of the threads in the thread pool. Keep in mind that once the thread pool is exhausted, other futures will have to wait for a thread to become available again.&lt;/p&gt;

&lt;p&gt;Let’s try out our parallel uploading:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def &lt;/span&gt;&lt;span class="nv"&gt;f&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;upload-images&lt;/span&gt; &lt;span class="nv"&gt;images&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;map &lt;/span&gt;&lt;span class="nv"&gt;deref&lt;/span&gt; &lt;span class="nv"&gt;f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;When every single image upload completes, you’ll get back a collection of hashes like the one we defined in ‘save-image’.&lt;/p&gt;

&lt;p&gt;Like I mentioned earlier, futures are one of my favorite concurrency primitives, because they allow you to dish out heavy or long running tasks to a thread pool with ease, letting your main execution path continue on its marry way, and not get bogged down by long running requests.&lt;/p&gt;

&lt;h3 id="agents"&gt;agents&lt;/h3&gt;

&lt;p&gt;Let’s say you have a problem that almost warrants the use of an Atom, but you need your functionality to be &lt;em&gt;asynchronous&lt;/em&gt; instead of &lt;em&gt;synchronous&lt;/em&gt;. On top of that, you know that it’s a bad idea to use Atoms when your functions have side-effects, because they might get invoked several times when threads are competing, but your functions are going to do some I/O. What can you do? You should consider using Agents.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: the following example was borrowed from &lt;a href="http://lethain.com/a-couple-of-clojure-agent-examples/" rel="nofollow" target="_blank"&gt;Will Larson&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;One great use case for Agents is for shared logging. We’re writing our program, and we have several threads that need to log to the same shared BufferedWriter file. We know that BufferedWriter is not a thread safe data structure, and ignoring this fact will lead to strange interleaving in our log files due to thread contention. We also know that our logging use case is something that can happen asynchronously from our main app logic - logging really shouldn’t be stopping the main flow of your program execution. Agents will help us solve this problem quite easily.&lt;/p&gt;

&lt;p&gt;First, we wrap the BuffedWriter in an agent, similar to how we wrap Atoms and Refs.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;import &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;java&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;io&lt;/span&gt; &lt;span class="nv"&gt;BufferedWriter&lt;/span&gt; &lt;span class="nv"&gt;FileWriter&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
	
	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def &lt;/span&gt;&lt;span class="nv"&gt;logfile&lt;/span&gt;
	  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;agent &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;BufferedWriter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;FileWriter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt; &lt;span class="s"&gt;"shared-logfile.log"&lt;/span&gt;&lt;span class="p"&gt;))))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now let’s go ahead and write our log function that’s going to handle writing out to the BufferedWriter.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn &lt;/span&gt;&lt;span class="nv"&gt;write-out&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;out&lt;/span&gt; &lt;span class="nv"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
	  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;write&lt;/span&gt; &lt;span class="nv"&gt;out&lt;/span&gt; &lt;span class="nv"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
	  &lt;span class="nv"&gt;out&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This function writes to the BufferedWriter, and then returns the instance of the BufferedWriter. We’ll see why it’s important to return the BufferedWriter instance in a moment.&lt;/p&gt;

&lt;p&gt;Now, we need a way to dispatch our write-out function to the agent. To do this, we use the built-in ‘send’ function.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn &lt;/span&gt;&lt;span class="nv"&gt;log&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;logger&lt;/span&gt; &lt;span class="nv"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
	  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;send &lt;/span&gt;&lt;span class="nv"&gt;logger&lt;/span&gt; &lt;span class="nv"&gt;write-out&lt;/span&gt; &lt;span class="nv"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
	  
	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn &lt;/span&gt;&lt;span class="nv"&gt;close&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
	  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;send &lt;/span&gt;&lt;span class="nv"&gt;logger&lt;/span&gt; &lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;close&lt;/span&gt; &lt;span class="nv"&gt;%&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The first parameter to ‘send’ is the agent itself, followed by the function to apply to the agent, and any additional arguments to pass into the function. In our case, we’re applying the write-out function to the logger agent and passing the message along to the write-out function. Then we can send log events to the logger using the ‘log’ function:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt; &lt;span class="nv"&gt;logfile&lt;/span&gt; &lt;span class="s"&gt;"My awesome message"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt; &lt;span class="nv"&gt;logfile&lt;/span&gt; &lt;span class="s"&gt;"My other awesome message"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt; &lt;span class="nv"&gt;logfile&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And both of those log lines would be present in our log file. This is all fine and well, but it doesn’t really demonstrate the reason we used agents in the first place. We chose agents because we wanted to be able to have multiple threads writing to the same log file without any interleave or contention issues. Let’s throw a bunch of threads at our logger, and have them all write out to the log file:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;dotimes &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;i&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
	  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;future&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt; &lt;span class="nv"&gt;logfile&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt; &lt;span class="s"&gt;"Message number %s\n"&lt;/span&gt; &lt;span class="nv"&gt;i&lt;/span&gt;&lt;span class="p"&gt;))))&lt;/span&gt;
	  
	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt; &lt;span class="nv"&gt;logfile&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This will utilize a thread pool to write all those log events to the file. When I open up my logfile to see the results, I get something tha looks like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Message number 1
Message number 3
Message number 5
Message number 9
Message number 11
Message number 22
Message number 23
Message number 24
Message number 25
...&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You’ll notice that the log numbers are not in order - because multiple threads were trying to write to the file at the same time, so ordering is not guaranteed or expected. The good news is, none of our log lines are interleaved. This is due to our functions being applied to the agent in a serial fashion. Think of agents like a queue for the functions you want to apply to some piece of state. Even though multiple threads are trying to apply their function to the agent at the same time, all the function calls get ordered and applied one after the other.&lt;/p&gt;

&lt;p&gt;There are two ways you can dispatch a function to an agent. You can use the ‘send’ function like we did in the example, or you can use the ‘send-off’ function. On the surface, these two functions appear to do the same thing, with a subtle difference. Under the covers, ‘send’ uses a thread pool that has a fixed size, depending on the number of cores your CPU has. This means that if one of the threads from the thread pool blocks for a long period of time, you risk starving your agent from available threads. If all the threads in the thread pool block for a long period of time, you’ll get a backup of ‘sends’.&lt;/p&gt;

&lt;p&gt;On the other hand, using ‘send-off’ will utilize a separate thread pool that is capable of growing in size. This means that if your threads block for any lengthy period of time, more threads can be created to accomodate the increasing demands (up to a certain point).&lt;/p&gt;

&lt;p&gt;What does this mean for you as the programmer? The general rule of thumb is if you’re making long I/O calls, like going out to the network for something, use ‘send-off’. If your operations are generally CPU bound, or risk no chance of blocking for a long time, use ‘send’.&lt;/p&gt;

&lt;h3 id="promises"&gt;promises&lt;/h3&gt;

&lt;p&gt;In a basic sense, a promise is a contract between one thread and another to deliver a calculation at some point in the future. Put another way, a promise is a mechanism to safetly deliver data between two threads. Let’s walk through a circumstance where using a promise might ease the ability to share data in between concurrent processes.&lt;/p&gt;

&lt;p&gt;Imagine you’re planning a party. The restaurant party manager calls you three weeks before the event to get the guest count. You don’t yet know how many people are going to come to your party, but you expect you’ll have the final head count soon. You tell the party manager that you’re still working on getting final head count and that you’ll call him and let him know as soon as you’ve got the number nailed down. You work on getting the last RSVPs gathered, and three days later you call back the restaurant owner and give him the final count.&lt;/p&gt;

&lt;p&gt;In this example, you don’t know what the exact guest count is, but you know it’s a number you’re going to have to give the party manager in the future - so you make him a &lt;em&gt;promise&lt;/em&gt; that you’ll tell him the final count as soon as you know it. Then you go about calling your invited guests to sum the total count. Once you know number, you &lt;em&gt;deliver&lt;/em&gt; on that promise by calling the manager back and telling him what it is.&lt;/p&gt;

&lt;p&gt;This interaction represents how you might use Clojure promises. The typical pattern goes like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A thread generates a promise by invoking the ‘promise’ function with no arguments.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;def &lt;/span&gt;&lt;span class="nv"&gt;guest-count&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;promise&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;That thread passes the promise along to another thread. This states the intetion “I am going to deliver the guest count to you at some point in the future when I know it”. That other thread is free to do other things while waiting on the value contained in the promise, and check to see if the other thread delivered the value periodically.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;future&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;manager-duties&lt;/span&gt; &lt;span class="nv"&gt;guest-count&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;In this case, we use a future to perform all the manager duties in another thread. The manager duties might be described like this:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn &lt;/span&gt;&lt;span class="nv"&gt;talk-to-guests&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
	  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;prn &lt;/span&gt;&lt;span class="s"&gt;"Talking to guests"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
	
	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn &lt;/span&gt;&lt;span class="nv"&gt;train-wait-staff&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
	  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;prn &lt;/span&gt;&lt;span class="s"&gt;"Training wait staff"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
	
	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn &lt;/span&gt;&lt;span class="nv"&gt;check-party-guest-count&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;p&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
	  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;realized?&lt;/span&gt; &lt;span class="nv"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
	    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;deref &lt;/span&gt;&lt;span class="nv"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
	    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;prn &lt;/span&gt;&lt;span class="s"&gt;"Don't know the guest count yet, call later"&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
	
	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn &lt;/span&gt;&lt;span class="nv"&gt;manager-duties&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;cnt&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
	  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;talk-to-guests&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
	  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;train-wait-staff&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
	  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;if-let &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;count&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;check-party-guest-count&lt;/span&gt; &lt;span class="nv"&gt;cnt&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
	    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;prn &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt; &lt;span class="s"&gt;"Total guest count is %s"&lt;/span&gt; &lt;span class="nv"&gt;count&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
	    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;do&lt;/span&gt;
	      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;Thread/sleep&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
	      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;manager-duties&lt;/span&gt; &lt;span class="nv"&gt;cnt&lt;/span&gt;&lt;span class="p"&gt;))))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We set up a few tasks for the party manager to perform, and he performs them continually. Notice the use of the ‘realized?’ function in the ‘check-party-guest-count’ function. This function can be used on promises to check if the promise has been delived yet. You may need to do this in some circumstances if you don’t want to invoke ‘deref’ and block until the promise is delivered.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The guest count is delivered from the main thread, thus completing the promise. The manager stops performing his tasks.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="clojure"&gt;	&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;deliver&lt;/span&gt; &lt;span class="nv"&gt;guest-count&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;When I first encountered promises, I was confused about how they differ from futures. When do I use one and when would I use the other? Let me explain the difference. With futures, your main thread of execution is delegating work to another thread. When the value of the future comes back, the main thread gets to harvest this value and benefit from it. With promises, this relationship is usually inverted. The main thread of execution generates a promise, and passes it off to another thread. The main thread of execution does the hard work to generate the value that will be delivered, and delivers it to the second thread. The second thread gets to benefit from the hard work of the main thread.&lt;/p&gt;

&lt;p&gt;One handy rule of thumb for determining whether to use a future or a promise is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;I want another thread to do my work for me and tell me the result: use a future.&lt;/li&gt;

&lt;li&gt;I want to do the work and tell the other thread when I’m done: use a promise.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id="the_world_ahead"&gt;the world ahead&lt;/h3&gt;

&lt;p&gt;I hope you’ll come away from this feeling more empowered to write concurrent Clojure programs. Part of the challenge of learning this stuff is figuring out the new patterns and different ways of thinking that are required to write concurrent code. Concurrent and parallel programming is a very big topic, and this series of posts serves as a way to get excited about the potential of multi-threaded programming with Clojure. In a lot of ways, our computer systems have run out of affordable vertical scaling runway - the future holds the growing need to make our computer systems grow horizontally, and thus places more demands on the programmer to write concurrent code. I believe that mastering this stuff can open up doors to all kinds of problems you didn’t even think solvable. Jump in, and have fun!&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=fNYsq8bueVA:bz0Ziyb9n_8:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=fNYsq8bueVA:bz0Ziyb9n_8:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/fNYsq8bueVA" height="1" width="1"/&gt;</content>
		<author>
			<name>Blake Smith</name>
			<uri>http://pipes.yahoo.com/pipes/pipe.info?_id=7b8be19b36639ba4bee6013c90ce65f8</uri>
		</author>
		<source>
			<title type="html">Blake Smith</title>
			<subtitle type="html">Pipes Output</subtitle>
			<link rel="self" href="http://pipes.yahoo.com/pipes/pipe.run?_id=7b8be19b36639ba4bee6013c90ce65f8&amp;_render=rss" />
			<id>http://pipes.yahoo.com/pipes/pipe.info?_id=7b8be19b36639ba4bee6013c90ce65f8</id>
		</source>
	<feedburner:origLink>http://blakesmith.me/2012/05/25/understanding-clojure-concurrency-part-2.html</feedburner:origLink></entry>

	<entry>
		<title type="html">Clojure: expectations, colorized</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/joS-o4o84ug/clojure-expectations-colorized.html" />
		<id>tag:blogger.com,1999:blog-12467669.post-6237898775794439423</id>
		<updated>2012-05-24T13:00:05+00:00</updated>
		<content type="html">The current version of expectations (1.4.3) prints colorized results by default on non-windows boxes. &lt;br /&gt;&lt;br /&gt;The following screenshot is an example of the output when no tests are failing: &lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both;"&gt;&lt;a href="http://3.bp.blogspot.com/-zlr9XXR-uLQ/T6_gdCp5R2I/AAAAAAAAAFw/yHY4UzHsl9I/s1600/Screen%2Bshot%2B2012-05-13%2Bat%2B12.24.38%2BPM.png"&gt;&lt;img border="0" height="122" src="http://3.bp.blogspot.com/-zlr9XXR-uLQ/T6_gdCp5R2I/AAAAAAAAAFw/yHY4UzHsl9I/s400/Screen%2Bshot%2B2012-05-13%2Bat%2B12.24.38%2BPM.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;And, the following screenshot is an example of the output when there are failures or errors: &lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both;"&gt;&lt;a href="http://1.bp.blogspot.com/-nJLOoI3ovps/T6_hHaL6FmI/AAAAAAAAAF8/kTH_w4sVvpQ/s1600/Screen%2Bshot%2B2012-05-13%2Bat%2B12.27.03%2BPM.png"&gt;&lt;img border="0" height="196" src="http://1.bp.blogspot.com/-nJLOoI3ovps/T6_hHaL6FmI/AAAAAAAAAF8/kTH_w4sVvpQ/s400/Screen%2Bshot%2B2012-05-13%2Bat%2B12.27.03%2BPM.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Colorized output is one of those small things that is easy to de-prioritize, but once it's done you can't figure out why you didn't do it earlier. The code to colorize your results is very simple, and there's even a lib, &lt;a href="https://github.com/ibdknox/colorize"&gt;colorize&lt;/a&gt;, if you prefer to simply include a dependency instead. &lt;br /&gt;&lt;br /&gt;Of course, if you prefer to stick with non-colorized results that's possible as well - simply set the environment variable EXPECTATIONS_COLORIZE to 'false'.&lt;div class="blogger-post-footer"&gt;&lt;br /&gt;&lt;a href="http://www.jayfields.com"&gt;© Jay Fields - www.jayfields.com&lt;/a&gt;&lt;img alt="" height="1" src="https://blogger.googleusercontent.com/tracker/12467669-6237898775794439423?l=blog.jayfields.com" width="1" /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=joS-o4o84ug:6bbzSf8hAns:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=joS-o4o84ug:6bbzSf8hAns:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/joS-o4o84ug" height="1" width="1"/&gt;</content>
		<author>
			<name>jaycfields</name>
			<email>noreply@blogger.com</email>
			<uri>http://blog.jayfields.com/search/label/clojure</uri>
		</author>
		<source>
			<title type="html">Jay Fields' Thoughts</title>
			<subtitle type="html">experiences in software development</subtitle>
			<link rel="self" href="http://www.blogger.com/feeds/12467669/posts/default/-/clojure" />
			<id>tag:blogger.com,1999:blog-12467669</id>
		</source>
	<feedburner:origLink>http://blog.jayfields.com/2012/05/clojure-expectations-colorized.html</feedburner:origLink></entry>

	<entry>
		<title type="html">The root of polymorphism: The Anti-If Campaign</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/Vp2dfNnxUbw/root-of-polymorphism-anti-if-campaign.html" />
		<id>tag:blogger.com,1999:blog-5556918437810598389.post-6967862940464527141</id>
		<updated>2012-05-24T12:09:53+00:00</updated>
		<content type="html">Ever heard about the &lt;a href="http://www.antiifcampaign.com/" target="_blank"&gt;Anti-If Campaign&lt;/a&gt;? The less &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt;-statements there are in your code, the better -- argues Francesco Cirillo, the initiator of the Anti-If Campaign. There is a lot of truth behind his campaign. Too much &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt;-statements in your code are evil, that's for sure. They'll make your code static, hard to maintain and no fun to read. It goes without saying that related concepts like switch-statements, conditionals and the like are subsumed under "&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt;". They are just syntactic sugar for a certain arrangement of &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt;-statements.&lt;br /&gt;&lt;br /&gt;I asked myself: What if we abandon &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt;-statements completely? What about being absolutely strict about the use of &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt; and related concepts: No &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt;s in your code anywhere anyplace. You are not allowed to use &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt; at all. It is like not having such a construct in your programming language.&lt;br /&gt;&lt;br /&gt;Is it possible to write code without &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt;s? Yes, it is, as I'll show in this post. You'll end up with polymorphic functions instead -- and this is really cool stuff. Polymorphic functions are a result of having no &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt;s at your fingertips.&lt;br /&gt;&lt;br /&gt;So let us proclaim the &lt;span style="font-family: inherit;"&gt;&lt;i&gt;No-If Campaign&lt;/i&gt; for the sake of being extreme&lt;/span&gt; -- and see where it leads us to. In the following, I'll use Clojure for demonstration purposes. &lt;a href="http://clojure.org/" target="_blank"&gt;Clojure&lt;/a&gt; is a functional programming language and belongs to the family of Lisp languages. Don't worry if you don't know Clojure. The programs are simple to grasp and should let you follow the line of argumentation.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt; The Magic with Maps&lt;/h3&gt;&lt;div&gt;A map, sometimes also called dictionary, associative array or hash map, is a data structure that stores pairs of key values and target values. A key value is uniquely associated with a target value. In Clojure, maps are written with curly braces. The example interaction at the console (called REPL in Clojure speak) associates so-called keywords with numbers; the ordering of the pairs is irrelevant.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;user=&amp;gt; (def day {:mon 1 :tue 2 :wed 3 :thu 4 :fri 5})&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;#'user/day&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;It is a specialty of Lisp-like languages, that programs are written with parentheses. It's something one quickly gets used to. The above code defines &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;day &lt;/span&gt;to be bound to a map with the given elements.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;To query a map, the map and a key value must be given.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;user=&amp;gt; (day :thu)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;4&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;user=&amp;gt; (day :sat)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;nil&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;If there is no target value associated with a key value, &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;nil&lt;/span&gt; is returned. We can provide a default value as an extra argument to be returned instead.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;user=&amp;gt; (day :thu 0)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;4&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;user=&amp;gt; (day :sat 0)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;0&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The notion of equality is built into maps. Otherwise we couldn't query a map. That means: We can re-implement "equality" with the help of a map.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;user=&amp;gt; (defn equal? [x y] ({y true} x false))&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;#'user/equal?&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The code defines a function called &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;equal?&lt;/span&gt; that expects two arguments, namely &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;x&lt;/span&gt; and &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;y&lt;/span&gt;. The body of the functions says: if &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;x&lt;/span&gt; is not a key value in map &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;{y true}&lt;/span&gt; return &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;false&lt;/span&gt;; otherwise, if &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;x&lt;/span&gt; equals &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;y&lt;/span&gt; return &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;true&lt;/span&gt;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Let this use of a map sink in for a moment. Once you get the overall idea, it is easy to see how we can re-implement &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;How does &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if &lt;/span&gt;work in Clojure? In Clojure, &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt; is a so-called special form. It expects at least two arguments, a third argument is optional. The evaluation of an &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt; is as follows: If the evaluation of the first arguments results in &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;false &lt;/span&gt;or &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;nil&lt;/span&gt;, the third argument is evaluated and its result returned; if the third argument is missing, &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;nil &lt;/span&gt;is returned. If the evaluation of the first argument is neither &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;false&lt;/span&gt; nor &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;nil&lt;/span&gt;, the second argument is evaluated and its result returned. It sounds more complicated than it actually is. Let us take an example&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;user=&amp;gt; (if (== 2 3) (+ 2 3) (- 2 3))&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;-1&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Since the evaluation of &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;(== 2 3)&lt;/span&gt; leads to &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;false&lt;/span&gt;, the third argument to &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt; is evaluated, which results in &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;-1&lt;/span&gt;. Easy, isn't it?!&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;We could emulate this behavior with a map in the following way:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;user=&amp;gt; (eval ({false '(- 2 3) nil '(- 2 3)} (== 2 3) '(+ 2 3)))&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;-1&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In the map, there are key values for &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;false&lt;/span&gt; and &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;nil&lt;/span&gt;, which are both associated to the same expression. They are quoted (that's what the apostrophe is for) to suppress premature evaluation. The default expression &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;'(+ 2 3)&lt;/span&gt; is quoted for the very same reason. Depending on the evaluation of the test-expression, here &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;(== 2 3)&lt;/span&gt;, either the default expression or the target value is taken. The resulting expression is evaluated by &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;eval&lt;/span&gt;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;We can capture this use of a map as a coding pattern with the help of a macro. Let us call the macro &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;IF&lt;/span&gt; -- for obvious reasons.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;(defmacro IF&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;  ([test then]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;    `(IF ~test ~then nil))&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;  ([test then else]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;    `(eval ({false '~else, nil '~else} ~test '~then))))&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Don't worry when you don't get all the details of macros and the special characters used inside. The point is that&lt;/div&gt;&lt;div&gt;&lt;ol&gt;&lt;li&gt;this macros behaves exactly like an &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt; without using an &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt; for its implementation. It is a proof-of-concept: We can live without &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt; -- because we can re-built it from maps.&lt;/li&gt;&lt;li&gt;this macro reads like a perfect specification of an &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt;, which is a very interesting aspect of our approach.&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;user=&amp;gt; (IF (== 2 3) (+ 2 3) (- 2 3))&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;-1&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;(Note to experts: Because of &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;eval&lt;/span&gt;, the macro does not respect lexical scope. Nothing to worry about in a proof-of-concept demonstration.)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;To conclude: Yes, we don't need &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt; as long as we have maps natively provided in our programming language. We can re-implement &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This sounds ridiculous: We proclaim the No-If Campaign just in order to re-introduce &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt;-statements? You are right, we need &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt;-statements one way or the other. We can't seriously get rid of them. In programming, the concept of choice is essential and needs to be used. &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt;-statements are just the most primitive &lt;i&gt;binary choice construct&lt;/i&gt; you can think of -- and they have their meaning and use.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;But there is another lesson to be learnt from re-implementing &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt; with a map. With maps, we have a &lt;i&gt;multiple choice construct&lt;/i&gt;, which can be instrumented for implementing polymorphic functions.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h3&gt; Polymorphism&lt;/h3&gt;Instead of choosing either something based on &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;false&lt;/span&gt;/&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;nil&lt;/span&gt; or choosing something else otherwise (&lt;i&gt;binary choice&lt;/i&gt;), we generalize the idea of choice with maps. Based on any kind and any number of key values a map returns an associated target value (&lt;i&gt;multiple choice&lt;/i&gt;). To get rid of the use of &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;eval&lt;/span&gt; (see our &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;IF&lt;/span&gt; macro), we demand that any value associated with a key value has to be a function.&lt;br /&gt;&lt;br /&gt;Assumed we would like to calculate the area of a given geometric shape. The formulas are dependent on the type of shape. The area of a circle is computed in another way than the area of a rectangle. This knowledge can be encoded with a map.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;(def shape2func&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;  {:circle    (fn [r]   (* r r Math/PI))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;   :rectangle (fn [a b] (* a b))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;   :triangle  (fn [a h] (* a h 0.5))})&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now, we define a function &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;area &lt;/span&gt;which expects at least one argument. This very argument acts as a sort of identifier for choosing the right function from map &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;shape2func&lt;/span&gt;. The function is applied on any further arguments supplied with function &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;area&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;(defn area [shape &amp;amp; args]&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;  (apply (shape2func shape) args))&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;Function &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;area&lt;/span&gt; has become a polymorphic function! Based on the value of some argument -- here the very first argument identifying the kind or type of shape one refers to -- a proper implementation is chosen and called.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;user=&amp;gt; (area :circle 2)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;12.566370614359172&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;user=&amp;gt; (area :rectangle 2 3)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;6&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This kind of polymorphism is so much intriguing that it is worth being captured with a macro. The macro eases the definition of polymorphic functions. What we add to the macro is the idea of a dispatch function. The dispatch function determines the identifier used as a key value for looking up the function in the map. It gives us some additional flexibility.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;(defmacro defnpoly&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;  ([name dispatch-fn map]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;    `(defnpoly ~name ~dispatch-fn ~map nil))&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;  ([name dispatch-fn map default-fn]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;    `(defn ~name [&amp;amp; args#]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;      (apply&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;        (~map (apply ~dispatch-fn args#) ~default-fn)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;        args#))))&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Don't worry if you do not get the details of the macro. Using the macro is straight forward. It captures a pattern of a &lt;i&gt;multiple choice construct&lt;/i&gt; -- and that is what we are after.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Using the macro, the definition of our polymorphic function &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;area&lt;/span&gt; looks like this; note how the area for a square is implemented:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;(defnpoly area (fn [shape &amp;amp; args] shape)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;  {:circle (fn [self r] (* r r Math/PI))&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;   :rectangle (fn [self a b] (* a b))&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;   :square (fn [self a] (area :rectangle a a))&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;   :triangle (fn [self a b] (* a b 0.5))})&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The dispatch function captures the previously mentioned strategy how a dispatch value is determined from a given set of arguments. It is the very first argument the dispatch is based on. Since the different functions implementing &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;area&lt;/span&gt; are called with the very same arguments as the dispatch function is called with, we need to capture the first argument called &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;self&lt;/span&gt; though it is ignored in the body of the functions. The use of &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;self&lt;/span&gt; might trigger a revelation: object-orientation is nearby.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;user=&amp;gt; (area :circle 2)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;12.566370614359172&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;user=&amp;gt; (area :square 2)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;4&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;As you can see, no &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt;-statements are needed nor used in polymorphic functions. And that's exactly what the Anti-If Campaign is after: Use polymorphic functions, use the power of such a &lt;i&gt;multiple choice construct&lt;/i&gt; whenever meaningful and possible. &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;If&lt;/span&gt;-statements are no adequate means to emulate multiple choice. Beyond the need of &lt;i&gt;binary choice&lt;/i&gt;, &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt;-statements make code for &lt;i&gt;multiple choice&lt;/i&gt; ugly, hard to maintain and less adaptable. As you can see, it is a breeze to add an implementation for &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;:square&lt;/span&gt; to &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;area&lt;/span&gt; -- no &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt; is required.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;One can do amazing things with polymorphic functions and a flexible dispatch mechanism. It embraces first argument type dispatch as is done in object-orientation. But there is more to it. Let us have a simple example for dispatching on the type of both arguments given to polymorphic function &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;times&lt;/span&gt;: &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;(defnpoly times (fn [x y] [(type x) (type y)])&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;  {[Long Long]   (fn [x y] (* x y))&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;   [Long String] (fn [n s] (reduce str (repeat n s)))&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;   [String Long] (fn [s n] (times n s))})&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The program is clear and succinct -- because there are no &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt;s. Polymorphic functions have their own beauty!&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;user=&amp;gt; (times 4 3)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;12&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;user=&amp;gt; (times 4 "hi")&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;"hihihihi"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;user=&amp;gt; (times "hi" 0)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;""&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Polymorphic functions are so much useful that Clojure has them already included. In Clojure, polymorphic functions are called multimethods.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h3&gt; Multimethods in Clojure&lt;/h3&gt;&lt;div&gt;Part of the fascination of Lisp-like languages such as Clojure is that they are extremely extensible. If you are missing polymorphic functions, you write yourself a short macro, and you have the feature and can use it. We demonstrated how easy that is.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Clojure follows the tradition of Lisp and favors a slightly different model of defining a polymorphic function in your code. The polymorphic function is declared with &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;defmulti &lt;/span&gt;and its implementing functions are defined with &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;defmethod&lt;/span&gt;. This way, Clojure abstracts away the use of a map for polymorphism. It adds a layer of abstraction and removes a little bit of syntactic overhead we had in our solution. Other than that, &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;defmulti&lt;/span&gt; and &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;defmethod &lt;/span&gt;behave exactly like &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;defnpoly&lt;/span&gt;. See yourself, how close the definition of area is to our &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;defnpoly &lt;/span&gt;approach.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;(defmulti area (fn [shape &amp;amp; args] shape))&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;(defmethod area :circle [self r] (* r r Math/PI))&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;(defmethod area :rectangle [self a b] (* a b))&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;(defmethod area :square [self a] (area :rectangle a a))&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;(defmethod area :triangle [self a b] (* a b 0.5))&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Multifunction &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;area &lt;/span&gt;is used exactly like our polymorphic function definition of &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;area&lt;/span&gt;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;user=&amp;gt; (area :circle 2)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;12.566370614359172&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;user=&amp;gt; (area :square 2)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;4&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;There is a lot more to say about multifunctions in Clojure, but I do not want to drift away from our starting point: the Anti-If Campaign.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h3&gt; Summary&lt;/h3&gt;&lt;div&gt;In the data structure of a map the concepts of &lt;i&gt;equality &lt;/i&gt;and &lt;i&gt;choice &lt;/i&gt;are inherently included. The interesting part is that a map provides a mechanism for multiple choice. That means that binary choice (being another word for &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt;, so to speak) is just a special case of multiple choice; that is why &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt; can easily be re-implemented using maps. To have a binary choice construct like &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt; at hand is useful and meaningful.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The fun part is to utilize and explore the power of multiple choice with maps. It takes a simple step and the introduction of a dispatch function and we have polymorphic functions. Polymorphic functions are a very powerful control construct. They are easy to use, make code highly readable and flexible to adapt. Same does object-orientation. But the flexibility given by a dispatch function goes beyond (single type-dispatch) object-orientation.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;And that is the message of the Anti-If Campaign: &lt;i&gt;Learn to think in and use multiple choice constructs&lt;/i&gt; -- be they provided in form of object-orientation or polymorphic functions (like in Clojure). If you use binary choice (i.e. &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt;) for multiple choice, your code will be messy and ugly. So, don't use &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;if&lt;/span&gt; to emulate multiple choice. Be the power of maps with you ;-)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img alt="" height="1" src="https://blogger.googleusercontent.com/tracker/5556918437810598389-6967862940464527141?l=denkspuren.blogspot.com" width="1" /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=Vp2dfNnxUbw:d4XYT881LWs:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=Vp2dfNnxUbw:d4XYT881LWs:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/Vp2dfNnxUbw" height="1" width="1"/&gt;</content>
		<author>
			<name>dh</name>
			<email>noreply@blogger.com</email>
			<uri>http://denkspuren.blogspot.com/search/label/clojure</uri>
		</author>
		<source>
			<title type="html">denkspuren</title>
			<subtitle type="html">gedanken, ideen, anregungen und links rund um informatik-themen</subtitle>
			<link rel="self" href="http://www.blogger.com/feeds/5556918437810598389/posts/default/-/clojure" />
			<id>tag:blogger.com,1999:blog-5556918437810598389</id>
		</source>
	<feedburner:origLink>http://denkspuren.blogspot.com/2012/05/root-of-polymorphism-anti-if-campaign.html</feedburner:origLink></entry>

	<entry>
		<title type="html">Clojure, visualization, and scripts</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/y3B_THH4kCc/clojure-visualization-and-scripts.html" />
		<id>tag:blogger.com,1999:blog-4867372421772813569.post-1112415088722588841</id>
		<updated>2012-05-24T07:25:49+00:00</updated>
		<content type="html">Bit of a technical post for my own reference, about visualization and scripting in clojure.&lt;br /&gt;&lt;br /&gt;&lt;h2&gt; Clojure and visualization&lt;/h2&gt;Being interested in clojure, a tweet by Francesco Strozzi (@fstrozzi) caught my attention last week: "&lt;i&gt;A D3 like #dataviz project for #clojure. Codename &lt;b&gt;C2&lt;/b&gt; and looks promising. &lt;a href="http://keminglabs.com/c2/"&gt;http://keminglabs.com/c2/&lt;/a&gt;. They need contribs so spread the word!&lt;/i&gt;" I tried a while ago to do some stuff in D3, but the javascript got in the way so I gave up after a while. But I was still pulled towards something html5+css rather than java applets as created by processing.org.&lt;br /&gt;&lt;br /&gt;Although still in a very early stage, C2 is already very powerful. Rapid development of visualizations is aided by the visual repl: the webpage localhost:8987 automatically loads the last modified file in the samples directory.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;(ns rectangles-hover&lt;br /&gt;  (:use [c2.core :only [unify]]))&lt;br /&gt;&lt;br /&gt;(def css "&lt;br /&gt;body { background-color:white;}&lt;br /&gt;rect { -webkit-transition: all 1s ease-in-out;&lt;br /&gt;       fill:rgb(255,0,0);}&lt;br /&gt;rect:hover { -webkit-transform: translate(3em,0);&lt;/pre&gt;&lt;pre&gt;fill:rgb(0,255,0);}&lt;/pre&gt;&lt;pre&gt;circle { opacity: 1;&lt;br /&gt;         -webkit-transition: opacity 1s linear;&lt;br /&gt;         fill:rgb(0,0,255);}&lt;br /&gt;circle:hover { opacity: 0; }&lt;br /&gt;")&lt;br /&gt;&lt;br /&gt;[:svg&lt;br /&gt; [:style {:type "text/css"} (str "&amp;lt;[CDATA[" css "]]&amp;gt;")]&lt;br /&gt; (unify {"A" 50 "B" 120} (fn [[label val]]&lt;br /&gt;  [:rect {:x val :y val :height 50 :width 60}]))&lt;br /&gt; (unify {"C" 180 "D" 240} (fn [[label val]]&lt;br /&gt;  [:circle {:cx val :cy val :r 15}]))]&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-eifqHnLmb5o/T70dxHevT2I/AAAAAAAAD-Y/qk7Pab0YFMk/s1600/Screen+Shot+2012-05-23+at+19.25.42.png" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-eifqHnLmb5o/T70dxHevT2I/AAAAAAAAD-Y/qk7Pab0YFMk/s1600/Screen+Shot+2012-05-23+at+19.25.42.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;This bit of code draws 2 red rectangles and 2 blue circles. Hovering the mouse over any of the rectangles will move it to the right and change its colour to green; hovering over a circle will make that circle transparent. Some more scripts that I've used to build up simple things and learn C2 are on &lt;a href="https://github.com/jandot/c2-samples"&gt;github&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Although interactions are not covered in C2 itself, simple transitions can be handled in the CSS part (see the example above). Brushing, linking and other types of interaction would be interesting to have available as well, though. But the developer Kevin Lynagh is very responsive.&lt;br /&gt;&lt;br /&gt;I haven't looked yet into how to run C2 without the visual repl; still on my to-do list. (&lt;b&gt;UPDATE&lt;/b&gt;: see end of post)&lt;br /&gt;&lt;br /&gt;&lt;h2&gt; Clojure and scripting&lt;/h2&gt;And today, I saw &lt;a href="http://charsequence.blogspot.com/2012/04/scripting-clojure-with-leiningen-2.html"&gt;this&lt;/a&gt;. Leiningen 2 will allow you to easily execute little clojure scripts without the whole setup of a project. Makes it amenable for pipelining just like you would do with little perl/ruby/python scripts. The completely-useless-but-good-enough-as-proof-of-principle little example below attaches some dashes to the front and stars at the back of anything you throw at it from STDIN.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;#!/bin/bash lein exec&lt;br /&gt;(doseq [line (line-seq (java.io.BufferedReader. *in*))]&lt;br /&gt; (println (str "----" line "****")))&lt;/pre&gt;&lt;br /&gt;Pipe anything into this:&lt;br /&gt;&lt;pre&gt;ls ~ | ./proof-of-principle.clj&lt;/pre&gt;&lt;br /&gt;Dependencies are now stored in ~/.mv2 rather than in the project directory, you can load libraries such as clojure like this:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;#!/bin/bash lein exec&lt;br /&gt;(use '[leiningen.exec :only (deps)])&lt;br /&gt;(deps '[[incanter "1.3.0"]])&lt;br /&gt;&lt;br /&gt;(use '(incanter core charts stats datasets))&lt;br /&gt;(save (histogram (sample-normal 1000)) "plot.png")&lt;/pre&gt;&lt;br /&gt;This also works in the interactive repl ("lein repl").&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Bringing the two together&lt;/h2&gt;It's really easy to combine these two (after a pointer from C2 Kevin (Thanks!)). You need an additional dependency on hiccup to convert to html, but that's it.&lt;br /&gt;&lt;br /&gt;Here's a script that, when executed with "lein exec this-script.clj" will generate a html file with the interactive picture shown above.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;#!/bin/bash lein exec&lt;br /&gt;(use '[leiningen.exec :only (deps)])&lt;br /&gt;(deps '[[com.keminglabs/c2 "0.1.1"] [hiccup "1.0.0"]])&lt;br /&gt;&lt;br /&gt;(use '[c2.core :only (unify)])&lt;br /&gt;(use 'hiccup.core)&lt;br /&gt;&lt;br /&gt;(def css "&lt;br /&gt;body { background-color:white;}&lt;br /&gt;rect { -webkit-transition: all 1s ease-in-out;&lt;br /&gt;       fill:rgb(255,0,0);}&lt;br /&gt;rect:hover { -webkit-transform: translate(3em,0);&lt;br /&gt;             fill:rgb(0,255,0);}&lt;br /&gt;circle { opacity: 1;&lt;br /&gt;         -webkit-transition: opacity 1s linear;&lt;br /&gt;         fill:rgb(0,0,255);}&lt;br /&gt;circle:hover { opacity: 0; }&lt;br /&gt;")&lt;br /&gt;&lt;br /&gt;(def svg [:svg&lt;br /&gt; [:style {:type "text/css"} (str "")]&lt;br /&gt; (unify {"A" 50 "B" 120} (fn [[label val]]&lt;br /&gt;  [:rect {:x val :y val :height 50 :width 60}]))&lt;br /&gt; (unify {"C" 180 "D" 240} (fn [[label val]]&lt;br /&gt;  [:circle {:cx val :cy val :r 15}]))])&lt;br /&gt;&lt;br /&gt;(spit "test.html" (html svg))&lt;/pre&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img alt="" height="1" src="https://blogger.googleusercontent.com/tracker/4867372421772813569-1112415088722588841?l=saaientist.blogspot.com" width="1" /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=y3B_THH4kCc:xZrlCIIXq4k:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=y3B_THH4kCc:xZrlCIIXq4k:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/y3B_THH4kCc" height="1" width="1"/&gt;</content>
		<author>
			<name>Jan Aerts</name>
			<email>noreply@blogger.com</email>
			<uri>http://saaientist.blogspot.com/search/label/clojure</uri>
		</author>
		<source>
			<title type="html">Saaien Tist</title>
			<subtitle type="html">On data visualization, bioinformatics and personal productivity</subtitle>
			<link rel="self" href="http://www.blogger.com/feeds/4867372421772813569/posts/default/-/clojure" />
			<id>tag:blogger.com,1999:blog-4867372421772813569</id>
		</source>
	<feedburner:origLink>http://saaientist.blogspot.com/2012/05/clojure-visualization-and-scripts.html</feedburner:origLink></entry>

	<entry>
		<title type="html">[lein-droid "0.0.1"]</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/odO1HjMxNYg/lein-droid-001.html" />
		<id>tag:blogger.com,1999:blog-7856174353097322988.post-7698570383663777879</id>
		<updated>2012-05-23T20:21:00+00:00</updated>
		<content type="html">&lt;div dir="ltr" style="text-align: left;"&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; text-align: right;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/--wa8mg9E35g/T71CemnE-4I/AAAAAAAAAVk/F-XYPDi6uRk/s1600/forever-in-love.png" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="200" src="http://3.bp.blogspot.com/--wa8mg9E35g/T71CemnE-4I/AAAAAAAAAVk/F-XYPDi6uRk/s200/forever-in-love.png" width="200" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Best friends forever.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;So, the very first release is done.&lt;br /&gt;&lt;br /&gt;Actually it wasn't much work to do since I posted here the last time. I added some fancy functions to take apart the AndroidManifest.xml file - it was necessary since starting the REPL requires the Internet permission, and I wanted it to be added automatically (if it wasn't not already there). Also I get the package name and the main activity name from the manifest in order to start the application from Leiningen. Not so necessary, but convenient.&lt;br /&gt;&lt;br /&gt;I managed to make all the project dependencies to get totally AOT-compiled for the development build. Now all of them are available in the REPL (as it turned out, they were not before).&lt;br /&gt;&lt;br /&gt;Added a "new" task to create Android projects using leiningen.new.templates library.&lt;br /&gt;&lt;br /&gt;Designed a fancy macro for running subprocesses (which form the 90% of my plugin). Now the subprocess runs silently by default, but if it's return code is not zero, then it prints out the errors. With the DEBUG flag enabled it prints the messages even if the process finishes successfully.&lt;br /&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-x836qvfAz2Q/T71CfKKsPQI/AAAAAAAAAVo/yEqUJvV1klM/s1600/wielding-parentheses.png" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="159" src="http://3.bp.blogspot.com/-x836qvfAz2Q/T71CfKKsPQI/AAAAAAAAAVo/yEqUJvV1klM/s200/wielding-parentheses.png" width="200" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Android wields the parentheses &lt;br /&gt;filled with the Power of Lisp&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;Learned how to read passwords from the console in Java. The official javadocs suggest to fill the array of password characters with zeros as soon as the password is no longer needed. I wonder how many potentially-unsafe data Clojure leaves in memory when I convert the array to string and pass it around for a bit? And how long will it live before the GC cleans it out?&lt;br /&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-OqzHqDHBdXs/T71CkE2rtZI/AAAAAAAAAV0/I-Ev_oDL_qM/s1600/ic_launcher_hdpi.png" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-OqzHqDHBdXs/T71CkE2rtZI/AAAAAAAAAV0/I-Ev_oDL_qM/s1600/ic_launcher_hdpi.png" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Hey there!&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;Put together a little &lt;a href="https://github.com/alexander-yakushev/lein-droid/wiki/Tutorial" target="_blank"&gt;tutorial&lt;/a&gt; to explain how to start using lein-droid.&lt;br /&gt;&lt;br /&gt;And by the way - GSoC has officially begun! So things would only get more interesting. So stay tuned and enjoy the end of the spring ;). &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img alt="" height="1" src="https://blogger.googleusercontent.com/tracker/7856174353097322988-7698570383663777879?l=clojure-android.blogspot.com" width="1" /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=odO1HjMxNYg:K0wERkh-PBo:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=odO1HjMxNYg:K0wERkh-PBo:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/odO1HjMxNYg" height="1" width="1"/&gt;</content>
		<author>
			<name>Alex Yakushev</name>
			<email>noreply@blogger.com</email>
			<uri>http://clojure-android.blogspot.com/</uri>
		</author>
		<source>
			<title type="html">Clojure Development on Android</title>
			<link rel="self" href="http://clojure-android.blogspot.com/feeds/posts/default?alt=rss" />
			<id>tag:blogger.com,1999:blog-7856174353097322988</id>
		</source>
	<feedburner:origLink>http://clojure-android.blogspot.com/2012/05/lein-droid-001.html</feedburner:origLink></entry>

	<entry>
		<title type="html" xml:lang="en">Calculating Bell numbers in a single tweet</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/Gs8SF8HdaS4/" />
		<id>http://maurits.wordpress.com/?p=661</id>
		<updated>2012-05-23T12:48:40+00:00</updated>
		<content type="html" xml:lang="en">&lt;p&gt;Recently I stumbled upon a white paper by Roger Sessions called &lt;a href="http://www.objectwatch.com/whitepapers/MathOfITSimplification-103.pdf"&gt;“The Mathematics of IT Simplification”&lt;/a&gt;. In this paper he describes an approach called synergistic partitioning, which is based on the mathematics of sets, equivalence relations, and partitions. One of the topics that comes up in this article is how many ways there are to partition N elements. The answer to this is well-known and called the Nth &lt;a href="http://en.wikipedia.org/wiki/Bell_number"&gt;Bell number&lt;/a&gt;.&lt;/p&gt;
&lt;div class="wp-caption aligncenter" style="width: 159px;"&gt;&lt;img alt="" height="360" src="http://upload.wikimedia.org/wikipedia/commons/thumb/1/19/Set_partitions_5%3B_circles.svg/249px-Set_partitions_5%3B_circles.svg.png" width="149" /&gt;&lt;p class="wp-caption-text"&gt;The 52 partitions of a set with 5 elements&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;The Wikipedia page that explains the Bell number also shows two implementations on how to calculate them, one in Ruby and the other one in Python. The Ruby version needs 17 lines of code, the Python version 12 lines. I have the peculiar habit of intriguing/annoying my colleagues at work with the statement that using Clojure the solution to any programming problem fits into one single tweet. In other words: 140 characters.&lt;/p&gt;
&lt;p&gt;I’ll start with my first attempt:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;pre class="brush: clojure;"&gt;(defn append-ele [s x] (concat s (list (+ x (last s)))))

(defn next-row [s]
  (reduce append-ele (list (last s)) s))

(defn bell [n]
  (loop [n n s '(1) b s]
    (if (= n 1)
      (reverse b)
      (recur (dec n) (next-row s) (cons (last s) b)))))

(println (bell 9))
&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The first function (&lt;em&gt;append-ele&lt;/em&gt;) appends a single new element to a row in the Bell triangle (explained in the Wikipedia article). In several ways this implementation is suboptimal since &lt;em&gt;concat&lt;/em&gt; can only concatenate sequences, so I have to convert the single element to a list first. And what’s worse, appending at the end of a sequence is expensive since it’s computation is O(N), while prepending would only take one single operation.&lt;/p&gt;
&lt;p&gt;The function &lt;em&gt;next-row&lt;/em&gt; calculates the next row in the Bell triangle. This row always starts with the last element of the previous row. I implemented this by a simple reduce over the elements of the previous row.&lt;/p&gt;
&lt;p&gt;And finally the function &lt;em&gt;bell&lt;/em&gt; returns a sequence with the first &lt;em&gt;n&lt;/em&gt; Bell numbers. I use a loop/recur to avoid a stack overflow. The sequence of Bell numbers is constructed in reverse order, so at the end (line 9) I have to call &lt;em&gt;reverse&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;While this version is already pretty short (10 lines, without the printing), this still won’t fit in a single tweet. So the next step was to remove the first two helper functions and inline all the code into a single function. &lt;strong&gt;Warning&lt;/strong&gt;: this is not good coding practice! With this disclaimer, here is the resulting code:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;pre class="brush: clojure;"&gt;(defn bell [n]
  (loop [n n s '(1) b s]
    (if (= n 1)
      (reverse b)
      (recur (dec n)
             (reduce #(concat % (list (+ %2 (last %)))) (list (last s)) s)
             (cons (last s) b)))))
&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Without the whitespace this implementation is 170 characters. Almost there! As you can see there are still some ‘expensive’ keywords like &lt;em&gt;concat&lt;/em&gt; and &lt;em&gt;reverse&lt;/em&gt; (6 and 7 characters!) and some annoying conversions from single numbers to lists. The only way to avoid this is to use a specialized data structure like vector instead of a sequence:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;pre class="brush: clojure;"&gt;(defn bell [n]
  (loop [n n s [1] b s]
    (if (= n 1)
      b
      (recur (dec n)
             (reduce #(conj % (+ %2 (last %))) [(last s)] s)
             (conj b (last s))))))
&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Finally the code (without the indentation) fits into 140 characters. One caveat: I use &lt;em&gt;conj&lt;/em&gt; which nicely appends an element to the end of a vector. However this behaviour of &lt;em&gt;conj&lt;/em&gt; is not guaranteed. It is allowed to add an element anywhere in a sequence. When you use a list for example, the element is prepended. Because of this he above algorithm is O(N^2).&lt;/p&gt;
&lt;p&gt;&lt;img alt="" class="alignnone aligncenter" height="128" src="http://hosting.ber-art.nl/wp-content/uploads/twitter-logo.png" width="128" /&gt;&lt;/p&gt;
&lt;p&gt;I will leave it as an exercise for the reader to implement the Bell number calculation as a lazy sequence so that you can use for example &lt;em&gt;(take 9 (bell))&lt;/em&gt;. Have fun.&lt;/p&gt;
&lt;br /&gt;  &lt;a href="http://feeds.wordpress.com/1.0/gocomments/maurits.wordpress.com/661/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/maurits.wordpress.com/661/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/godelicious/maurits.wordpress.com/661/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/maurits.wordpress.com/661/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/gofacebook/maurits.wordpress.com/661/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/maurits.wordpress.com/661/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/gotwitter/maurits.wordpress.com/661/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/maurits.wordpress.com/661/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/gostumble/maurits.wordpress.com/661/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/maurits.wordpress.com/661/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/godigg/maurits.wordpress.com/661/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/maurits.wordpress.com/661/" /&gt;&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/goreddit/maurits.wordpress.com/661/" rel="nofollow"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/maurits.wordpress.com/661/" /&gt;&lt;/a&gt; &lt;img alt="" border="0" height="1" src="http://stats.wordpress.com/b.gif?host=maurits.wordpress.com&amp;amp;blog=73044&amp;amp;post=661&amp;amp;subd=maurits&amp;amp;ref=&amp;amp;feed=1" width="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=Gs8SF8HdaS4:w8ZJEiLXx8c:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=Gs8SF8HdaS4:w8ZJEiLXx8c:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/Gs8SF8HdaS4" height="1" width="1"/&gt;</content>
		<author>
			<name>maurits</name>
			<uri>http://maurits.wordpress.com</uri>
		</author>
		<source>
			<title type="html">Maurits thinks aloud » Clojure</title>
			<subtitle type="html">Stuff I care about</subtitle>
			<link rel="self" href="http://maurits.wordpress.com/category/clojure/feed/" />
			<id>http://maurits.wordpress.com</id>
		</source>
	<feedburner:origLink>http://maurits.wordpress.com/2012/05/23/calculating-bell-numbers-in-a-single-tweet/</feedburner:origLink></entry>

	<entry>
		<title type="html">Generating HTML with Clojure</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/_gytFwdBpEI/generating-html-with-clojure.html" />
		<id>http://www.andrewwhitehouse.com/journal/2012/5/23/generating-html-with-clojure.html</id>
		<updated>2012-05-23T11:48:25+00:00</updated>
		<content type="html">&lt;p&gt;[It's been a while ... I'm currently inbetween contracts and this has given me the chance to focus on writing some Clojure code.]&lt;/p&gt;
&lt;p&gt;As I'm between contracts I'm working on a web application for commuters. It's currently Postgres on the back end (which I am going to migrate to MongoDB) and Clojure for the application.&lt;/p&gt;
&lt;p&gt;When building web pages I want something that allows me to get the static pages right first and then make them dynamic, rather than the common approach of tweaking the dynamically generated pages until they look right. In Clojure, you can do this with the Enlive library, written by Christophe Grande.&lt;/p&gt;
&lt;p&gt;Today my copy of Clojure Programming arrived; Christophe is one of the authors and it has a section on Enlive, which has been really helpful.&lt;/p&gt;
&lt;p&gt;I've been trying to figure out how to generate a drop-down list and it turned out to be easier than I expected. Here's the code:&lt;/p&gt;
&lt;pre class="Clojure brush:"&gt;(ns scratch.enlive.test1
  (:require [net.cgrand.enlive-html :as h]))

(def select-template
  "&lt;select&gt;
    &lt;option&gt;baz&lt;/option&gt;
  &lt;/select&gt;")

(defn options
  [option-values]
  (h/sniptest my-select
    [:option] (h/clone-for [option-value-map option-values]
                (h/do-&amp;gt;
                  (h/set-attr :value (:value option-value-map))
                  (h/content (:display option-value-map))))))

(options [{:value "one" :display "two"} {:value "three" :display "four"}])
&lt;/pre&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=_gytFwdBpEI:T6gI0Jt1RYQ:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=_gytFwdBpEI:T6gI0Jt1RYQ:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/_gytFwdBpEI" height="1" width="1"/&gt;</content>
		<author>
			<name>Andrew Whitehouse</name>
			<uri>http://pipes.yahoo.com/pipes/pipe.info?_id=23ba1ea6d318e56ea43738984d9d19ff</uri>
		</author>
		<source>
			<title type="html">Andrew Whitehouse</title>
			<subtitle type="html">Pipes Output</subtitle>
			<link rel="self" href="http://pipes.yahoo.com/pipes/pipe.run?_id=23ba1ea6d318e56ea43738984d9d19ff&amp;_render=rss" />
			<id>http://pipes.yahoo.com/pipes/pipe.info?_id=23ba1ea6d318e56ea43738984d9d19ff</id>
		</source>
	<feedburner:origLink>http://www.andrewwhitehouse.com/journal/2012/5/23/generating-html-with-clojure.html</feedburner:origLink></entry>

	<entry>
		<title type="html">Generating HTML with Clojure and Enlive</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/umYXYG6IrJw/generating-html-with-clojure-and-enlive.html" />
		<id>http://www.andrewwhitehouse.com/journal/2012/5/23/generating-html-with-clojure-and-enlive.html</id>
		<updated>2012-05-23T11:48:25+00:00</updated>
		<content type="html">&lt;p&gt;[It's been a while ... I'm currently between contracts and this has given me the chance to write some more Clojure code.]&lt;/p&gt;
&lt;p&gt;My side project is a web application for commuters. The database is currently Postgres (which I am going to migrate to MongoDB) and I'm using Clojure for the application.&lt;/p&gt;
&lt;p&gt;When building web pages I want something that allows me to get the static pages right first and then make them dynamic, rather than the common approach of tweaking the dynamically generated pages until they look right. In Clojure, you can do this with the &lt;a href="https://github.com/cgrand/enlive" rel="nofollow" target="_blank"&gt;Enlive&lt;/a&gt; library, written by &lt;a href="http://clj-me.blogspot.co.uk/" rel="nofollow" target="_blank"&gt;Christophe Grande&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I have read Clojure in Action, Programming Clojure, and dipped into the Joy of Clojure. Today my copy of Clojure Programming arrived, co-authored by Christophe with &lt;a href="http://cemerick.com/" rel="nofollow" target="_blank"&gt;Chas Emerick&lt;/a&gt; and &lt;a href="http://briancarper.net/" rel="nofollow" target="_blank"&gt;Brian Carper&lt;/a&gt;. It it sub-titled "Practical Lisp for the Java World" and the practical approach is apparent; it has a section on Enlive which has been really helpful.&lt;/p&gt;
&lt;p&gt;I've been trying to figure out how to generate a drop-down list and it turned out to be easier than I was expecting once I'd read the book. Here's the code:&lt;/p&gt;
&lt;pre&gt;&lt;code class="brush: Clojure"&gt;
(ns scratch.enlive.test1
  (:require [net.cgrand.enlive-html :as h]))

(def select-template "&amp;lt;select name=\"test1\"&amp;gt;&amp;lt;option value=\"bar\"&amp;gt;baz&amp;lt;/option&amp;gt;&amp;lt;/select&amp;gt;")

(defn options
  [option-values]
  (h/sniptest select-template
    [:option] (h/clone-for [option-value-map option-values]
                (h/do-&amp;gt;
                  (h/set-attr :value (:value option-value-map))
                  (h/content (:display option-value-map))))))

(options [{:value "one" :display "two"} {:value "three" :display "four"}])
; =&amp;gt; "&lt;select&gt;\n    &lt;option&gt;two&lt;/option&gt;&lt;option&gt;four&lt;/option&gt;\n  &lt;/select&gt;"
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
The sniptest function is a great help to be able to try things out in the REPL. That [:option] vector is a selector, and the result of sniptest is to replace any elements matching that selector with the result of the clone-for.
&lt;/p&gt;
&lt;p&gt;
I think I am going to enjoy using Enlive.
&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=umYXYG6IrJw:Ak51KP_o_ao:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=umYXYG6IrJw:Ak51KP_o_ao:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/umYXYG6IrJw" height="1" width="1"/&gt;</content>
		<author>
			<name>Andrew Whitehouse</name>
			<uri>http://pipes.yahoo.com/pipes/pipe.info?_id=23ba1ea6d318e56ea43738984d9d19ff</uri>
		</author>
		<source>
			<title type="html">Andrew Whitehouse</title>
			<subtitle type="html">Pipes Output</subtitle>
			<link rel="self" href="http://pipes.yahoo.com/pipes/pipe.run?_id=23ba1ea6d318e56ea43738984d9d19ff&amp;_render=rss" />
			<id>http://pipes.yahoo.com/pipes/pipe.info?_id=23ba1ea6d318e56ea43738984d9d19ff</id>
		</source>
	<feedburner:origLink>http://www.andrewwhitehouse.com/journal/2012/5/23/generating-html-with-clojure-and-enlive.html</feedburner:origLink></entry>

	<entry>
		<title type="html" xml:lang="en">The Clojure Library Ecosystem</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/tgvLyglStjE/" />
		<id>http://www.paullegato.com/?p=590</id>
		<updated>2012-05-23T00:46:50+00:00</updated>
		<content type="html" xml:lang="en">&lt;p&gt;Clojure’s library ecosystem can be a source of confusion for new users. This quick overview will help to orient new Clojure programmers to the current state of the library system, with pointers to resources for further information.&lt;span id="more-590"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2&gt;Leiningen&lt;/h2&gt;
&lt;p&gt;Most Clojure projects use &lt;a href="https://github.com/technomancy/leiningen/" target="_blank"&gt;Leiningen&lt;/a&gt; as their build and dependency management system. Project dependencies and their required versions are placed in a file called &lt;code&gt;project.clj&lt;/code&gt;, and Leiningen takes care of downloading them. Leiningen also creates JARs of the release versions of your project, and can bridge to Emacs’ SLIME mode, run a REPL at the command line, and so on. Many plugins exist to extend Leiningen’s functionality for other things like testing and deployment.&lt;/p&gt;
&lt;p&gt;Under the covers, Leiningen uses &lt;a href="http://maven.apache.org/" target="_blank"&gt;Maven&lt;/a&gt; for dependency management. Maven is one of those ridiculously over-engineered Java projects that we all love to hate where you have to write 100 lines of XML boilerplate around 2 lines of actual project-specific configuration data. Fortunately, Leiningen insulates us from all of that.&lt;/p&gt;
&lt;p&gt;Users should be aware that, as of this writing (May, 2012), Leiningen is about to release version 2.0, which uses a slightly different &lt;code&gt;project.clj&lt;/code&gt; format. Some Leiningen plugins have not been updated for the new format. This is easy enough to work around if you know that there has been a specification change. In particular, many &lt;code&gt;:dev-dependencies&lt;/code&gt; that affect Leiningen itself have to be moved to the new &lt;code&gt;:plugins&lt;/code&gt; key.&lt;/p&gt;
&lt;h2&gt;Clojars and GitHub&lt;/h2&gt;
&lt;p&gt;Most Clojure libraries are provided in binary JAR format on &lt;a href="http://clojars.org/" target="_blank"&gt;Clojars&lt;/a&gt;, and have their source code hosted on &lt;a href="https://www.github.com/" target="_blank"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Clojure developers frequently face the situation where some critical bugfix or new feature exists only on somebody’s GitHub fork, but not in the mainline repository. The best option in this case is to get the maintainer to push a new official release with the required changes, but this is not always possible. If the project has a slow release cycle, or if the original developer is not very into the project, it can be months between the creation of patches in a fork and their release from the mainline repository to a new version on Clojars. We have a few options in that case.&lt;/p&gt;
&lt;p&gt;For development, it can be convenient to use the &lt;a href="https://github.com/tobyhede/lein-git-deps" target="_blank"&gt;lein-git-deps plugin&lt;/a&gt;. This extends Leiningen to allow it to download dependencies from GitHub into a hidden directory in your project. This is something of a fragile hack, though. If the subproject has any dependencies, they will not be checked out by Leiningen — you have to manually install them in the parent project. Worse, the code on GitHub can change at any time (unless you specify a particular release). If you redeploy your code in the future, you might wind up with a broken project. If it’s impractical to get the maintainer of a library to produce a new official release, it’s best to fork the library and make your own stable release.&lt;/p&gt;
&lt;p&gt;If you just want to use it locally, check out your fork to your local machine, bump the version number, and do &lt;code&gt;lein install&lt;/code&gt;. Within your organization, you can easily host a private Maven repository. If you want to deploy publicly, you can push a forked release to Clojars with a different group-id. Detailled instructions on how to do these things can be found &lt;a href="https://github.com/technomancy/leiningen/blob/stable/doc/DEPLOY.md" target="_blank"&gt;in the Leiningen documentation&lt;/a&gt;.&lt;/p&gt;
&lt;img alt="" src="http://www.paullegato.com/?ak_action=api_record_view&amp;amp;id=590&amp;amp;type=feed" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=tgvLyglStjE:NTqr6ZmlDpI:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=tgvLyglStjE:NTqr6ZmlDpI:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/tgvLyglStjE" height="1" width="1"/&gt;</content>
		<author>
			<name>Paul Legato</name>
			<uri>http://www.paullegato.com</uri>
		</author>
		<source>
			<title type="html">Paul Legato » clojure</title>
			<link rel="self" href="http://www.paullegato.com/blog/tag/clojure/feed/" />
			<id>http://www.paullegato.com</id>
		</source>
	<feedburner:origLink>http://www.paullegato.com/blog/clojure-library-ecosystem/</feedburner:origLink></entry>

	<entry>
		<title type="html">Senior Software Engineer at Mediaplex (Full-time)</title>
		<link href="http://feedproxy.google.com/~r/clojure/~3/4FyCRHtROkY/108-senior-software-engineer-at-mediaplex" />
		<id>urn:uuid:f4478fee-5b55-28c2-9987-8389e543aebd</id>
		<updated>2012-05-23T00:19:36+00:00</updated>
		<content type="html">&lt;p&gt;Why join us?&lt;/p&gt;

&lt;p&gt;Are you looking to join an organization with a start-up feel that has the backing of an established, stable, public company?  Do you want to work in a small group of exceptionally sharp engineers in a challenging and rewarding role while having further opportunities to grow your career?  If so, we’d like to meet with you.&lt;/p&gt;

&lt;p&gt;We are looking for a strong Senior Software Engineer to join our ad server infrastructure team.  In addition to contributing to our current core technology platform, you will help build a high volume Real-Time Bidding (RTB) system from the ground up.&lt;/p&gt;

&lt;p&gt;Your Mission&lt;/p&gt;

&lt;p&gt;Thrive in a small team environment where you’ll have the opportunity to showcase your ingenuity and influence the direction of our products. &lt;/p&gt;

&lt;p&gt;Is this you?&lt;/p&gt;

&lt;p&gt;• 7+ years experience in software development&lt;/p&gt;

&lt;p&gt;• Experience with Java-based web/app server implementations (Tomcat, Jetty, etc.)&lt;/p&gt;

&lt;p&gt;• Well-versed in internet protocols and paradigms (HTTP, REST, etc.)&lt;/p&gt;

&lt;p&gt;• Recent experience or a dedicated interest in functional programming&lt;/p&gt;

&lt;p&gt;• Desire to enhance and support large, complex systems in a global production environment&lt;/p&gt;

&lt;p&gt;• Experience with SQL (Oracle, MySQL preferred) and NoSQL (Cassandra, Hbase, MongoDB, Riak, etc.) and big data (Hadoop)&lt;/p&gt;

&lt;p&gt;• Good communication skills&lt;/p&gt;

&lt;p&gt;• Confident in a Linux-based development/production environment  (command line tools, shell scripting, etc.)&lt;/p&gt;

&lt;p&gt;• Testing and documentation skills&lt;/p&gt;

&lt;p&gt;• CS/Math degree or equivalent real-world experience&lt;/p&gt;

&lt;p&gt;Pluses:&lt;/p&gt;

&lt;p&gt;• Open source contributions&lt;/p&gt;

&lt;p&gt;• Clojure, Erlang and/or Scala experience&lt;/p&gt;

&lt;p&gt;• C/C++ experience&lt;/p&gt;

&lt;p&gt;• Experience with internet advertising&lt;/p&gt;

&lt;p&gt;• Strong debugging/troubleshooting skills in complex architectures&lt;/p&gt;

&lt;p&gt;If you are looking to join an expanding global company that still maintains that small start-up feel, we’d love to hear from you!&lt;/p&gt;
&lt;p&gt;Get information on &lt;a href="http://functionaljobs.com/jobs/108-senior-software-engineer-at-mediaplex"&gt;how to apply&lt;/a&gt; for this position.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/clojure?a=4FyCRHtROkY:OIeS78bjjc0:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/clojure?a=4FyCRHtROkY:OIeS78bjjc0:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/clojure?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/clojure/~4/4FyCRHtROkY" height="1" width="1"/&gt;</content>
		<author>
			<name>FunctionalJobs.com</name>
			<uri>http://functionaljobs.com/</uri>
		</author>
		<source>
			<title type="html">Functional Jobs: Search 'clojure'</title>
			<link rel="self" href="http://functionaljobs.com/jobs/search/?q=clojure&amp;format=rss" />
			<id>urn:uuid:f0db074f-89a2-bec7-39fd-ebabe99e235d</id>
		</source>
	<feedburner:origLink>http://functionaljobs.com/jobs/108-senior-software-engineer-at-mediaplex</feedburner:origLink></entry>

</feed>

