<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Cognitive Consonance &#187; Programming</title>
	<atom:link href="http://tiago.org/cc/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://tiago.org/cc</link>
	<description>Software engineering in a computational biology environment</description>
	<lastBuildDate>Thu, 02 Feb 2012 13:12:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Python on 64-bit Windows</title>
		<link>http://tiago.org/cc/2011/08/02/python-on-64-bit-windows/</link>
		<comments>http://tiago.org/cc/2011/08/02/python-on-64-bit-windows/#comments</comments>
		<pubDate>Tue, 02 Aug 2011 14:25:59 +0000</pubDate>
		<dc:creator>tiago</dc:creator>
				<category><![CDATA[Bioinformatics]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Science]]></category>
		<category><![CDATA[64bit]]></category>
		<category><![CDATA[biopython]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://tiago.org/cc/?p=365</guid>
		<description><![CDATA[This is a post intended to help people trying to produce Python libraries and applications in 64-bit Windows (i.e. native 64-bit binaries, not just 32-bit applications running on 64-bit Windows). It reflects what I have learned when trying to compile and run Biopython. Corrections and comments are most welcome. Nothing here written is &#8220;rocket science&#8221;, [...]]]></description>
			<content:encoded><![CDATA[<p>This is a post intended to help people trying to produce Python libraries and applications in 64-bit Windows (i.e. native 64-bit binaries, not just 32-bit applications running on 64-bit Windows). It reflects what I have learned when trying to compile and run Biopython. Corrections and comments are <strong>most welcome</strong>. Nothing here written is &#8220;rocket science&#8221;, but it took me quite a while to compile this information, therefore it might make your life easier also.</p>
<p>Self-imposed requirement: To be able to compile with free compilers (preferably free as in speech, but free as in beer will do).</p>
<p>Point 1: Python does not compile with the free 64-bit compiler, <a href="http://mingw-w64.sourceforge.net/" title="mingw-w64" target="_blank">mingw-w64</a>. I actually did not try this, but I tried to compile biopython with mingw-w64 and Python headers were problematic (plus, if you go to Python bug database you will find references there to not being able to use mingw-w64).</p>
<p>Point 2: Visual Studio Express (the free beer compiler from Microsoft) does not natively target 64-bit architectures. Fear not, if you download <a href="http://msdn.microsoft.com/en-us/windows/bb980924" target="_blank">the Windows SDK</a>, then you get a 64-bit compiler. As far I as can see, this is the best current solution. The <b>easiest way to compile</b> (at least from the command line) is by using the Windows SDK Command Prompt (available in the Microsoft Windows SDK menu). Have a look at setenv (setenv.cmd) which allows you to set quite a few things about the target architecture. I am using VS2010 Express. In theory distutils only supports up to 2008 (v9), but I had no problems other than to add a /MANIFEST flag to the linker.</p>
<p>Point 3: If the code you are compiling depends on external libraries, then you mileage might vary (a lot), there are 4 options: (i) either the dependencies already have 64-bit versions (like NumPy which I needed for Biopython); (ii) There are no 64-bit versions, but it is easy for you to compile; (iii) There are no 64-bit versions and it is complex work to generate one. If it is case 3, then, well, case lost, back to the 32-bit version. You might have noticed that I mention FOUR options, well (iv) the fantastic porting effort done by Christoph Gohlke, if you need any Python 64-bit library check <a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/">his porting page</a> with truckloads of stuff (Compiled using Visual Studio professional editions).</p>
<p>So: Use VS Express and add the MS Windows SDK. setenv is your friend (and the Windows SDK command prompt, which is cmd with setenv, really).</p>
<p>As a final note, while I do grok pragmatism, I find less than desirable (to be euphemistic) that Python does not support the existing FREE (as in speech) 64-bit compiler on Windows.</p>
<div class='sociable'><div><span class='sociable-tagline'>Share and Enjoy:</span></div><ul><li><a rel="nofollow"   href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2011%2F08%2F02%2Fpython-on-64-bit-windows%2F&amp;title=Python%20on%2064-bit%20Windows&amp;bodytext=This%20is%20a%20post%20intended%20to%20help%20people%20trying%20to%20produce%20Python%20libraries%20and%20applications%20in%2064-bit%20Windows%20%28i.e.%20native%2064-bit%20binaries%2C%20not%20just%2032-bit%20applications%20running%20on%2064-bit%20Windows%29.%20It%20reflects%20what%20I%20have%20learned%20when%20trying%20to%20compile" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/digg.png" class="sociable-img sociable-hovers" title="Digg" alt="Digg" /></a></li><li><a rel="nofollow"   href="http://delicious.com/post?url=http%3A%2F%2Ftiago.org%2Fcc%2F2011%2F08%2F02%2Fpython-on-64-bit-windows%2F&amp;title=Python%20on%2064-bit%20Windows&amp;notes=This%20is%20a%20post%20intended%20to%20help%20people%20trying%20to%20produce%20Python%20libraries%20and%20applications%20in%2064-bit%20Windows%20%28i.e.%20native%2064-bit%20binaries%2C%20not%20just%2032-bit%20applications%20running%20on%2064-bit%20Windows%29.%20It%20reflects%20what%20I%20have%20learned%20when%20trying%20to%20compile" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/delicious.png" class="sociable-img sociable-hovers" title="del.icio.us" alt="del.icio.us" /></a></li><li><a rel="nofollow"   href="http://www.facebook.com/share.php?u=http%3A%2F%2Ftiago.org%2Fcc%2F2011%2F08%2F02%2Fpython-on-64-bit-windows%2F&amp;t=Python%20on%2064-bit%20Windows" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/facebook.png" class="sociable-img sociable-hovers" title="Facebook" alt="Facebook" /></a></li><li><a rel="nofollow"   href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Ftiago.org%2Fcc%2F2011%2F08%2F02%2Fpython-on-64-bit-windows%2F&amp;title=Python%20on%2064-bit%20Windows&amp;annotation=This%20is%20a%20post%20intended%20to%20help%20people%20trying%20to%20produce%20Python%20libraries%20and%20applications%20in%2064-bit%20Windows%20%28i.e.%20native%2064-bit%20binaries%2C%20not%20just%2032-bit%20applications%20running%20on%2064-bit%20Windows%29.%20It%20reflects%20what%20I%20have%20learned%20when%20trying%20to%20compile" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/googlebookmark.png" class="sociable-img sociable-hovers" title="Google Bookmarks" alt="Google Bookmarks" /></a></li><li><a rel="nofollow"   href="http://www.dzone.com/links/add.html?url=http%3A%2F%2Ftiago.org%2Fcc%2F2011%2F08%2F02%2Fpython-on-64-bit-windows%2F&amp;title=Python%20on%2064-bit%20Windows" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/dzone.png" class="sociable-img sociable-hovers" title="DZone" alt="DZone" /></a></li><li><a rel="nofollow"   href="http://reddit.com/submit?url=http%3A%2F%2Ftiago.org%2Fcc%2F2011%2F08%2F02%2Fpython-on-64-bit-windows%2F&amp;title=Python%20on%2064-bit%20Windows" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/reddit.png" class="sociable-img sociable-hovers" title="Reddit" alt="Reddit" /></a></li><li><a rel="nofollow"   href="http://technorati.com/faves?add=http%3A%2F%2Ftiago.org%2Fcc%2F2011%2F08%2F02%2Fpython-on-64-bit-windows%2F" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/technorati.png" class="sociable-img sociable-hovers" title="Technorati" alt="Technorati" /></a></li><li><a rel="nofollow"   href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2011%2F08%2F02%2Fpython-on-64-bit-windows%2F&amp;title=Python%20on%2064-bit%20Windows&amp;source=Cognitive+Consonance+Software+engineering+in+a+computational+biology+environment&amp;summary=This%20is%20a%20post%20intended%20to%20help%20people%20trying%20to%20produce%20Python%20libraries%20and%20applications%20in%2064-bit%20Windows%20%28i.e.%20native%2064-bit%20binaries%2C%20not%20just%2032-bit%20applications%20running%20on%2064-bit%20Windows%29.%20It%20reflects%20what%20I%20have%20learned%20when%20trying%20to%20compile" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/linkedin.png" class="sociable-img sociable-hovers" title="LinkedIn" alt="LinkedIn" /></a></li><li><a rel="nofollow"   href="http://www.connotea.org/addpopup?continue=confirm&amp;uri=http%3A%2F%2Ftiago.org%2Fcc%2F2011%2F08%2F02%2Fpython-on-64-bit-windows%2F&amp;title=Python%20on%2064-bit%20Windows&amp;description=This%20is%20a%20post%20intended%20to%20help%20people%20trying%20to%20produce%20Python%20libraries%20and%20applications%20in%2064-bit%20Windows%20%28i.e.%20native%2064-bit%20binaries%2C%20not%20just%2032-bit%20applications%20running%20on%2064-bit%20Windows%29.%20It%20reflects%20what%20I%20have%20learned%20when%20trying%20to%20compile" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/connotea.png" class="sociable-img sociable-hovers" title="connotea" alt="connotea" /></a></li><li><a rel="nofollow"   href="http://www.friendfeed.com/share?title=Python%20on%2064-bit%20Windows&amp;link=http%3A%2F%2Ftiago.org%2Fcc%2F2011%2F08%2F02%2Fpython-on-64-bit-windows%2F" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/friendfeed.png" class="sociable-img sociable-hovers" title="FriendFeed" alt="FriendFeed" /></a></li><li><a rel="nofollow"   href="http://twitter.com/home?status=Python%20on%2064-bit%20Windows%20-%20http%3A%2F%2Ftiago.org%2Fcc%2F2011%2F08%2F02%2Fpython-on-64-bit-windows%2F" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/twitter.png" class="sociable-img sociable-hovers" title="Twitter" alt="Twitter" /></a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://tiago.org/cc/2011/08/02/python-on-64-bit-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Music DSL with Groovy: enter AST Transformations (1/2)</title>
		<link>http://tiago.org/cc/2011/04/17/music-dsl-with-groovy-enter-ast-transformations-12/</link>
		<comments>http://tiago.org/cc/2011/04/17/music-dsl-with-groovy-enter-ast-transformations-12/#comments</comments>
		<pubDate>Sun, 17 Apr 2011 23:23:40 +0000</pubDate>
		<dc:creator>tiago</dc:creator>
				<category><![CDATA[Languages]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[DSL]]></category>
		<category><![CDATA[groovy]]></category>

		<guid isPermaLink="false">http://tiago.org/cc/?p=277</guid>
		<description><![CDATA[Lets continue the development agile DSL for music notation with Groovy. If you remember our fundamental concepts are Scores, Parts (for instruments), Phrases and Notes. At a certain time we are typically working only on a Score, Part and Phrase (indeed we might work only on a single Score during a session). So, we would [...]]]></description>
			<content:encoded><![CDATA[<p>Lets continue the development agile DSL for music notation with Groovy. If you remember our fundamental concepts are Scores, Parts (for instruments), Phrases and Notes.</p>
<p>At a certain time we are typically working only on a Score, Part and Phrase (indeed we might work only on a single Score during a session). So, we would like to have a concept of default Score, Part and Phrase, and avoid referring to it (unless of, course, we want to change the default). For instance, instead of writing:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;">...
<span style="color: #006600;">myScore</span> <span style="color: #66cc66;">=</span> score<span style="color: #66cc66;">&#40;</span>name:<span style="color: #ff0000;">&quot;Row Your Boat&quot;</span><span style="color: #66cc66;">&#41;</span>
myPart <span style="color: #66cc66;">=</span> part<span style="color: #66cc66;">&#40;</span>title: <span style="color: #ff0000;">&quot;Flute&quot;</span>, instrument: FLUTE, channel: <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>
myPhrase <span style="color: #66cc66;">=</span> phrase<span style="color: #66cc66;">&#40;</span>startTime: <span style="color: #cc66cc;">0.0</span><span style="color: #66cc66;">&#41;</span>
myPhrase.<span style="color: #006600;">addNoteList</span> pitchArray, rhythmArray</pre></div></div>

<p>(pitchArray and rhythmArray are pre-defined before)<br />
We want to write, the much simpler</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="groovy" style="font-family:monospace;">...
<span style="color: #006600;">score</span><span style="color: #66cc66;">&#40;</span>name:<span style="color: #ff0000;">&quot;Row Your Boat&quot;</span><span style="color: #66cc66;">&#41;</span>
part<span style="color: #66cc66;">&#40;</span>title: <span style="color: #ff0000;">&quot;Flute&quot;</span>, instrument: FLUTE, channel: <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>
phrase<span style="color: #66cc66;">&#40;</span>startTime: <span style="color: #cc66cc;">0.0</span><span style="color: #66cc66;">&#41;</span>
addNoteList pitchArray, rhythmArray</pre></td></tr></table></div>

<p>All Score, Part and Phrase methods will implicitly refer to myScore, myPart and myPhrase. Note that you can still explicitly refer to them. Indeed this will be necessary has most scores.</p>
<p>In this first instalment (of 2) we will not deal with line 5 above. Part 1 is actually the bulk of the work. Breath deeply has this will be the tough part.</p>
<p>We will use Groovy ASTTransformations for this. The Groovy compiler allows us to attach code to it while it is working. We can manipulate the AST (Abstract Syntax Tree) of our code during most of the compilation stages. This means that we will need a <b>separate program</b> to attach to the compiler. So, if we step back we now have 3 artifacts:</p>
<ol>
<li>The code to do the AST transformation (called during compilation)</li>
<li>The core DSL implementation (with all the other stuff except AST transforms)</li>
<li>Your music scripts with your score</li>
</ol>
<p>So we need kind of a sub-project to handle this as Groovy requires a separate jar with the AST transformation code. This separate jar will have to have a descriptor file in the META-INF/services directory called </p>
<p>org.codehaus.groovy.transform.ASTTransformation</p>
<p>That is the name of the file (big one eh?). Inside it should have only one line: the fully qualified name for the class implementing the transformation (SimpleTransformation in our case).</p>
<p>OK, now we need to develop SimpleTransformation. This is not a trivial bit of code, I will splash it here and the it line by line (only dealing with Scores &#8211; Parts and Phrases are similar):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="groovy" style="font-family:monospace;">@GroovyASTTransformation<span style="color: #66cc66;">&#40;</span>phase<span style="color: #66cc66;">=</span>CompilePhase.<span style="color: #006600;">CONVERSION</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SimpleTransformation <span style="color: #000000; font-weight: bold;">implements</span> ASTTransformation <span style="color: #66cc66;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> visit<span style="color: #66cc66;">&#40;</span>ASTNode<span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> astNodes, SourceUnit sourceUnit<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    BlockStatement sblock <span style="color: #66cc66;">=</span> sourceUnit.<span style="color: #006600;">getAST</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">?</span>.<span style="color: #006600;">getStatementBlock</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #aaaadd; font-weight: bold;">List</span> stmts <span style="color: #66cc66;">=</span> sblock.<span style="color: #006600;">getStatements</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #993333;">int</span> numStmts <span style="color: #66cc66;">=</span> stmts.<span style="color: #663399;">size</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> i<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">;</span>i <span style="color: #66cc66;">&lt;</span> numStmts <span style="color: #66cc66;">;</span>i <span style="color: #66cc66;">++</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">Class</span> cls <span style="color: #66cc66;">=</span> stmts.<span style="color: #663399;">get</span><span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getClass</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>cls <span style="color: #66cc66;">==</span> ExpressionStatement<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> 
        Expression es <span style="color: #66cc66;">=</span> stmts.<span style="color: #663399;">get</span><span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">expression</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>es.<span style="color: #006600;">getClass</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">==</span> MethodCallExpression<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
          <span style="color: #aaaadd; font-weight: bold;">String</span> method <span style="color: #66cc66;">=</span> es.<span style="color: #006600;">method</span>.<span style="color: #006600;">text</span>
          <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>method.<span style="color: #006600;">equals</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;score&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
              Expression e <span style="color: #66cc66;">=</span> transformBinary<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;myScore&quot;</span>, es<span style="color: #66cc66;">&#41;</span>
              stmts<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">setExpression</span><span style="color: #66cc66;">&#40;</span>e<span style="color: #66cc66;">&#41;</span>
          <span style="color: #66cc66;">&#125;</span>
        <span style="color: #66cc66;">&#125;</span>
      <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
  <span style="color: #66cc66;">&#125;</span>
...</pre></td></tr></table></div>

<p>So</p>
<ul>
<li>Lines 1-4 &#8211; Boilerplate of our class so that the Groovy compiler uses this. There is one important part here: the <a href="http://groovy.codehaus.org/Compiler+Phase+Guide">phase</a> where the code will attach. For now I am attaching to the conversion phase. But this might change in the future (I would like to do some type analysis, but I do not even think that that is possible with Groovy. If it is possible, than analysis would have to be done at a later phase).</li>
<li>5-6 &#8211; We get the statements of the script that we are compiling</li>
<li>7 &#8211; Here we iterate through all statements. Note the for and not an each/closure. I do this because I might want to change the statement list (like adding stuff at the end &#8211; prints). That is not so easy with each/closures
</li>
<li>10 &#8211; We get all expressions. This means we ignore fors, ifs, switches, function definitions, &#8230; We are not going deep, just changing methods at the top level of the code.</li>
<li>13-17 &#8211; If it is a Method Call, and it method name is called score then we apply our transformation (16) and replace the expression (line 17)</li>
</ul>
<p>Our transformation is:</p>
</pre>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;">BinaryExpression transformBinary<span style="color: #66cc66;">&#40;</span><span style="color: #aaaadd; font-weight: bold;">String</span> var, Expression expression<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    BinaryExpression newExp <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> BinaryExpression<span style="color: #66cc66;">&#40;</span>
      <span style="color: #000000; font-weight: bold;">new</span> VariableExpression<span style="color: #66cc66;">&#40;</span>var<span style="color: #66cc66;">&#41;</span>,<span style="color: #000000; font-weight: bold;">new</span> Token <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">100</span>, <span style="color: #ff0000;">&quot;=&quot;</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>, expression<span style="color: #66cc66;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">return</span> newExp
  <span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>OK, here the bulk of the work is done: We create a new BinaryExpression composed of a Variable (called myScore in our case - as per the code above), a Token and then we attach the old expression, as is. So score(name:"Row Your Boat") becomes myScore=score(name:"Row Your Boat").</p>
<p>Now, a confession. The 100 in the Token was a reverse engineering of an expression. I do not know where the table of options for token types is (If you know, please tell).</p>
<p>You will need a few imports to do the above, by the way</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #a1a100;">org.codehaus.groovy.ast.*</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #a1a100;">org.codehaus.groovy.ast.expr.*</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #a1a100;">org.codehaus.groovy.ast.stmt.*</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #a1a100;">org.codehaus.groovy.control.*</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #a1a100;">org.codehaus.groovy.syntax.Token</span>
<span style="color: #000000; font-weight: bold;">import</span> org.<span style="color: #006600;">codehaus</span>.<span style="color: #006600;">groovy</span>.<span style="color: #006600;">transform</span>.<span style="color: #66cc66;">*</span></pre></div></div>

<p>With all this you now create a jar that will have to be on the classpath of the Groovy compiler. So, this code will be used by the Groovy compiler to manipulate the AST.</p>
<p>Note that this code is pretty basic: It will not recurse through for/switch statements, will not go in closures, functions, etc. It will also only look at the first token in a method call expression. I will deal with this in time (not in the second part of this article). For now it is good for illustrative purposes and good for my personal needs.</p>
<p>Some final notes...</p>
<p>You can inspect an AST from groovyConsole (helps a lot), here is an example for sc=score(name:"Row Your Boat"):</p>
<div id="attachment_298" class="wp-caption aligncenter" style="width: 962px"><a href="http://tiago.org/cc/wp-content/uploads/2011/04/ast.png"><img src="http://tiago.org/cc/wp-content/uploads/2011/04/ast.png" alt="" title="AST viewing with groovyConsole" width="952" height="474" class="size-full wp-image-298" /></a><p class="wp-caption-text">AST viewing with groovyConsole</p></div>
<p>Another point if that these kind of transformations are a bit heavy in the theory and heavy in the approach. For instance, it was difficult, in netbeans to setup a project architecture that would allow easy build (an agile cycle of develop/build/test). This is of course because part of the code has to be hooked to the compiler and IDEs are not normally used to do that. It is a bit like compiling part of the compiler before going to the actual code. Well, I finally switched to emacs+gradle. Any excuse to stop using Oracle software (which netbeans nowadays is) is fair game for me.</p>
<p>In the second instalment we will trap method calls like addNoteList so that addNoteList listOfNotes becomes myPhrase.addNoteList listofNotes (like line 5 on the initial example above). In this case we will use some introspection to determine the method names of Score, Part and Phrase. The second part will be cooler as the bulk of the boilerplate work was done here.</p>
<p>You can find the <a href="https://launchpad.net/mousai">code in launchpad</a>. Note that this is still in early stages.</p>
<p>Comments and improvements will be most appreciated!</p>
<div class='sociable'><div><span class='sociable-tagline'>Share and Enjoy:</span></div><ul><li><a rel="nofollow"   href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2011%2F04%2F17%2Fmusic-dsl-with-groovy-enter-ast-transformations-12%2F&amp;title=Music%20DSL%20with%20Groovy%3A%20enter%20AST%20Transformations%20%281%2F2%29&amp;bodytext=Lets%20continue%20the%20development%20agile%20DSL%20for%20music%20notation%20with%20Groovy.%20If%20you%20remember%20our%20fundamental%20concepts%20are%20Scores%2C%20Parts%20%28for%20instruments%29%2C%20Phrases%20and%20Notes.%0D%0A%0D%0AAt%20a%20certain%20time%20we%20are%20typically%20working%20only%20on%20a%20Score%2C%20Part%20and%20Phrase%20%28i" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/digg.png" class="sociable-img sociable-hovers" title="Digg" alt="Digg" /></a></li><li><a rel="nofollow"   href="http://delicious.com/post?url=http%3A%2F%2Ftiago.org%2Fcc%2F2011%2F04%2F17%2Fmusic-dsl-with-groovy-enter-ast-transformations-12%2F&amp;title=Music%20DSL%20with%20Groovy%3A%20enter%20AST%20Transformations%20%281%2F2%29&amp;notes=Lets%20continue%20the%20development%20agile%20DSL%20for%20music%20notation%20with%20Groovy.%20If%20you%20remember%20our%20fundamental%20concepts%20are%20Scores%2C%20Parts%20%28for%20instruments%29%2C%20Phrases%20and%20Notes.%0D%0A%0D%0AAt%20a%20certain%20time%20we%20are%20typically%20working%20only%20on%20a%20Score%2C%20Part%20and%20Phrase%20%28i" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/delicious.png" class="sociable-img sociable-hovers" title="del.icio.us" alt="del.icio.us" /></a></li><li><a rel="nofollow"   href="http://www.facebook.com/share.php?u=http%3A%2F%2Ftiago.org%2Fcc%2F2011%2F04%2F17%2Fmusic-dsl-with-groovy-enter-ast-transformations-12%2F&amp;t=Music%20DSL%20with%20Groovy%3A%20enter%20AST%20Transformations%20%281%2F2%29" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/facebook.png" class="sociable-img sociable-hovers" title="Facebook" alt="Facebook" /></a></li><li><a rel="nofollow"   href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Ftiago.org%2Fcc%2F2011%2F04%2F17%2Fmusic-dsl-with-groovy-enter-ast-transformations-12%2F&amp;title=Music%20DSL%20with%20Groovy%3A%20enter%20AST%20Transformations%20%281%2F2%29&amp;annotation=Lets%20continue%20the%20development%20agile%20DSL%20for%20music%20notation%20with%20Groovy.%20If%20you%20remember%20our%20fundamental%20concepts%20are%20Scores%2C%20Parts%20%28for%20instruments%29%2C%20Phrases%20and%20Notes.%0D%0A%0D%0AAt%20a%20certain%20time%20we%20are%20typically%20working%20only%20on%20a%20Score%2C%20Part%20and%20Phrase%20%28i" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/googlebookmark.png" class="sociable-img sociable-hovers" title="Google Bookmarks" alt="Google Bookmarks" /></a></li><li><a rel="nofollow"   href="http://www.dzone.com/links/add.html?url=http%3A%2F%2Ftiago.org%2Fcc%2F2011%2F04%2F17%2Fmusic-dsl-with-groovy-enter-ast-transformations-12%2F&amp;title=Music%20DSL%20with%20Groovy%3A%20enter%20AST%20Transformations%20%281%2F2%29" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/dzone.png" class="sociable-img sociable-hovers" title="DZone" alt="DZone" /></a></li><li><a rel="nofollow"   href="http://reddit.com/submit?url=http%3A%2F%2Ftiago.org%2Fcc%2F2011%2F04%2F17%2Fmusic-dsl-with-groovy-enter-ast-transformations-12%2F&amp;title=Music%20DSL%20with%20Groovy%3A%20enter%20AST%20Transformations%20%281%2F2%29" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/reddit.png" class="sociable-img sociable-hovers" title="Reddit" alt="Reddit" /></a></li><li><a rel="nofollow"   href="http://technorati.com/faves?add=http%3A%2F%2Ftiago.org%2Fcc%2F2011%2F04%2F17%2Fmusic-dsl-with-groovy-enter-ast-transformations-12%2F" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/technorati.png" class="sociable-img sociable-hovers" title="Technorati" alt="Technorati" /></a></li><li><a rel="nofollow"   href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2011%2F04%2F17%2Fmusic-dsl-with-groovy-enter-ast-transformations-12%2F&amp;title=Music%20DSL%20with%20Groovy%3A%20enter%20AST%20Transformations%20%281%2F2%29&amp;source=Cognitive+Consonance+Software+engineering+in+a+computational+biology+environment&amp;summary=Lets%20continue%20the%20development%20agile%20DSL%20for%20music%20notation%20with%20Groovy.%20If%20you%20remember%20our%20fundamental%20concepts%20are%20Scores%2C%20Parts%20%28for%20instruments%29%2C%20Phrases%20and%20Notes.%0D%0A%0D%0AAt%20a%20certain%20time%20we%20are%20typically%20working%20only%20on%20a%20Score%2C%20Part%20and%20Phrase%20%28i" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/linkedin.png" class="sociable-img sociable-hovers" title="LinkedIn" alt="LinkedIn" /></a></li><li><a rel="nofollow"   href="http://www.connotea.org/addpopup?continue=confirm&amp;uri=http%3A%2F%2Ftiago.org%2Fcc%2F2011%2F04%2F17%2Fmusic-dsl-with-groovy-enter-ast-transformations-12%2F&amp;title=Music%20DSL%20with%20Groovy%3A%20enter%20AST%20Transformations%20%281%2F2%29&amp;description=Lets%20continue%20the%20development%20agile%20DSL%20for%20music%20notation%20with%20Groovy.%20If%20you%20remember%20our%20fundamental%20concepts%20are%20Scores%2C%20Parts%20%28for%20instruments%29%2C%20Phrases%20and%20Notes.%0D%0A%0D%0AAt%20a%20certain%20time%20we%20are%20typically%20working%20only%20on%20a%20Score%2C%20Part%20and%20Phrase%20%28i" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/connotea.png" class="sociable-img sociable-hovers" title="connotea" alt="connotea" /></a></li><li><a rel="nofollow"   href="http://www.friendfeed.com/share?title=Music%20DSL%20with%20Groovy%3A%20enter%20AST%20Transformations%20%281%2F2%29&amp;link=http%3A%2F%2Ftiago.org%2Fcc%2F2011%2F04%2F17%2Fmusic-dsl-with-groovy-enter-ast-transformations-12%2F" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/friendfeed.png" class="sociable-img sociable-hovers" title="FriendFeed" alt="FriendFeed" /></a></li><li><a rel="nofollow"   href="http://twitter.com/home?status=Music%20DSL%20with%20Groovy%3A%20enter%20AST%20Transformations%20%281%2F2%29%20-%20http%3A%2F%2Ftiago.org%2Fcc%2F2011%2F04%2F17%2Fmusic-dsl-with-groovy-enter-ast-transformations-12%2F" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/twitter.png" class="sociable-img sociable-hovers" title="Twitter" alt="Twitter" /></a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://tiago.org/cc/2011/04/17/music-dsl-with-groovy-enter-ast-transformations-12/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A phylogenetic tree viewer in clojure</title>
		<link>http://tiago.org/cc/2009/11/16/a-phylogenetic-tree-viewer-in-clojure/</link>
		<comments>http://tiago.org/cc/2009/11/16/a-phylogenetic-tree-viewer-in-clojure/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 19:44:11 +0000</pubDate>
		<dc:creator>tiago</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[clojure]]></category>
		<category><![CDATA[phylogenetics]]></category>

		<guid isPermaLink="false">http://tiago.org/cc/?p=160</guid>
		<description><![CDATA[Here is my first clojure application: A phylogenetic tree viewer (PhyloXML format). The obligatory screenshot: Preamble: This is newbie code: Handle with care! My main objective is not to make a tree viewer but a tree comparer. So this is no more than a learning step. You can test it yourself as it is a [...]]]></description>
			<content:encoded><![CDATA[<p>Here is my first clojure application: A phylogenetic tree viewer (PhyloXML format). The obligatory screenshot:</p>
<div id="attachment_172" class="wp-caption alignnone" style="width: 461px"><img src="http://tiago.org/cc/wp-content/uploads/2009/11/Screenshot-Simple.png" alt="Simple Phylogenetic viewer" title="Simple" width="451" height="480" class="size-full wp-image-172" /><p class="wp-caption-text">Simple Phylogenetic viewer</p></div>
<p>Preamble:</p>
<ol>
<li>This is newbie code: Handle with care! My main objective is not to make a tree viewer but a tree comparer. So this is no more than a learning step.</li>
<li>You can test it yourself as it is a Java WebStart application, just click <a href="http://popgen.eu/soft/tV/launch.jnlp">here</a>. You don&#8217;t need to have a phylogenetic tree file yourself. I supply an example inside.
         </li>
<li>This makes use of JGraph and Archaeopteryx (the PhyloXML parser)
</li>
</ol>
<p>I do maintain this code on github. I have <a href="http://github.com/tiagoantao/treeHugger">one project for the viewer</a> and <a href="http://github.com/tiagoantao/cljUtils">another for general utilities</a>. All the code is still very crude, but you might be interesting in stealing some of the <a href="http://github.com/tiagoantao/cljUtils/blob/master/src/org/tiago/swing.clj">swing code</a>, either as a crude example of how to interact with swing or taking my <a href="http://tiago.org/cc/2009/10/27/swing-menus-in-clojure/">micro-DSL for menus</a>. If you want to interact with JGraph, <a href="http://github.com/tiagoantao/cljUtils/blob/master/src/org/tiago/graph_vis.clj">this</a> might be a starting point. I don&#8217;t want, in any way, suggest that this code is any good. </p>
<p>Some lessons that I&#8217;ve learned and that I would like to share:</p>
<ol>
<li>Some of the clojure.contrib code is a bit green. I tried to use the graph library, but it is very small and specific. I ended up starting doing my own. Mine is even smaller and specific, no claims of generality.</li>
<li>I don&#8217;t appreciate some of the core functions of Clojure (I&#8217;ve written on this before and will write more in the near future). The great thing about Clojure is that you can import only what you want from the core and extend it yourself. I intend to do just that for my personal use. This is a PLUS point for Clojure: the flexibility that is made available to change many of the decisions of the language implementor (in the great tradition of declarative and homoiconic languages)
  </li>
<li>While I can change the core for my uses, I think defnk should really be core for everybody! I fact I wander if defn should not become defnk&#8230;</li>
<li>I am pretty sure that when *warn-on-reflection* is activated and action taken to correct the warnings, lots of code will increase in performance. With the more important side effect of annotating the code with type info.</li>
<li>I have quite a lot of recursive code that doesn&#8217;t use recur. Something to learn and master&#8230;</li>
<li>JGraph layout algorithms are not fantastic. I&#8217;ve tried with much bigger trees and the result was far from perfect (I also noticed performance problems in my own code).</li>
</ol>
<p>The biggest hurdle that I&#8217;ve found was the construction of user interfaces and how verbose Clojure Java interop can become. Of course one can create functions (and that was done) to create buttons, frames, menus, etc. But the creation of Java container structures (think frame contains menubar which contains menu with menus inside and so on) would benefit from a dialect where, when a certain (container) object was created it&#8217;s (Java) namespace would become easily available.</p>
<p>Imagine constructing a Structure like this:</p>
<pre>
MenuBar[
    Menu(File) [
        Menu(New)
        Menu(Close)
        Separator
        Menu
    ]
    Menu(Edit) [
        Menu(Cut)
        Menu(Paste)
    ]
]
</pre>
<p>it would be nice to be able to write something like:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>new JMenuBar<span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#40;</span>add <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>new JMenu <span style="color: #ff0000;">&quot;File&quot;</span><span style="color: #66cc66;">&#41;</span>
       <span style="color: #66cc66;">&#40;</span>add <span style="color: #66cc66;">&#40;</span>new JMenu <span style="color: #ff0000;">&quot;New&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
       <span style="color: #66cc66;">&#40;</span>add <span style="color: #66cc66;">&#40;</span>new JMenu <span style="color: #ff0000;">&quot;Close&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
       <span style="color: #66cc66;">&#40;</span>addSeparator<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#40;</span>add <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>new JMenu <span style="color: #ff0000;">&quot;Edit&quot;</span><span style="color: #66cc66;">&#41;</span>
       <span style="color: #66cc66;">&#40;</span>add <span style="color: #66cc66;">&#40;</span>new JMenu <span style="color: #ff0000;">&quot;Cut&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
       <span style="color: #66cc66;">&#40;</span>add <span style="color: #66cc66;">&#40;</span>new JMenu <span style="color: #ff0000;">&quot;Paste&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>&#8220;add&#8221; and &#8220;addSeparator&#8221; are Java methods. All this would be dynamic against the Java object hierarchy (not a hand-written library!). Note that there is no doto special form (or variants) and, most importantly, note that, given a list (a b c d), if a is a Java object b c d are evaluated as methods of a. If b is (i (y x s)), x and s would be evaluated as methods of y, if they failed then as methods of a, if this fails interpreted as normal Clojure. Something like this (rough sketch).<br />
This would be useful, e.g., to construct Swing hierarchies by hand in a expedient way (not suggesting anything more, especially not to do big programs with outside scope).<br />
I am going to try to write some code that does this in the next few days.</p>
<div class='sociable'><div><span class='sociable-tagline'>Share and Enjoy:</span></div><ul><li><a rel="nofollow"   href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F16%2Fa-phylogenetic-tree-viewer-in-clojure%2F&amp;title=A%20phylogenetic%20tree%20viewer%20in%20clojure&amp;bodytext=Here%20is%20my%20first%20clojure%20application%3A%20A%20phylogenetic%20tree%20viewer%20%28PhyloXML%20format%29.%20The%20obligatory%20screenshot%3A%0D%0A%0D%0A%0D%0A%0D%0APreamble%3A%0D%0A%0D%0A%0D%0A%09This%20is%20newbie%20code%3A%20Handle%20with%20care%21%20My%20main%20objective%20is%20not%20to%20make%20a%20tree%20viewer%20but%20a%20tree%20comparer.%20So%20this%20i" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/digg.png" class="sociable-img sociable-hovers" title="Digg" alt="Digg" /></a></li><li><a rel="nofollow"   href="http://delicious.com/post?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F16%2Fa-phylogenetic-tree-viewer-in-clojure%2F&amp;title=A%20phylogenetic%20tree%20viewer%20in%20clojure&amp;notes=Here%20is%20my%20first%20clojure%20application%3A%20A%20phylogenetic%20tree%20viewer%20%28PhyloXML%20format%29.%20The%20obligatory%20screenshot%3A%0D%0A%0D%0A%0D%0A%0D%0APreamble%3A%0D%0A%0D%0A%0D%0A%09This%20is%20newbie%20code%3A%20Handle%20with%20care%21%20My%20main%20objective%20is%20not%20to%20make%20a%20tree%20viewer%20but%20a%20tree%20comparer.%20So%20this%20i" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/delicious.png" class="sociable-img sociable-hovers" title="del.icio.us" alt="del.icio.us" /></a></li><li><a rel="nofollow"   href="http://www.facebook.com/share.php?u=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F16%2Fa-phylogenetic-tree-viewer-in-clojure%2F&amp;t=A%20phylogenetic%20tree%20viewer%20in%20clojure" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/facebook.png" class="sociable-img sociable-hovers" title="Facebook" alt="Facebook" /></a></li><li><a rel="nofollow"   href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F16%2Fa-phylogenetic-tree-viewer-in-clojure%2F&amp;title=A%20phylogenetic%20tree%20viewer%20in%20clojure&amp;annotation=Here%20is%20my%20first%20clojure%20application%3A%20A%20phylogenetic%20tree%20viewer%20%28PhyloXML%20format%29.%20The%20obligatory%20screenshot%3A%0D%0A%0D%0A%0D%0A%0D%0APreamble%3A%0D%0A%0D%0A%0D%0A%09This%20is%20newbie%20code%3A%20Handle%20with%20care%21%20My%20main%20objective%20is%20not%20to%20make%20a%20tree%20viewer%20but%20a%20tree%20comparer.%20So%20this%20i" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/googlebookmark.png" class="sociable-img sociable-hovers" title="Google Bookmarks" alt="Google Bookmarks" /></a></li><li><a rel="nofollow"   href="http://www.dzone.com/links/add.html?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F16%2Fa-phylogenetic-tree-viewer-in-clojure%2F&amp;title=A%20phylogenetic%20tree%20viewer%20in%20clojure" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/dzone.png" class="sociable-img sociable-hovers" title="DZone" alt="DZone" /></a></li><li><a rel="nofollow"   href="http://reddit.com/submit?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F16%2Fa-phylogenetic-tree-viewer-in-clojure%2F&amp;title=A%20phylogenetic%20tree%20viewer%20in%20clojure" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/reddit.png" class="sociable-img sociable-hovers" title="Reddit" alt="Reddit" /></a></li><li><a rel="nofollow"   href="http://technorati.com/faves?add=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F16%2Fa-phylogenetic-tree-viewer-in-clojure%2F" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/technorati.png" class="sociable-img sociable-hovers" title="Technorati" alt="Technorati" /></a></li><li><a rel="nofollow"   href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F16%2Fa-phylogenetic-tree-viewer-in-clojure%2F&amp;title=A%20phylogenetic%20tree%20viewer%20in%20clojure&amp;source=Cognitive+Consonance+Software+engineering+in+a+computational+biology+environment&amp;summary=Here%20is%20my%20first%20clojure%20application%3A%20A%20phylogenetic%20tree%20viewer%20%28PhyloXML%20format%29.%20The%20obligatory%20screenshot%3A%0D%0A%0D%0A%0D%0A%0D%0APreamble%3A%0D%0A%0D%0A%0D%0A%09This%20is%20newbie%20code%3A%20Handle%20with%20care%21%20My%20main%20objective%20is%20not%20to%20make%20a%20tree%20viewer%20but%20a%20tree%20comparer.%20So%20this%20i" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/linkedin.png" class="sociable-img sociable-hovers" title="LinkedIn" alt="LinkedIn" /></a></li><li><a rel="nofollow"   href="http://www.connotea.org/addpopup?continue=confirm&amp;uri=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F16%2Fa-phylogenetic-tree-viewer-in-clojure%2F&amp;title=A%20phylogenetic%20tree%20viewer%20in%20clojure&amp;description=Here%20is%20my%20first%20clojure%20application%3A%20A%20phylogenetic%20tree%20viewer%20%28PhyloXML%20format%29.%20The%20obligatory%20screenshot%3A%0D%0A%0D%0A%0D%0A%0D%0APreamble%3A%0D%0A%0D%0A%0D%0A%09This%20is%20newbie%20code%3A%20Handle%20with%20care%21%20My%20main%20objective%20is%20not%20to%20make%20a%20tree%20viewer%20but%20a%20tree%20comparer.%20So%20this%20i" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/connotea.png" class="sociable-img sociable-hovers" title="connotea" alt="connotea" /></a></li><li><a rel="nofollow"   href="http://www.friendfeed.com/share?title=A%20phylogenetic%20tree%20viewer%20in%20clojure&amp;link=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F16%2Fa-phylogenetic-tree-viewer-in-clojure%2F" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/friendfeed.png" class="sociable-img sociable-hovers" title="FriendFeed" alt="FriendFeed" /></a></li><li><a rel="nofollow"   href="http://twitter.com/home?status=A%20phylogenetic%20tree%20viewer%20in%20clojure%20-%20http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F16%2Fa-phylogenetic-tree-viewer-in-clojure%2F" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/twitter.png" class="sociable-img sociable-hovers" title="Twitter" alt="Twitter" /></a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://tiago.org/cc/2009/11/16/a-phylogenetic-tree-viewer-in-clojure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The 99 Prolog problems in Clojure</title>
		<link>http://tiago.org/cc/2009/11/11/the-99-prolog-problems-in-clojure/</link>
		<comments>http://tiago.org/cc/2009/11/11/the-99-prolog-problems-in-clojure/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 12:33:45 +0000</pubDate>
		<dc:creator>tiago</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[clojure]]></category>
		<category><![CDATA[prolog]]></category>

		<guid isPermaLink="false">http://tiago.org/cc/?p=167</guid>
		<description><![CDATA[Here can be found an interesting effort to implement the 99 Prolog problems in Clojure. It is not clear to me that the exercise is conducted in the same way as the original one [Update: the author actually says this in the preamble]. Let me explain: The original Prolog problems are solved without the help [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://m.3wa.com/?p=426">Here</a> can be found an interesting effort to implement the <a href="https://prof.ti.bfh.ch/hew1/informatik3/prolog/p-99/">99 Prolog problems</a> in Clojure.</p>
<p>It is not clear to me that the exercise is conducted in the same way as the original one [Update: the author actually says this in the preamble]. Let me explain:</p>
<p>The original Prolog problems are solved without the help of the (existing) Prolog libraries, just using the basic language mechanisms. They are a good at illustrating the underlying declarative power of Prolog.</p>
<p>For instance, problem 1, finding the last element of a list is solved with this in Prolog:</p>

<div class="wp_syntax"><div class="code"><pre class="prolog" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">% P01 (*): Find the last element of a list</span>
&nbsp;
<span style="color: #666666; font-style: italic;">% my_last(X,L) :- X is the last element of the list L</span>
<span style="color: #666666; font-style: italic;">%    (element,list) (?,?)</span>
&nbsp;
<span style="color: #666666; font-style: italic;">% Note: last(?Elem, ?List) is predefined</span>
&nbsp;
my_last<span style="color: #009900;">&#40;</span>X<span style="color: #339933;">,</span><span style="color: #009900;">&#91;</span>X<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>
my_last<span style="color: #009900;">&#40;</span>X<span style="color: #339933;">,</span><span style="color: #009900;">&#91;</span>_<span style="color: #339933;">|</span>L<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:-</span> my_last<span style="color: #009900;">&#40;</span>X<span style="color: #339933;">,</span>L<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span></pre></div></div>

<p>Notice the in-code comment that &#8220;last is predefined&#8221;. In fact, using the Prolog library this could be done with a one liner:</p>

<div class="wp_syntax"><div class="code"><pre class="prolog" style="font-family:monospace;"><span style="color: #339933;">?-</span> last<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #800080;">1</span><span style="color: #339933;">,</span><span style="color: #800080;">2</span><span style="color: #339933;">,</span><span style="color: #800080;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>E<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>
E <span style="color: #339933;">=</span> <span style="color: #800080;">3</span><span style="color: #339933;">.</span></pre></div></div>

<p>The offered solution in Clojure is also a one liner:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;">user<span style="color: #66cc66;">=&gt;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">last</span> <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span> <span style="color: #cc66cc;">1</span> <span style="color: #cc66cc;">2</span> <span style="color: #cc66cc;">3</span> <span style="color: #cc66cc;">5</span> <span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #cc66cc;">8</span></pre></div></div>

<p>Given a sufficiently large and clever library (and Clojure has a very nice library) all problems on the list could be solved with a one-liner.</p>
<p>In my opinion, an apples-to-apples comparison with the original solutions would not use the core library.<br />
It would probably be like this for the same problem:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>defn mylast <span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">l</span><span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#91;</span>mynext <span style="color: #66cc66;">&#40;</span>next <span style="color: #b1b100;">l</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">nil</span>? mynext<span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>first <span style="color: #b1b100;">l</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>mylast mynext<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Yep, next is in the core library also, but being a call to clojure.lang.RT, I think it is fair game to use it.</p>
<p>Ok, better yet, with recur, as it is on core (this is essentially a copy of the core version):</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>defn mylast <span style="color: #66cc66;">&#91;</span>s<span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>next s<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>recur <span style="color: #66cc66;">&#40;</span>next s<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>first s<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>The Prolog exercise exposes the declarativeness and expressive power of Prolog. The Clojure example exposes mostly the cleverness of the core library.</p>
<p>Both are interesting points of view (I am not criticizing the Clojure solution), but they cannot be used for comparison purposes.</p>
<div class='sociable'><div><span class='sociable-tagline'>Share and Enjoy:</span></div><ul><li><a rel="nofollow"   href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F11%2Fthe-99-prolog-problems-in-clojure%2F&amp;title=The%2099%20Prolog%20problems%20in%20Clojure&amp;bodytext=Here%20can%20be%20found%20an%20interesting%20effort%20to%20implement%20the%2099%20Prolog%20problems%20in%20Clojure.%0D%0A%0D%0AIt%20is%20not%20clear%20to%20me%20that%20the%20exercise%20is%20conducted%20in%20the%20same%20way%20as%20the%20original%20one%20%5BUpdate%3A%20the%20author%20actually%20says%20this%20in%20the%20preamble%5D.%20Let%20me%20explai" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/digg.png" class="sociable-img sociable-hovers" title="Digg" alt="Digg" /></a></li><li><a rel="nofollow"   href="http://delicious.com/post?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F11%2Fthe-99-prolog-problems-in-clojure%2F&amp;title=The%2099%20Prolog%20problems%20in%20Clojure&amp;notes=Here%20can%20be%20found%20an%20interesting%20effort%20to%20implement%20the%2099%20Prolog%20problems%20in%20Clojure.%0D%0A%0D%0AIt%20is%20not%20clear%20to%20me%20that%20the%20exercise%20is%20conducted%20in%20the%20same%20way%20as%20the%20original%20one%20%5BUpdate%3A%20the%20author%20actually%20says%20this%20in%20the%20preamble%5D.%20Let%20me%20explai" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/delicious.png" class="sociable-img sociable-hovers" title="del.icio.us" alt="del.icio.us" /></a></li><li><a rel="nofollow"   href="http://www.facebook.com/share.php?u=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F11%2Fthe-99-prolog-problems-in-clojure%2F&amp;t=The%2099%20Prolog%20problems%20in%20Clojure" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/facebook.png" class="sociable-img sociable-hovers" title="Facebook" alt="Facebook" /></a></li><li><a rel="nofollow"   href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F11%2Fthe-99-prolog-problems-in-clojure%2F&amp;title=The%2099%20Prolog%20problems%20in%20Clojure&amp;annotation=Here%20can%20be%20found%20an%20interesting%20effort%20to%20implement%20the%2099%20Prolog%20problems%20in%20Clojure.%0D%0A%0D%0AIt%20is%20not%20clear%20to%20me%20that%20the%20exercise%20is%20conducted%20in%20the%20same%20way%20as%20the%20original%20one%20%5BUpdate%3A%20the%20author%20actually%20says%20this%20in%20the%20preamble%5D.%20Let%20me%20explai" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/googlebookmark.png" class="sociable-img sociable-hovers" title="Google Bookmarks" alt="Google Bookmarks" /></a></li><li><a rel="nofollow"   href="http://www.dzone.com/links/add.html?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F11%2Fthe-99-prolog-problems-in-clojure%2F&amp;title=The%2099%20Prolog%20problems%20in%20Clojure" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/dzone.png" class="sociable-img sociable-hovers" title="DZone" alt="DZone" /></a></li><li><a rel="nofollow"   href="http://reddit.com/submit?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F11%2Fthe-99-prolog-problems-in-clojure%2F&amp;title=The%2099%20Prolog%20problems%20in%20Clojure" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/reddit.png" class="sociable-img sociable-hovers" title="Reddit" alt="Reddit" /></a></li><li><a rel="nofollow"   href="http://technorati.com/faves?add=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F11%2Fthe-99-prolog-problems-in-clojure%2F" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/technorati.png" class="sociable-img sociable-hovers" title="Technorati" alt="Technorati" /></a></li><li><a rel="nofollow"   href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F11%2Fthe-99-prolog-problems-in-clojure%2F&amp;title=The%2099%20Prolog%20problems%20in%20Clojure&amp;source=Cognitive+Consonance+Software+engineering+in+a+computational+biology+environment&amp;summary=Here%20can%20be%20found%20an%20interesting%20effort%20to%20implement%20the%2099%20Prolog%20problems%20in%20Clojure.%0D%0A%0D%0AIt%20is%20not%20clear%20to%20me%20that%20the%20exercise%20is%20conducted%20in%20the%20same%20way%20as%20the%20original%20one%20%5BUpdate%3A%20the%20author%20actually%20says%20this%20in%20the%20preamble%5D.%20Let%20me%20explai" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/linkedin.png" class="sociable-img sociable-hovers" title="LinkedIn" alt="LinkedIn" /></a></li><li><a rel="nofollow"   href="http://www.connotea.org/addpopup?continue=confirm&amp;uri=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F11%2Fthe-99-prolog-problems-in-clojure%2F&amp;title=The%2099%20Prolog%20problems%20in%20Clojure&amp;description=Here%20can%20be%20found%20an%20interesting%20effort%20to%20implement%20the%2099%20Prolog%20problems%20in%20Clojure.%0D%0A%0D%0AIt%20is%20not%20clear%20to%20me%20that%20the%20exercise%20is%20conducted%20in%20the%20same%20way%20as%20the%20original%20one%20%5BUpdate%3A%20the%20author%20actually%20says%20this%20in%20the%20preamble%5D.%20Let%20me%20explai" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/connotea.png" class="sociable-img sociable-hovers" title="connotea" alt="connotea" /></a></li><li><a rel="nofollow"   href="http://www.friendfeed.com/share?title=The%2099%20Prolog%20problems%20in%20Clojure&amp;link=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F11%2Fthe-99-prolog-problems-in-clojure%2F" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/friendfeed.png" class="sociable-img sociable-hovers" title="FriendFeed" alt="FriendFeed" /></a></li><li><a rel="nofollow"   href="http://twitter.com/home?status=The%2099%20Prolog%20problems%20in%20Clojure%20-%20http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F11%2Fthe-99-prolog-problems-in-clojure%2F" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/twitter.png" class="sociable-img sociable-hovers" title="Twitter" alt="Twitter" /></a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://tiago.org/cc/2009/11/11/the-99-prolog-problems-in-clojure/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Concurrency and multicore CPU/GPUs are overhyped</title>
		<link>http://tiago.org/cc/2009/11/02/concurrency-and-multicore-cpugpus-are-overhyped/</link>
		<comments>http://tiago.org/cc/2009/11/02/concurrency-and-multicore-cpugpus-are-overhyped/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 14:07:47 +0000</pubDate>
		<dc:creator>tiago</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[clojure]]></category>
		<category><![CDATA[concurrrent programming]]></category>
		<category><![CDATA[multicore]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://tiago.org/cc/?p=130</guid>
		<description><![CDATA[More than 10 years ago I participated in the development of an University IT system (the front- and backend to maintain grades and that sort of stuff). The system was based on a DB/2 backend (a very nice database system) with the business code stored on a Prolog interpreter (Prolog interpreter which was in-house developed) [...]]]></description>
			<content:encoded><![CDATA[<p>More than 10 years ago I participated in the development of an University IT system (the front- and backend to maintain grades and that sort of stuff). The system was based on a DB/2 backend (a very nice database system) with the business code stored on a Prolog interpreter (Prolog interpreter which was in-house developed) and the web backend being a Java servlet engine (the old JServ, the thingy pre-Tomcat from Apache). Prolog is famed to be slow, and Java (at that point in time) was very slow. Surprise, surprise&#8230; the bottleneck was on the DB/2 server. Eventually, as the system grow (and the database hardware was beefed up) the bottleneck come forward to the business and web tiers, but the problem was sorted by just adding more machines: The contention was on a bunch of parallel independent process, they could be run on separate machines.</p>
<p>The example above illustrates why the concurrency problem posed by multiple core CPUs and GPUs, might not be that much important:</p>
<ol>
<li>Many problems are not CPU bound anyway, and even if they are, the bottleneck might be elsewhere. Another example: I am the proud owner of 3 cheap, slow laptops (one being a netbook). For my use case I really don&#8217;t need faster applications, I wonder how many users really need more than they already have?</li>
<li>Even if more CPU/GPU power is needed, a loosely coupled model (without much interprocess communication and contention issues) might be enough. This is typically the case of many web apps, which can scale by just adding more computers which run independent processes.</li>
</ol>
<p>Concurrency, even with modern abstractions, is hard. It should be avoided if possible and it can be avoided in many applications. If it cannot be avoided, maybe a loosely coupled model is enough&#8230; Guido van Rossum <a href="http://mail.python.org/pipermail/python-3000/2007-May/007414.html">has a nice take on this issue</a>.</p>
<p>This is important as concurrency is being touted as an important criteria to evaluate languages. Modern functional languages (think Scala and Clojure) are being touted as a better option precisely because they are better to do concurrency (both because of functional &#8211; &#8220;no changing state&#8221; &#8211; programming and the availability of libraries implementing nice concurrency paradigms like actors).</p>
<p>When addressing this importance of this issue, I would propose, that people would ask themselves this: &#8220;Am I developing computationally intensive software?&#8221; and &#8220;If I am developing computationally intensive software, can I live with loosely coupled models of computation, preferably processes with no shared memory?&#8221;</p>
<p>This is not to say that there are not some cases where tightly coupled computing is a good idea. It is just that, this complex solution might be an overkill for many problems.</p>
<p>I would just like to add that I am not defending my cause, in fact it is quite the opposite. There is actually some content produced here, in the past, on how to tackle concurrent programming:</p>
<ol>
<li><a href="http://popgen.eu/soft/lositan">LOSITAN</a> &#8211; A multicore-aware Jython-based (Python for the JVM) Web Start application to do selection detection.</li>
<li>An introductory tutorial on concurrent computing targeting computational biologists &#8211; Part <a href="http://tiago.org/ps/2007/07/06/bioinformatics-multi-core-cpus-and-grid-computing-introduction-14/">1</a>, <a href="http://tiago.org/ps/2007/07/17/bioinformatics-multi-core-cpus-and-grid-computing-user-perspective-24/">2</a> and <a href="http://tiago.org/ps/2007/07/31/bioinformatics-multi-core-cpus-and-grid-computing-developer-perspective-34/">3</a></li>
</ol>
<div class='sociable'><div><span class='sociable-tagline'>Share and Enjoy:</span></div><ul><li><a rel="nofollow"   href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F02%2Fconcurrency-and-multicore-cpugpus-are-overhyped%2F&amp;title=Concurrency%20and%20multicore%20CPU%2FGPUs%20are%20overhyped&amp;bodytext=More%20than%2010%20years%20ago%20I%20participated%20in%20the%20development%20of%20an%20University%20IT%20system%20%28the%20front-%20and%20backend%20to%20maintain%20grades%20and%20that%20sort%20of%20stuff%29.%20The%20system%20was%20based%20on%20a%20DB%2F2%20backend%20%28a%20very%20nice%20database%20system%29%20with%20the%20business%20code%20stored" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/digg.png" class="sociable-img sociable-hovers" title="Digg" alt="Digg" /></a></li><li><a rel="nofollow"   href="http://delicious.com/post?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F02%2Fconcurrency-and-multicore-cpugpus-are-overhyped%2F&amp;title=Concurrency%20and%20multicore%20CPU%2FGPUs%20are%20overhyped&amp;notes=More%20than%2010%20years%20ago%20I%20participated%20in%20the%20development%20of%20an%20University%20IT%20system%20%28the%20front-%20and%20backend%20to%20maintain%20grades%20and%20that%20sort%20of%20stuff%29.%20The%20system%20was%20based%20on%20a%20DB%2F2%20backend%20%28a%20very%20nice%20database%20system%29%20with%20the%20business%20code%20stored" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/delicious.png" class="sociable-img sociable-hovers" title="del.icio.us" alt="del.icio.us" /></a></li><li><a rel="nofollow"   href="http://www.facebook.com/share.php?u=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F02%2Fconcurrency-and-multicore-cpugpus-are-overhyped%2F&amp;t=Concurrency%20and%20multicore%20CPU%2FGPUs%20are%20overhyped" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/facebook.png" class="sociable-img sociable-hovers" title="Facebook" alt="Facebook" /></a></li><li><a rel="nofollow"   href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F02%2Fconcurrency-and-multicore-cpugpus-are-overhyped%2F&amp;title=Concurrency%20and%20multicore%20CPU%2FGPUs%20are%20overhyped&amp;annotation=More%20than%2010%20years%20ago%20I%20participated%20in%20the%20development%20of%20an%20University%20IT%20system%20%28the%20front-%20and%20backend%20to%20maintain%20grades%20and%20that%20sort%20of%20stuff%29.%20The%20system%20was%20based%20on%20a%20DB%2F2%20backend%20%28a%20very%20nice%20database%20system%29%20with%20the%20business%20code%20stored" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/googlebookmark.png" class="sociable-img sociable-hovers" title="Google Bookmarks" alt="Google Bookmarks" /></a></li><li><a rel="nofollow"   href="http://www.dzone.com/links/add.html?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F02%2Fconcurrency-and-multicore-cpugpus-are-overhyped%2F&amp;title=Concurrency%20and%20multicore%20CPU%2FGPUs%20are%20overhyped" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/dzone.png" class="sociable-img sociable-hovers" title="DZone" alt="DZone" /></a></li><li><a rel="nofollow"   href="http://reddit.com/submit?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F02%2Fconcurrency-and-multicore-cpugpus-are-overhyped%2F&amp;title=Concurrency%20and%20multicore%20CPU%2FGPUs%20are%20overhyped" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/reddit.png" class="sociable-img sociable-hovers" title="Reddit" alt="Reddit" /></a></li><li><a rel="nofollow"   href="http://technorati.com/faves?add=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F02%2Fconcurrency-and-multicore-cpugpus-are-overhyped%2F" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/technorati.png" class="sociable-img sociable-hovers" title="Technorati" alt="Technorati" /></a></li><li><a rel="nofollow"   href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F02%2Fconcurrency-and-multicore-cpugpus-are-overhyped%2F&amp;title=Concurrency%20and%20multicore%20CPU%2FGPUs%20are%20overhyped&amp;source=Cognitive+Consonance+Software+engineering+in+a+computational+biology+environment&amp;summary=More%20than%2010%20years%20ago%20I%20participated%20in%20the%20development%20of%20an%20University%20IT%20system%20%28the%20front-%20and%20backend%20to%20maintain%20grades%20and%20that%20sort%20of%20stuff%29.%20The%20system%20was%20based%20on%20a%20DB%2F2%20backend%20%28a%20very%20nice%20database%20system%29%20with%20the%20business%20code%20stored" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/linkedin.png" class="sociable-img sociable-hovers" title="LinkedIn" alt="LinkedIn" /></a></li><li><a rel="nofollow"   href="http://www.connotea.org/addpopup?continue=confirm&amp;uri=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F02%2Fconcurrency-and-multicore-cpugpus-are-overhyped%2F&amp;title=Concurrency%20and%20multicore%20CPU%2FGPUs%20are%20overhyped&amp;description=More%20than%2010%20years%20ago%20I%20participated%20in%20the%20development%20of%20an%20University%20IT%20system%20%28the%20front-%20and%20backend%20to%20maintain%20grades%20and%20that%20sort%20of%20stuff%29.%20The%20system%20was%20based%20on%20a%20DB%2F2%20backend%20%28a%20very%20nice%20database%20system%29%20with%20the%20business%20code%20stored" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/connotea.png" class="sociable-img sociable-hovers" title="connotea" alt="connotea" /></a></li><li><a rel="nofollow"   href="http://www.friendfeed.com/share?title=Concurrency%20and%20multicore%20CPU%2FGPUs%20are%20overhyped&amp;link=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F02%2Fconcurrency-and-multicore-cpugpus-are-overhyped%2F" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/friendfeed.png" class="sociable-img sociable-hovers" title="FriendFeed" alt="FriendFeed" /></a></li><li><a rel="nofollow"   href="http://twitter.com/home?status=Concurrency%20and%20multicore%20CPU%2FGPUs%20are%20overhyped%20-%20http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F11%2F02%2Fconcurrency-and-multicore-cpugpus-are-overhyped%2F" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/twitter.png" class="sociable-img sociable-hovers" title="Twitter" alt="Twitter" /></a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://tiago.org/cc/2009/11/02/concurrency-and-multicore-cpugpus-are-overhyped/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Swing menus in Clojure</title>
		<link>http://tiago.org/cc/2009/10/27/swing-menus-in-clojure/</link>
		<comments>http://tiago.org/cc/2009/10/27/swing-menus-in-clojure/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 22:19:39 +0000</pubDate>
		<dc:creator>tiago</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[clojure]]></category>
		<category><![CDATA[DSL]]></category>
		<category><![CDATA[swing]]></category>

		<guid isPermaLink="false">http://tiago.org/cc/?p=110</guid>
		<description><![CDATA[I am doing some development in Clojure (a Lisp type language for the JVM). Lisp as in a clone tailored for the JVM, not Lisp as only &#8220;functional programming&#8221;. I note, by the way, that more than functional programming, Lisp is an homoiconic language. I developed a simple system to specify Swing menus in clojure, [...]]]></description>
			<content:encoded><![CDATA[<p>I am doing some development in Clojure (a Lisp type language for the JVM). Lisp as in a clone tailored for the JVM, not Lisp as only &#8220;functional programming&#8221;. I note, by the way, that more than functional programming, Lisp is an homoiconic language.</p>
<p>I developed a simple system to specify Swing menus in clojure, here is an example:</p>
<div id="attachment_116" class="wp-caption alignnone" style="width: 155px"><img src="http://tiago.org/cc/wp-content/uploads/2009/10/Screenshot-treeHugger.png" alt="Simple Menu" title="menuSimple" width="145" height="145" class="size-full wp-image-116" /><p class="wp-caption-text">Simple Menu</p></div>
<p>The following &#8220;micro-language&#8221; was developed to specify this:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"> <span style="color: #66cc66;">&#40;</span>getMenuBar actionManager '<span style="color: #66cc66;">&#40;</span>
    <span style="color: #66cc66;">&#40;</span>menu <span style="color: #66cc66;">&#123;</span>
      <span style="color: #66cc66;">:</span><span style="color: #555;">text</span> <span style="color: #ff0000;">&quot;Project&quot;</span> <span style="color: #66cc66;">:</span><span style="color: #555;">key</span> <span style="color: #ff0000;">&quot;P&quot;</span>
      <span style="color: #66cc66;">:</span><span style="color: #555;">content</span> <span style="color: #66cc66;">&#40;</span>
        <span style="color: #66cc66;">&#40;</span>item <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">:</span><span style="color: #555;">text</span> <span style="color: #ff0000;">&quot;New&quot;</span> <span style="color: #66cc66;">:</span><span style="color: #555;">key</span> <span style="color: #ff0000;">&quot;N&quot;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span>item <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">:</span><span style="color: #555;">text</span> <span style="color: #ff0000;">&quot;Open&quot;</span> <span style="color: #66cc66;">:</span><span style="color: #555;">key</span> <span style="color: #ff0000;">&quot;O&quot;</span>  <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span>item <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">:</span><span style="color: #555;">text</span> <span style="color: #ff0000;">&quot;Close&quot;</span> <span style="color: #66cc66;">:</span><span style="color: #555;">key</span> <span style="color: #ff0000;">&quot;O&quot;</span> <span style="color: #66cc66;">:</span><span style="color: #555;">id</span> <span style="color: #ff0000;">&quot;Close&quot;</span> <span style="color: #66cc66;">:</span><span style="color: #555;">enabled</span> false<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span>item <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">:</span><span style="color: #555;">text</span> <span style="color: #ff0000;">&quot;Recent&quot;</span> <span style="color: #66cc66;">:</span><span style="color: #555;">key</span> <span style="color: #ff0000;">&quot;R&quot;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span>separator<span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span>item <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">:</span><span style="color: #555;">text</span> <span style="color: #ff0000;">&quot;Exit&quot;</span> <span style="color: #66cc66;">:</span><span style="color: #555;">key</span> <span style="color: #ff0000;">&quot;E&quot;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>menu <span style="color: #66cc66;">&#123;</span>
      <span style="color: #66cc66;">:</span><span style="color: #555;">text</span> <span style="color: #ff0000;">&quot;Options&quot;</span> <span style="color: #66cc66;">:</span><span style="color: #555;">key</span> <span style="color: #ff0000;">&quot;O&quot;</span>
      <span style="color: #66cc66;">:</span><span style="color: #555;">content</span> <span style="color: #66cc66;">&#40;</span>
        <span style="color: #66cc66;">&#40;</span>item <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">:</span><span style="color: #555;">text</span> <span style="color: #ff0000;">&quot;Rendering&quot;</span> <span style="color: #66cc66;">:</span><span style="color: #555;">key</span> <span style="color: #ff0000;">&quot;R&quot;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>The code is very easy to read, I hope: two menu items, with a few menu entries with text, ability to enable/disable and accelerator keys, plus a separator.</p>
<p>Notice the actionManager on top, is it the (very simple) event processing function which receives only a text as parameter (to identify the selection). The text is simply the menu text, or, if specified an id. Not the most general solution, but enough for simple menu structures.</p>
<p>The code? Below is the _complete_ implementation.</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;">&nbsp;
<span style="color: #66cc66;">&#40;</span>ns org<span style="color: #66cc66;">.</span>tiago<span style="color: #66cc66;">.</span>swing
  <span style="color: #808080; font-style: italic;">;(:require clojure.contrib.def)</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #555;">use</span>
    <span style="color: #66cc66;">&#91;</span>clojure<span style="color: #66cc66;">.</span>contrib<span style="color: #66cc66;">.</span>seq-utils <span style="color: #66cc66;">:</span><span style="color: #555;">only</span> <span style="color: #66cc66;">&#40;</span>flatten<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
    <span style="color: #66cc66;">&#91;</span>clojure<span style="color: #66cc66;">.</span>contrib<span style="color: #66cc66;">.</span>def <span style="color: #66cc66;">:</span><span style="color: #555;">only</span> <span style="color: #66cc66;">&#40;</span>defnk<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #555;">import</span>
    <span style="color: #66cc66;">&#40;</span>java<span style="color: #66cc66;">.</span>awt<span style="color: #66cc66;">.</span>event ActionListener KeyEvent<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>javax<span style="color: #66cc66;">.</span>swing JFrame JMenu JMenuBar JMenuItem<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>defnk createFrame <span style="color: #66cc66;">&#91;</span>title <span style="color: #66cc66;">:</span><span style="color: #555;">menuBar</span> <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#40;</span>def frame <span style="color: #66cc66;">&#40;</span>new JFrame title<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> frame setDefaultCloseOperation <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> JFrame EXIT_ON_CLOSE<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> menuBar <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> frame setJMenuBar menuBar<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> frame pack<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> frame setVisible true<span style="color: #66cc66;">&#41;</span>
  frame
<span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>defmulti addMItem <span style="color: #66cc66;">&#40;</span>fn <span style="color: #66cc66;">&#91;</span>manager x <span style="color: #66cc66;">&amp;</span> rst<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#40;</span>first x<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>defmethod addMItem 'item <span style="color: #66cc66;">&#91;</span>manager content menu<span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#91;</span>params <span style="color: #66cc66;">&#40;</span>second content<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
    <span style="color: #66cc66;">&#40;</span>def mItem <span style="color: #66cc66;">&#40;</span>new JMenuItem <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #555;">text</span> params<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>contains? params <span style="color: #66cc66;">:</span><span style="color: #555;">id</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> mItem putClientProperty <span style="color: #ff0000;">&quot;id&quot;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #555;">id</span> params<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>contains? params <span style="color: #66cc66;">:</span><span style="color: #555;">key</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> mItem setMnemonic <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #555;">key</span> params<span style="color: #66cc66;">&#41;</span> charAt <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> menu add mItem<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> mItem addActionListener manager<span style="color: #66cc66;">&#41;</span>
&nbsp;
  <span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>defmethod addMItem 'separator <span style="color: #66cc66;">&#91;</span>manager sep menu<span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> menu addSeparator<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>defmulti getMBItem first<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>defmethod getMBItem 'menu <span style="color: #66cc66;">&#91;</span>desc<span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#91;</span>params <span style="color: #66cc66;">&#40;</span>second desc<span style="color: #66cc66;">&#41;</span> manager <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">last</span> desc<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
    <span style="color: #66cc66;">&#40;</span>def menu <span style="color: #66cc66;">&#40;</span>new JMenu <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #555;">text</span> params<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #808080; font-style: italic;">;Assuming mnemonic is ASCII CODE.</span>
    <span style="color: #808080; font-style: italic;">;java7 has . KeyEvent getExtendedKeyCodeForChar</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>contains? params <span style="color: #66cc66;">:</span><span style="color: #555;">key</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> menu setMnemonic <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #555;">key</span> params<span style="color: #66cc66;">&#41;</span> charAt <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>contains? params <span style="color: #66cc66;">:</span><span style="color: #555;">id</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> menu putClientProperty <span style="color: #ff0000;">&quot;id&quot;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #555;">id</span> params<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>dorun <span style="color: #66cc66;">&#40;</span>map #<span style="color: #66cc66;">&#40;</span>addMItem manager <span style="color: #66cc66;">%</span> menu<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #555;">content</span> params<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    menu
  <span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>defmethod getMBItem <span style="color: #66cc66;">:</span><span style="color: #555;">default</span> <span style="color: #66cc66;">&#91;</span>arg<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#40;</span>new JMenu <span style="color: #ff0000;">&quot;UNK&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>defn getMenuBar <span style="color: #66cc66;">&#91;</span>actionManager menuItems<span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#91;</span>manager <span style="color: #66cc66;">&#40;</span>
      proxy <span style="color: #66cc66;">&#91;</span>ActionListener<span style="color: #66cc66;">&#93;</span>
      <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>
      <span style="color: #66cc66;">&#40;</span>actionPerformed <span style="color: #66cc66;">&#91;</span>e<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#91;</span>obj <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span>getSource e<span style="color: #66cc66;">&#41;</span>
                                 id <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span>getClientProperty obj <span style="color: #ff0000;">&quot;id&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
        <span style="color: #66cc66;">&#40;</span>actionManager <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">nil</span>? id<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> obj getText<span style="color: #66cc66;">&#41;</span> id<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
   <span style="color: #66cc66;">&#40;</span>def menuBar <span style="color: #66cc66;">&#40;</span>new JMenuBar<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#40;</span>dorun <span style="color: #66cc66;">&#40;</span>map #<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> menuBar add <span style="color: #66cc66;">%</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #66cc66;">&#40;</span>map #<span style="color: #66cc66;">&#40;</span>getMBItem <span style="color: #66cc66;">&#40;</span>concat <span style="color: #66cc66;">%</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> manager <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> menuItems<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    menuBar
  <span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>OK, comments have to be added <img src='http://tiago.org/cc/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  .<br />
From a declarative point of view, not bad at all.</p>
<p>My first Lisp program. It completely baffles me that, 25 years of programming with all the languages imaginable (including some functional like Caml or highly declarative like Prolog), I never tried Lisp.</p>
<div class='sociable'><div><span class='sociable-tagline'>Share and Enjoy:</span></div><ul><li><a rel="nofollow"   href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F10%2F27%2Fswing-menus-in-clojure%2F&amp;title=Swing%20menus%20in%20Clojure&amp;bodytext=I%20am%20doing%20some%20development%20in%20Clojure%20%28a%20Lisp%20type%20language%20for%20the%20JVM%29.%20Lisp%20as%20in%20a%20clone%20tailored%20for%20the%20JVM%2C%20not%20Lisp%20as%20only%20%22functional%20programming%22.%20I%20note%2C%20by%20the%20way%2C%20that%20more%20than%20functional%20programming%2C%20Lisp%20is%20an%20homoiconic%20language.%0D" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/digg.png" class="sociable-img sociable-hovers" title="Digg" alt="Digg" /></a></li><li><a rel="nofollow"   href="http://delicious.com/post?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F10%2F27%2Fswing-menus-in-clojure%2F&amp;title=Swing%20menus%20in%20Clojure&amp;notes=I%20am%20doing%20some%20development%20in%20Clojure%20%28a%20Lisp%20type%20language%20for%20the%20JVM%29.%20Lisp%20as%20in%20a%20clone%20tailored%20for%20the%20JVM%2C%20not%20Lisp%20as%20only%20%22functional%20programming%22.%20I%20note%2C%20by%20the%20way%2C%20that%20more%20than%20functional%20programming%2C%20Lisp%20is%20an%20homoiconic%20language.%0D" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/delicious.png" class="sociable-img sociable-hovers" title="del.icio.us" alt="del.icio.us" /></a></li><li><a rel="nofollow"   href="http://www.facebook.com/share.php?u=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F10%2F27%2Fswing-menus-in-clojure%2F&amp;t=Swing%20menus%20in%20Clojure" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/facebook.png" class="sociable-img sociable-hovers" title="Facebook" alt="Facebook" /></a></li><li><a rel="nofollow"   href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F10%2F27%2Fswing-menus-in-clojure%2F&amp;title=Swing%20menus%20in%20Clojure&amp;annotation=I%20am%20doing%20some%20development%20in%20Clojure%20%28a%20Lisp%20type%20language%20for%20the%20JVM%29.%20Lisp%20as%20in%20a%20clone%20tailored%20for%20the%20JVM%2C%20not%20Lisp%20as%20only%20%22functional%20programming%22.%20I%20note%2C%20by%20the%20way%2C%20that%20more%20than%20functional%20programming%2C%20Lisp%20is%20an%20homoiconic%20language.%0D" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/googlebookmark.png" class="sociable-img sociable-hovers" title="Google Bookmarks" alt="Google Bookmarks" /></a></li><li><a rel="nofollow"   href="http://www.dzone.com/links/add.html?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F10%2F27%2Fswing-menus-in-clojure%2F&amp;title=Swing%20menus%20in%20Clojure" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/dzone.png" class="sociable-img sociable-hovers" title="DZone" alt="DZone" /></a></li><li><a rel="nofollow"   href="http://reddit.com/submit?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F10%2F27%2Fswing-menus-in-clojure%2F&amp;title=Swing%20menus%20in%20Clojure" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/reddit.png" class="sociable-img sociable-hovers" title="Reddit" alt="Reddit" /></a></li><li><a rel="nofollow"   href="http://technorati.com/faves?add=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F10%2F27%2Fswing-menus-in-clojure%2F" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/technorati.png" class="sociable-img sociable-hovers" title="Technorati" alt="Technorati" /></a></li><li><a rel="nofollow"   href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F10%2F27%2Fswing-menus-in-clojure%2F&amp;title=Swing%20menus%20in%20Clojure&amp;source=Cognitive+Consonance+Software+engineering+in+a+computational+biology+environment&amp;summary=I%20am%20doing%20some%20development%20in%20Clojure%20%28a%20Lisp%20type%20language%20for%20the%20JVM%29.%20Lisp%20as%20in%20a%20clone%20tailored%20for%20the%20JVM%2C%20not%20Lisp%20as%20only%20%22functional%20programming%22.%20I%20note%2C%20by%20the%20way%2C%20that%20more%20than%20functional%20programming%2C%20Lisp%20is%20an%20homoiconic%20language.%0D" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/linkedin.png" class="sociable-img sociable-hovers" title="LinkedIn" alt="LinkedIn" /></a></li><li><a rel="nofollow"   href="http://www.connotea.org/addpopup?continue=confirm&amp;uri=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F10%2F27%2Fswing-menus-in-clojure%2F&amp;title=Swing%20menus%20in%20Clojure&amp;description=I%20am%20doing%20some%20development%20in%20Clojure%20%28a%20Lisp%20type%20language%20for%20the%20JVM%29.%20Lisp%20as%20in%20a%20clone%20tailored%20for%20the%20JVM%2C%20not%20Lisp%20as%20only%20%22functional%20programming%22.%20I%20note%2C%20by%20the%20way%2C%20that%20more%20than%20functional%20programming%2C%20Lisp%20is%20an%20homoiconic%20language.%0D" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/connotea.png" class="sociable-img sociable-hovers" title="connotea" alt="connotea" /></a></li><li><a rel="nofollow"   href="http://www.friendfeed.com/share?title=Swing%20menus%20in%20Clojure&amp;link=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F10%2F27%2Fswing-menus-in-clojure%2F" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/friendfeed.png" class="sociable-img sociable-hovers" title="FriendFeed" alt="FriendFeed" /></a></li><li><a rel="nofollow"   href="http://twitter.com/home?status=Swing%20menus%20in%20Clojure%20-%20http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F10%2F27%2Fswing-menus-in-clojure%2F" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/twitter.png" class="sociable-img sociable-hovers" title="Twitter" alt="Twitter" /></a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://tiago.org/cc/2009/10/27/swing-menus-in-clojure/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Toying with processing</title>
		<link>http://tiago.org/cc/2009/08/11/toying-with-processing/</link>
		<comments>http://tiago.org/cc/2009/08/11/toying-with-processing/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 17:30:16 +0000</pubDate>
		<dc:creator>tiago</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Visual]]></category>
		<category><![CDATA[processing]]></category>

		<guid isPermaLink="false">http://tiago.org/cc/?p=90</guid>
		<description><![CDATA[I have been toying with Processing. Processing is.. &#8230;an open source programming language and environment for people who want to program images, animation, and interactions. It is used by students, artists, designers, researchers, and hobbyists for learning, prototyping, and production. Processing is actually a full blown IDE with a language based on Java (it is [...]]]></description>
			<content:encoded><![CDATA[<p>I have been toying with <a href="http://processing.org">Processing</a>. Processing is..</p>
<blockquote><p>
&#8230;an open source programming language and environment for people who want to program images, animation, and interactions. It is used by students, artists, designers, researchers, and hobbyists for learning, prototyping, and production.
</p></blockquote>
<p>Processing is actually a full blown IDE with a language based on Java (it is JVM based).</p>
<p>I am fascinated by its community and how most things seems to cleverly done.</p>
<p>Here is my first example (applet alert!). After it loads, move the mouse over the applet to see it in action (you might have to mouse click for it to start on some browsers, like Opera):</p>
<p><applet name="door" WIDTH="400" HEIGHT="200" archive="http://tiago.org/pstmp/door/door.jar" standby="Loading Processing software..." CODE="door" mayscript="true" scriptable="true" image="http://tiago.org/pstmp/door/loading.gif" boxmessage="Loading Processing software..." boxcolor="#FFFFFF"><br />
Please install Java!<br />
</applet> </p>
<p>The code for the above is just:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    size<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">400</span>, <span style="color: #cc66cc;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
color elColor <span style="color: #339933;">=</span> color<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span>,<span style="color: #cc66cc;">255</span>,<span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  background<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">float</span> delta <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1.0</span><span style="color: #339933;">*</span>mouseY<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span>height<span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>random<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      elColor <span style="color: #339933;">=</span> color<span style="color: #009900;">&#40;</span>random<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span>, random<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span>, random<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  fill<span style="color: #009900;">&#40;</span>elColor<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  ellipse<span style="color: #009900;">&#40;</span>width<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span>, height<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">80.0</span><span style="color: #339933;">*</span>mouseY<span style="color: #339933;">/</span>height, <span style="color: #cc66cc;">50.0</span><span style="color: #339933;">*</span>mouseX<span style="color: #339933;">/</span>width<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255.0</span><span style="color: #339933;">*</span>mouseY<span style="color: #339933;">/</span>width,<span style="color: #cc66cc;">255.0</span><span style="color: #339933;">*</span>mouseX<span style="color: #339933;">/</span>width, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">255</span><span style="color: #339933;">*</span>mouseX<span style="color: #339933;">/</span>width<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  quad<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>,
      delta<span style="color: #339933;">*</span>width<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span>, <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span>delta<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>height<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span>,
      delta<span style="color: #339933;">*</span>width<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span>, height <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span>delta<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>height<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span>,
      <span style="color: #cc66cc;">0</span>, height<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  quad<span style="color: #009900;">&#40;</span>width, <span style="color: #cc66cc;">0</span>,
      width <span style="color: #339933;">-</span> delta<span style="color: #339933;">*</span>width<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span>, <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span>delta<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>height<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span>,
      width <span style="color: #339933;">-</span> delta<span style="color: #339933;">*</span>width<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span>, height <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span>delta<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>height<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span>,
      width, height<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The vibrant community behind seems to produce quite a lot of really neat examples. <a href="http://processing.org">Go and check for yourself</a>&#8230;</p>
<div class='sociable'><div><span class='sociable-tagline'>Share and Enjoy:</span></div><ul><li><a rel="nofollow"   href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F11%2Ftoying-with-processing%2F&amp;title=Toying%20with%20processing&amp;bodytext=I%20have%20been%20toying%20with%20Processing.%20Processing%20is..%0D%0A%0D%0A%0D%0A...an%20open%20source%20programming%20language%20and%20environment%20for%20people%20who%20want%20to%20program%20images%2C%20animation%2C%20and%20interactions.%20It%20is%20used%20by%20students%2C%20artists%2C%20designers%2C%20researchers%2C%20and%20hobbyists" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/digg.png" class="sociable-img sociable-hovers" title="Digg" alt="Digg" /></a></li><li><a rel="nofollow"   href="http://delicious.com/post?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F11%2Ftoying-with-processing%2F&amp;title=Toying%20with%20processing&amp;notes=I%20have%20been%20toying%20with%20Processing.%20Processing%20is..%0D%0A%0D%0A%0D%0A...an%20open%20source%20programming%20language%20and%20environment%20for%20people%20who%20want%20to%20program%20images%2C%20animation%2C%20and%20interactions.%20It%20is%20used%20by%20students%2C%20artists%2C%20designers%2C%20researchers%2C%20and%20hobbyists" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/delicious.png" class="sociable-img sociable-hovers" title="del.icio.us" alt="del.icio.us" /></a></li><li><a rel="nofollow"   href="http://www.facebook.com/share.php?u=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F11%2Ftoying-with-processing%2F&amp;t=Toying%20with%20processing" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/facebook.png" class="sociable-img sociable-hovers" title="Facebook" alt="Facebook" /></a></li><li><a rel="nofollow"   href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F11%2Ftoying-with-processing%2F&amp;title=Toying%20with%20processing&amp;annotation=I%20have%20been%20toying%20with%20Processing.%20Processing%20is..%0D%0A%0D%0A%0D%0A...an%20open%20source%20programming%20language%20and%20environment%20for%20people%20who%20want%20to%20program%20images%2C%20animation%2C%20and%20interactions.%20It%20is%20used%20by%20students%2C%20artists%2C%20designers%2C%20researchers%2C%20and%20hobbyists" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/googlebookmark.png" class="sociable-img sociable-hovers" title="Google Bookmarks" alt="Google Bookmarks" /></a></li><li><a rel="nofollow"   href="http://www.dzone.com/links/add.html?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F11%2Ftoying-with-processing%2F&amp;title=Toying%20with%20processing" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/dzone.png" class="sociable-img sociable-hovers" title="DZone" alt="DZone" /></a></li><li><a rel="nofollow"   href="http://reddit.com/submit?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F11%2Ftoying-with-processing%2F&amp;title=Toying%20with%20processing" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/reddit.png" class="sociable-img sociable-hovers" title="Reddit" alt="Reddit" /></a></li><li><a rel="nofollow"   href="http://technorati.com/faves?add=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F11%2Ftoying-with-processing%2F" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/technorati.png" class="sociable-img sociable-hovers" title="Technorati" alt="Technorati" /></a></li><li><a rel="nofollow"   href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F11%2Ftoying-with-processing%2F&amp;title=Toying%20with%20processing&amp;source=Cognitive+Consonance+Software+engineering+in+a+computational+biology+environment&amp;summary=I%20have%20been%20toying%20with%20Processing.%20Processing%20is..%0D%0A%0D%0A%0D%0A...an%20open%20source%20programming%20language%20and%20environment%20for%20people%20who%20want%20to%20program%20images%2C%20animation%2C%20and%20interactions.%20It%20is%20used%20by%20students%2C%20artists%2C%20designers%2C%20researchers%2C%20and%20hobbyists" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/linkedin.png" class="sociable-img sociable-hovers" title="LinkedIn" alt="LinkedIn" /></a></li><li><a rel="nofollow"   href="http://www.connotea.org/addpopup?continue=confirm&amp;uri=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F11%2Ftoying-with-processing%2F&amp;title=Toying%20with%20processing&amp;description=I%20have%20been%20toying%20with%20Processing.%20Processing%20is..%0D%0A%0D%0A%0D%0A...an%20open%20source%20programming%20language%20and%20environment%20for%20people%20who%20want%20to%20program%20images%2C%20animation%2C%20and%20interactions.%20It%20is%20used%20by%20students%2C%20artists%2C%20designers%2C%20researchers%2C%20and%20hobbyists" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/connotea.png" class="sociable-img sociable-hovers" title="connotea" alt="connotea" /></a></li><li><a rel="nofollow"   href="http://www.friendfeed.com/share?title=Toying%20with%20processing&amp;link=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F11%2Ftoying-with-processing%2F" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/friendfeed.png" class="sociable-img sociable-hovers" title="FriendFeed" alt="FriendFeed" /></a></li><li><a rel="nofollow"   href="http://twitter.com/home?status=Toying%20with%20processing%20-%20http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F11%2Ftoying-with-processing%2F" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/twitter.png" class="sociable-img sociable-hovers" title="Twitter" alt="Twitter" /></a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://tiago.org/cc/2009/08/11/toying-with-processing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multicore (and GPU) approaches</title>
		<link>http://tiago.org/cc/2009/08/09/multicore-and-gpu-approaches/</link>
		<comments>http://tiago.org/cc/2009/08/09/multicore-and-gpu-approaches/#comments</comments>
		<pubDate>Sun, 09 Aug 2009 19:18:00 +0000</pubDate>
		<dc:creator>tiago</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[concurrrent programming]]></category>
		<category><![CDATA[multicore]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://tiago.org/cc/?p=86</guid>
		<description><![CDATA[It is interesting to see how different people tackle the ongoing multicore (and GPU) software &#8220;revolution&#8221;. There are strong philosophical differences on how to develop for these new concurrent architectures. Lets start with the extremes. The most interesting extreme comes from Guido van Rossum (aka Python benevolent dictator for life): He suggests that if you [...]]]></description>
			<content:encoded><![CDATA[<p>It is interesting to see how different people tackle the ongoing multicore (and GPU) software &#8220;revolution&#8221;. There are strong philosophical differences on how to develop for these new concurrent architectures. Lets start with the extremes.</p>
<p>The most interesting extreme comes from Guido van Rossum (aka Python benevolent dictator for life): He <a href="http://mail.python.org/pipermail/python-3000/2007-May/007414.html">suggests</a> that if you want to use the available processing power of multiple cores you should have separated processes, let me quote:</p>
<blockquote><p>[...] doesn&#8217;t mean that multiple processes (with judicious use of IPC) aren&#8217;t a much better approach to writing apps for multi-CPU boxes than threads.</p>
<p>Just Say No to the combined evils of locking, deadlocks, lock granularity, livelocks, nondeterminism and race conditions.</p></blockquote>
<p>Some similar arguments are made by the message passing crowd, which seems to be quite happy with a model based on explicit message passing between separated processes.</p>
<p>The fundamental idea here is that shared memory between parallel computing threads can lead to a lot of grief and sorrow, thus is is better if all the data memory space is the sole propriety of a single thread. Communication occurs in a explicit form (e.g., message passing among executing code) between threads that do not share anything (other than messages).</p>
<p>The opposite idea can be found on the typical C/C++/Fortran, lower-level crowd: One single process, many threads, a single memory space shared among threads with concurrent access controlled through a low level mechanism like semaphores. This seems also to be the underlying idea of the OpenMP system. These folks believe that programmers can tackle parallel complexity easily (well, at least it is not an impossible, daunting task according to this philosophy).</p>
<p>The point of contention comes from the fact that multiple execution flows introduce a completely new class of bugs coming from the need to coordinate a lot of things going on in parallel. The worst problem introduced is non-determinism: You can execute the same program twice, WITH THE SAME INPUT and get different results. Why? Because the different threads/processes will be scheduled in unpredicted ways by the operating system (or virtual machine) which can yield different results. This severely increases the difficulty to test and debug software. The shared memory crowd (the shared memory model is more efficient and flexible as, well, memory is directly shared) will say that we can deal with this. The message passing crowd suggests that having some restrictions and explicit communication will make life easier (or, less complicated).</p>
<p>The Java crowd is where you can find the most variety of opinions, but the core JVM and Java language itself seems to follow the C/C++ philosophy (though with some candy thrown in, like the Fork/Join framework). But on top of that you can find everything with a vocal support community: Tuple spaces, Map/Reduce, Message passing, etc. This is not to say that the Python and C/C++ communities are monolithic (they are not! Just check the C implementations of MPI and PVM), but you really can find a lot alternatives with vibrant communities on top of the JVM.</p>
<p>A sort of middle of the ground approach was introduced de facto with the programming language Erlang: Erlang allows for multiple threads, but the communication is shared-nothing and based on message passing. I.e. while there is one single process with multiple threads, there is no shared-memory per se and all inter-thread communication is based on message passing. This Actor model based language has influenced some recent language libraries in Scala, Groovy and Clojure, among others where the actor model is the main concurrent programming model.</p>
<p>Many functional languages (like Erlang, Scala and Clojure) proponents also suggest that mutability (ie, the concept of variable stemming from imperative languages like C, Java, C#, Basic, C++, 99% of used languages) is not easily amenable to parallel programming and suggest that immutable data structures make life much easier: If what is shared cannot be changed then much less bugs can be introduced.</p>
<p>To sum it up: Some people suggest concurrent programming is difficult and it is better to minimize communication to tackle that difficulty. Others suggest that concurrent programming is workable and tightly-coupled memory-sharing systems are OK. Some also suggest (functional crowd) that immutable data structures help.</p>
<p>Further reading:<br />
<a href="http://en.wikipedia.org/wiki/Concurrent_computing">Concurrent computing</a> (Wikipedia)<br />
<a href="http://www.scala-lang.org/node/242">Scala actors</a> &#8211; My preferred introduction to Actors (which happens to be based on Scala)<br />
<a href="http://en.wikipedia.org/wiki/Erlang_(programming_language)#Concurrency_and_distribution_oriented_language">Erlang Concurrency</a> Message passing (Wikipedia)</p>
<p>My opinion: Shared memory models are for real men! I am just a regular bloke, so I stick with message passing models. The complexity of bugs introduced by concurrent programming is much much worse compared to the existing sequential paradigm. In most of the cases that I have encountered, the restrictions imposed by message passing are acceptable compared to the benefits. Even with message passing and immutable data structures, concurrent programming is still very hard and bug prone (non-determinism is still quite possible with message passing). I expect (hope) that new R&#038;D will allow us to tame this complexity. Avoid shared memory/tightly coupled systems like the plague!</p>
<div class='sociable'><div><span class='sociable-tagline'>Share and Enjoy:</span></div><ul><li><a rel="nofollow"   href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F09%2Fmulticore-and-gpu-approaches%2F&amp;title=Multicore%20%28and%20GPU%29%20approaches&amp;bodytext=It%20is%20interesting%20to%20see%20how%20different%20people%20tackle%20the%20ongoing%20multicore%20%28and%20GPU%29%20software%20%22revolution%22.%20There%20are%20strong%20philosophical%20differences%20on%20how%20to%20develop%20for%20these%20new%20concurrent%20architectures.%20Lets%20start%20with%20the%20extremes.%0D%0A%0D%0AThe%20most" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/digg.png" class="sociable-img sociable-hovers" title="Digg" alt="Digg" /></a></li><li><a rel="nofollow"   href="http://delicious.com/post?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F09%2Fmulticore-and-gpu-approaches%2F&amp;title=Multicore%20%28and%20GPU%29%20approaches&amp;notes=It%20is%20interesting%20to%20see%20how%20different%20people%20tackle%20the%20ongoing%20multicore%20%28and%20GPU%29%20software%20%22revolution%22.%20There%20are%20strong%20philosophical%20differences%20on%20how%20to%20develop%20for%20these%20new%20concurrent%20architectures.%20Lets%20start%20with%20the%20extremes.%0D%0A%0D%0AThe%20most" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/delicious.png" class="sociable-img sociable-hovers" title="del.icio.us" alt="del.icio.us" /></a></li><li><a rel="nofollow"   href="http://www.facebook.com/share.php?u=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F09%2Fmulticore-and-gpu-approaches%2F&amp;t=Multicore%20%28and%20GPU%29%20approaches" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/facebook.png" class="sociable-img sociable-hovers" title="Facebook" alt="Facebook" /></a></li><li><a rel="nofollow"   href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F09%2Fmulticore-and-gpu-approaches%2F&amp;title=Multicore%20%28and%20GPU%29%20approaches&amp;annotation=It%20is%20interesting%20to%20see%20how%20different%20people%20tackle%20the%20ongoing%20multicore%20%28and%20GPU%29%20software%20%22revolution%22.%20There%20are%20strong%20philosophical%20differences%20on%20how%20to%20develop%20for%20these%20new%20concurrent%20architectures.%20Lets%20start%20with%20the%20extremes.%0D%0A%0D%0AThe%20most" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/googlebookmark.png" class="sociable-img sociable-hovers" title="Google Bookmarks" alt="Google Bookmarks" /></a></li><li><a rel="nofollow"   href="http://www.dzone.com/links/add.html?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F09%2Fmulticore-and-gpu-approaches%2F&amp;title=Multicore%20%28and%20GPU%29%20approaches" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/dzone.png" class="sociable-img sociable-hovers" title="DZone" alt="DZone" /></a></li><li><a rel="nofollow"   href="http://reddit.com/submit?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F09%2Fmulticore-and-gpu-approaches%2F&amp;title=Multicore%20%28and%20GPU%29%20approaches" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/reddit.png" class="sociable-img sociable-hovers" title="Reddit" alt="Reddit" /></a></li><li><a rel="nofollow"   href="http://technorati.com/faves?add=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F09%2Fmulticore-and-gpu-approaches%2F" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/technorati.png" class="sociable-img sociable-hovers" title="Technorati" alt="Technorati" /></a></li><li><a rel="nofollow"   href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F09%2Fmulticore-and-gpu-approaches%2F&amp;title=Multicore%20%28and%20GPU%29%20approaches&amp;source=Cognitive+Consonance+Software+engineering+in+a+computational+biology+environment&amp;summary=It%20is%20interesting%20to%20see%20how%20different%20people%20tackle%20the%20ongoing%20multicore%20%28and%20GPU%29%20software%20%22revolution%22.%20There%20are%20strong%20philosophical%20differences%20on%20how%20to%20develop%20for%20these%20new%20concurrent%20architectures.%20Lets%20start%20with%20the%20extremes.%0D%0A%0D%0AThe%20most" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/linkedin.png" class="sociable-img sociable-hovers" title="LinkedIn" alt="LinkedIn" /></a></li><li><a rel="nofollow"   href="http://www.connotea.org/addpopup?continue=confirm&amp;uri=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F09%2Fmulticore-and-gpu-approaches%2F&amp;title=Multicore%20%28and%20GPU%29%20approaches&amp;description=It%20is%20interesting%20to%20see%20how%20different%20people%20tackle%20the%20ongoing%20multicore%20%28and%20GPU%29%20software%20%22revolution%22.%20There%20are%20strong%20philosophical%20differences%20on%20how%20to%20develop%20for%20these%20new%20concurrent%20architectures.%20Lets%20start%20with%20the%20extremes.%0D%0A%0D%0AThe%20most" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/connotea.png" class="sociable-img sociable-hovers" title="connotea" alt="connotea" /></a></li><li><a rel="nofollow"   href="http://www.friendfeed.com/share?title=Multicore%20%28and%20GPU%29%20approaches&amp;link=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F09%2Fmulticore-and-gpu-approaches%2F" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/friendfeed.png" class="sociable-img sociable-hovers" title="FriendFeed" alt="FriendFeed" /></a></li><li><a rel="nofollow"   href="http://twitter.com/home?status=Multicore%20%28and%20GPU%29%20approaches%20-%20http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F08%2F09%2Fmulticore-and-gpu-approaches%2F" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/twitter.png" class="sociable-img sociable-hovers" title="Twitter" alt="Twitter" /></a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://tiago.org/cc/2009/08/09/multicore-and-gpu-approaches/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DSLs and IDEs</title>
		<link>http://tiago.org/cc/2009/01/12/dsls-and-ides/</link>
		<comments>http://tiago.org/cc/2009/01/12/dsls-and-ides/#comments</comments>
		<pubDate>Mon, 12 Jan 2009 18:05:59 +0000</pubDate>
		<dc:creator>tiago</dc:creator>
				<category><![CDATA[Languages]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[DSL]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[ioke]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[prolog]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://tiago.org/cc/?p=78</guid>
		<description><![CDATA[If you search the web you can find some discussions on whether IDEs for dynamic languages can be as helpful as IDEs for static languages. The issue is that static languages like Java have compile-time (thus easy to get at IDE-time) information in order to provide that fundamental code-completion functionality (among many others). If the [...]]]></description>
			<content:encoded><![CDATA[<p>If you search the web you can find some discussions on whether IDEs for dynamic languages can be as helpful as IDEs for static languages. The issue is that static languages like Java have compile-time (thus easy to get at IDE-time) information in order to provide that fundamental code-completion functionality (among many others). If the IDE knows that a certain parameter is a String, than it is simple: it will present to you all the String methods when you type in the dot. For dynamic languages things get more complex are there is formally no (by definition) compile-time information. Some people would argue that there are ways around it (which you can already find in existing IDEs, I remember having some sort of code completion, years ago, on SPE &#8211; for Python). I will not add anything to that discussion here, this preamble was mainly for putting the reader in context. I am more interested in discussing good IDEs for DSLs.</p>
<p>With DSLs you get, most of the times, added syntax. Worse than that, you might fall into situations where you have changed (not only added) the initial language syntax; furthermore those syntax changes might even become valid only in runtime (imagine that a method is added to a class that is supplying DSL methods).</p>
<p>One example comes from Ioke and Prolog operator precedence and associativity rules which are changeable (see the previous post). It is not trivial to know if something like 1+2 is even syntactically valid (*). Even if it is syntactically valid things like association rules might change. In languages like Groovy you can add (e.g., through categories) methods to code blocs (from classes that can be dynamically changed). Then there is dynamic dispatching and macros. What is valid in a certain piece of code can be different from what is valid a few lines below. In fact, complete information of what is valid in a certain code block might require code execution. Or, to put in another way, it might be very difficult to have a completely helpful IDE! In this scenario there are 3 considerations that I think are worth being done:</p>
<p>1. One should not be discouraged for not having perfect solutions. Maybe it is not possible to determine all that can be expressed in a certain code block, but sometimes good approximations are enough.<br />
2. On this issue, one good example comes from Prolog: In Prolog, syntax can be changed mainly through the use of the <img src='http://tiago.org/cc/wp-includes/images/smilies/icon_surprised.gif' alt=':-o' class='wp-smiley' /> p directive (and through asserts and retracts). The <img src='http://tiago.org/cc/wp-includes/images/smilies/icon_surprised.gif' alt=':-o' class='wp-smiley' /> p directive changes operators but is very easy to analyze pre-compilation/interpretation. So, the way DSLs are normally be constructed lend themselves very easily to code analysis which can be used by IDEs. This unfortunately not the case in most real-world languages.<br />
3. It would be cool to have a language where DSL specifications could be automatically used to construct IDEs. The current real-world DSL-able languages (Ruby, Groovy, &#8230;) are DSL-enabled through indirect techniques which can be used to build DSLs (Dynamic reception, operator overload, whatever), in fact many of these techniques exist with other objectives than creating DSLs. If there was a declarative and explicit way to create DSLs, that information could be used to inform IDEs on parsing and other issues. An embedded, core way, to explicitly specify DSLs.</p>
<p>(*) I suppose some will see this as an argument for the fact that you can do pretty stupid (or at least unintuitive) things with DSLs. Well, you can do stupid things with everything. The question is not if you can or not, but the extent of bad use cases and how bad uses can creep in easily. Another (interesting) discussion, but not for now.</p>
<div class='sociable'><div><span class='sociable-tagline'>Share and Enjoy:</span></div><ul><li><a rel="nofollow"   href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F12%2Fdsls-and-ides%2F&amp;title=DSLs%20and%20IDEs&amp;bodytext=If%20you%20search%20the%20web%20you%20can%20find%20some%20discussions%20on%20whether%20IDEs%20for%20dynamic%20languages%20can%20be%20as%20helpful%20as%20IDEs%20for%20static%20languages.%20The%20issue%20is%20that%20static%20languages%20like%20Java%20have%20compile-time%20%28thus%20easy%20to%20get%20at%20IDE-time%29%20information%20in%20ord" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/digg.png" class="sociable-img sociable-hovers" title="Digg" alt="Digg" /></a></li><li><a rel="nofollow"   href="http://delicious.com/post?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F12%2Fdsls-and-ides%2F&amp;title=DSLs%20and%20IDEs&amp;notes=If%20you%20search%20the%20web%20you%20can%20find%20some%20discussions%20on%20whether%20IDEs%20for%20dynamic%20languages%20can%20be%20as%20helpful%20as%20IDEs%20for%20static%20languages.%20The%20issue%20is%20that%20static%20languages%20like%20Java%20have%20compile-time%20%28thus%20easy%20to%20get%20at%20IDE-time%29%20information%20in%20ord" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/delicious.png" class="sociable-img sociable-hovers" title="del.icio.us" alt="del.icio.us" /></a></li><li><a rel="nofollow"   href="http://www.facebook.com/share.php?u=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F12%2Fdsls-and-ides%2F&amp;t=DSLs%20and%20IDEs" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/facebook.png" class="sociable-img sociable-hovers" title="Facebook" alt="Facebook" /></a></li><li><a rel="nofollow"   href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F12%2Fdsls-and-ides%2F&amp;title=DSLs%20and%20IDEs&amp;annotation=If%20you%20search%20the%20web%20you%20can%20find%20some%20discussions%20on%20whether%20IDEs%20for%20dynamic%20languages%20can%20be%20as%20helpful%20as%20IDEs%20for%20static%20languages.%20The%20issue%20is%20that%20static%20languages%20like%20Java%20have%20compile-time%20%28thus%20easy%20to%20get%20at%20IDE-time%29%20information%20in%20ord" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/googlebookmark.png" class="sociable-img sociable-hovers" title="Google Bookmarks" alt="Google Bookmarks" /></a></li><li><a rel="nofollow"   href="http://www.dzone.com/links/add.html?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F12%2Fdsls-and-ides%2F&amp;title=DSLs%20and%20IDEs" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/dzone.png" class="sociable-img sociable-hovers" title="DZone" alt="DZone" /></a></li><li><a rel="nofollow"   href="http://reddit.com/submit?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F12%2Fdsls-and-ides%2F&amp;title=DSLs%20and%20IDEs" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/reddit.png" class="sociable-img sociable-hovers" title="Reddit" alt="Reddit" /></a></li><li><a rel="nofollow"   href="http://technorati.com/faves?add=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F12%2Fdsls-and-ides%2F" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/technorati.png" class="sociable-img sociable-hovers" title="Technorati" alt="Technorati" /></a></li><li><a rel="nofollow"   href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F12%2Fdsls-and-ides%2F&amp;title=DSLs%20and%20IDEs&amp;source=Cognitive+Consonance+Software+engineering+in+a+computational+biology+environment&amp;summary=If%20you%20search%20the%20web%20you%20can%20find%20some%20discussions%20on%20whether%20IDEs%20for%20dynamic%20languages%20can%20be%20as%20helpful%20as%20IDEs%20for%20static%20languages.%20The%20issue%20is%20that%20static%20languages%20like%20Java%20have%20compile-time%20%28thus%20easy%20to%20get%20at%20IDE-time%29%20information%20in%20ord" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/linkedin.png" class="sociable-img sociable-hovers" title="LinkedIn" alt="LinkedIn" /></a></li><li><a rel="nofollow"   href="http://www.connotea.org/addpopup?continue=confirm&amp;uri=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F12%2Fdsls-and-ides%2F&amp;title=DSLs%20and%20IDEs&amp;description=If%20you%20search%20the%20web%20you%20can%20find%20some%20discussions%20on%20whether%20IDEs%20for%20dynamic%20languages%20can%20be%20as%20helpful%20as%20IDEs%20for%20static%20languages.%20The%20issue%20is%20that%20static%20languages%20like%20Java%20have%20compile-time%20%28thus%20easy%20to%20get%20at%20IDE-time%29%20information%20in%20ord" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/connotea.png" class="sociable-img sociable-hovers" title="connotea" alt="connotea" /></a></li><li><a rel="nofollow"   href="http://www.friendfeed.com/share?title=DSLs%20and%20IDEs&amp;link=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F12%2Fdsls-and-ides%2F" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/friendfeed.png" class="sociable-img sociable-hovers" title="FriendFeed" alt="FriendFeed" /></a></li><li><a rel="nofollow"   href="http://twitter.com/home?status=DSLs%20and%20IDEs%20-%20http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F12%2Fdsls-and-ides%2F" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/twitter.png" class="sociable-img sociable-hovers" title="Twitter" alt="Twitter" /></a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://tiago.org/cc/2009/01/12/dsls-and-ides/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Groovy type crazyness</title>
		<link>http://tiago.org/cc/2009/01/05/groovy-type-crazyness/</link>
		<comments>http://tiago.org/cc/2009/01/05/groovy-type-crazyness/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 17:36:07 +0000</pubDate>
		<dc:creator>tiago</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[groovy]]></category>

		<guid isPermaLink="false">http://tiago.org/cc/?p=56</guid>
		<description><![CDATA[Before I start, please remember the finesse of numbers in groovy: 0.1 is a BigDecimal, if you want a Double, you have to write 0.1D. Also, I might be seeing something completely wrong here, corrections are more than welcome! So, what is the result of code below? List lst = [0.1, 0.1D] println lst[0].class println [...]]]></description>
			<content:encoded><![CDATA[<p>Before I start, please remember the <i>finesse</i> of numbers in groovy: 0.1 is a BigDecimal, if you want a Double, you have to write 0.1D.</p>
<p>Also, I might be seeing something completely wrong here, corrections are more than welcome!</p>
<p>So, what is the result of code below?</p>
<p><code><br />
List<double> lst = [0.1, 0.1D]<br />
println lst[0].class<br />
println lst[1].class<br />
println 0.1 == lst[0]<br />
println 0.1 == lst[1]<br />
println 0.1 in [lst[0]]<br />
println 0.1 in [lst[1]]<br />
</double></code></p>
<p>Well, in my book the interpreter should whine on the first line and stop. I am declaring a List of doubles and putting a BigDecimal in. But it doesn&#8217;t. I suppose this is either a bug or some type messing coming from a the not very clear way (for me) Groovy handles types: If I say the type of lst is a List of Doubles, I expect it to behave statically. Either that or the language is misguiding me is allowing me to specify the type and then ignoring it, not good.<br />
So, the result:</p>
<p><code><br />
class java.math.BigDecimal<br />
class java.lang.Double<br />
true<br />
true<br />
true<br />
false<br />
</code></p>
<p>Note that 0.1 is equal to 0.1D (i.e. BigDecimal is equal to Double. For me it makes sense as they have the same value) BUT 0.1 is not in [0.1D]. This, I suppose can only be categorized as a bug (or as something completely unintuitive). </p>
<p>I understand that numbers are not an easy thing to address (precision vs efficiency), but this strikes me as nonintuitive in 2 fronts (type declaration  and number/equality behavior) </p>
<p>Correct me if I am wrong (I can see myself doing a big blunder with equality operator semantics, but I have trouble accepting that groovy lets me put a BigDecimal inside a list of double)&#8230;</p>
<div class='sociable'><div><span class='sociable-tagline'>Share and Enjoy:</span></div><ul><li><a rel="nofollow"   href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F05%2Fgroovy-type-crazyness%2F&amp;title=Groovy%20type%20crazyness&amp;bodytext=Before%20I%20start%2C%20please%20remember%20the%20finesse%20of%20numbers%20in%20groovy%3A%200.1%20is%20a%20BigDecimal%2C%20if%20you%20want%20a%20Double%2C%20you%20have%20to%20write%200.1D.%0D%0A%0D%0AAlso%2C%20I%20might%20be%20seeing%20something%20completely%20wrong%20here%2C%20corrections%20are%20more%20than%20welcome%21%0D%0A%0D%0ASo%2C%20what%20is%20the%20res" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/digg.png" class="sociable-img sociable-hovers" title="Digg" alt="Digg" /></a></li><li><a rel="nofollow"   href="http://delicious.com/post?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F05%2Fgroovy-type-crazyness%2F&amp;title=Groovy%20type%20crazyness&amp;notes=Before%20I%20start%2C%20please%20remember%20the%20finesse%20of%20numbers%20in%20groovy%3A%200.1%20is%20a%20BigDecimal%2C%20if%20you%20want%20a%20Double%2C%20you%20have%20to%20write%200.1D.%0D%0A%0D%0AAlso%2C%20I%20might%20be%20seeing%20something%20completely%20wrong%20here%2C%20corrections%20are%20more%20than%20welcome%21%0D%0A%0D%0ASo%2C%20what%20is%20the%20res" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/delicious.png" class="sociable-img sociable-hovers" title="del.icio.us" alt="del.icio.us" /></a></li><li><a rel="nofollow"   href="http://www.facebook.com/share.php?u=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F05%2Fgroovy-type-crazyness%2F&amp;t=Groovy%20type%20crazyness" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/facebook.png" class="sociable-img sociable-hovers" title="Facebook" alt="Facebook" /></a></li><li><a rel="nofollow"   href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F05%2Fgroovy-type-crazyness%2F&amp;title=Groovy%20type%20crazyness&amp;annotation=Before%20I%20start%2C%20please%20remember%20the%20finesse%20of%20numbers%20in%20groovy%3A%200.1%20is%20a%20BigDecimal%2C%20if%20you%20want%20a%20Double%2C%20you%20have%20to%20write%200.1D.%0D%0A%0D%0AAlso%2C%20I%20might%20be%20seeing%20something%20completely%20wrong%20here%2C%20corrections%20are%20more%20than%20welcome%21%0D%0A%0D%0ASo%2C%20what%20is%20the%20res" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/googlebookmark.png" class="sociable-img sociable-hovers" title="Google Bookmarks" alt="Google Bookmarks" /></a></li><li><a rel="nofollow"   href="http://www.dzone.com/links/add.html?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F05%2Fgroovy-type-crazyness%2F&amp;title=Groovy%20type%20crazyness" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/dzone.png" class="sociable-img sociable-hovers" title="DZone" alt="DZone" /></a></li><li><a rel="nofollow"   href="http://reddit.com/submit?url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F05%2Fgroovy-type-crazyness%2F&amp;title=Groovy%20type%20crazyness" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/reddit.png" class="sociable-img sociable-hovers" title="Reddit" alt="Reddit" /></a></li><li><a rel="nofollow"   href="http://technorati.com/faves?add=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F05%2Fgroovy-type-crazyness%2F" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/technorati.png" class="sociable-img sociable-hovers" title="Technorati" alt="Technorati" /></a></li><li><a rel="nofollow"   href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F05%2Fgroovy-type-crazyness%2F&amp;title=Groovy%20type%20crazyness&amp;source=Cognitive+Consonance+Software+engineering+in+a+computational+biology+environment&amp;summary=Before%20I%20start%2C%20please%20remember%20the%20finesse%20of%20numbers%20in%20groovy%3A%200.1%20is%20a%20BigDecimal%2C%20if%20you%20want%20a%20Double%2C%20you%20have%20to%20write%200.1D.%0D%0A%0D%0AAlso%2C%20I%20might%20be%20seeing%20something%20completely%20wrong%20here%2C%20corrections%20are%20more%20than%20welcome%21%0D%0A%0D%0ASo%2C%20what%20is%20the%20res" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/linkedin.png" class="sociable-img sociable-hovers" title="LinkedIn" alt="LinkedIn" /></a></li><li><a rel="nofollow"   href="http://www.connotea.org/addpopup?continue=confirm&amp;uri=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F05%2Fgroovy-type-crazyness%2F&amp;title=Groovy%20type%20crazyness&amp;description=Before%20I%20start%2C%20please%20remember%20the%20finesse%20of%20numbers%20in%20groovy%3A%200.1%20is%20a%20BigDecimal%2C%20if%20you%20want%20a%20Double%2C%20you%20have%20to%20write%200.1D.%0D%0A%0D%0AAlso%2C%20I%20might%20be%20seeing%20something%20completely%20wrong%20here%2C%20corrections%20are%20more%20than%20welcome%21%0D%0A%0D%0ASo%2C%20what%20is%20the%20res" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/connotea.png" class="sociable-img sociable-hovers" title="connotea" alt="connotea" /></a></li><li><a rel="nofollow"   href="http://www.friendfeed.com/share?title=Groovy%20type%20crazyness&amp;link=http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F05%2Fgroovy-type-crazyness%2F" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/friendfeed.png" class="sociable-img sociable-hovers" title="FriendFeed" alt="FriendFeed" /></a></li><li><a rel="nofollow"   href="http://twitter.com/home?status=Groovy%20type%20crazyness%20-%20http%3A%2F%2Ftiago.org%2Fcc%2F2009%2F01%2F05%2Fgroovy-type-crazyness%2F" ><img src="http://tiago.org/cc/wp-content/plugins/sociable-30/images/default/16/twitter.png" class="sociable-img sociable-hovers" title="Twitter" alt="Twitter" /></a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://tiago.org/cc/2009/01/05/groovy-type-crazyness/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

