<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
    <channel>
        <title>Bryan Weber - Blogs at Near Infinity</title>


        <link>http://www.nearinfinity.com/blogs/</link>
        <description>Employee Blogs</description>
        <language>en</language>
        <copyright>Copyright 2011</copyright>
        <lastBuildDate>Mon, 18 Apr 2011 21:40:48 -0500</lastBuildDate>
        <generator>http://www.sixapart.com/movabletype/</generator>
        <docs>http://www.rssboard.org/rss-specification</docs>
        
        <item>
            <title>Introducing Protogrid</title>
            <description><![CDATA[<p><meta charset="utf-8"><span class="Apple-style-span" style="color: rgb(221, 221, 221); font-family: Verdana, Arial, Helvetica, Tahoma, sans-serif; font-size: 12px; line-height: 20px; "></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="border-collapse: collapse; font-family: 'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif; font-size: 11px; line-height: 20px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">Protogrid is a dynamically typed, prototype based programming language that runs on the JVM.</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="border-collapse: collapse; font-family: 'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif; font-size: 11px; line-height: 20px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">It can be found on github at <a href="http://www.github.com/brweber2/protogrid">http://www.github.com/brweber2/protogrid</a>
<br /></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; line-height: 20px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" style="font-size: 1.953125em; "><b>For users:</b></font></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; line-height: 20px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" style="font-size: 1.953125em; "><b></b></font></span><span class="Apple-style-span" style="border-collapse: collapse; font-family: 'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif; font-size: 11px; line-height: 20px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">Protogrid strives to be simple to write and read. &nbsp;Each form is intended to mean one thing so there should not be any confusion once you become familiar with the syntax. &nbsp;In many ways this one to one mapping of syntax and semantics has been a simplifying and limiting factor in the design of the language. &nbsp;This is especially true for developers who come to protogrid with pre-conceived notions from past experience.</span></p><ul><li style="border-collapse: collapse; font-family: 'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">There is a single keyword 'var'.</li><li style="border-collapse: collapse; font-family: 'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">nil, undefined, true and false are built in prototypes.</li><li style="border-collapse: collapse; font-family: 'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">In protogrid there is a single numeric type.</li><li style="border-collapse: collapse; font-family: 'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">Variable names cannot contain numbers.</li><li style="border-collapse: collapse; font-family: 'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">Parenthesis always indicate function application, even there is no function to apply.  For example, parenthesis used for changing or specifying order of operation precedence are strictly evaluated and the resulting value is left as the current context, but no function invocation actually takes place.</li><li style="border-collapse: collapse; font-family: 'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">Brackets indicate a function declaration.</li><li style="border-collapse: collapse; font-family: 'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">Braces indicate a scoped block.</li><li style="border-collapse: collapse; font-family: 'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">Single = denotes assignment.</li></ul><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">
</font><font class="Apple-style-span" style="font-size: 1.953125em; "><b>For programming language enthusiasts:</b></font></span><p></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">Unfortunately, there isn't much here that will excite you. &nbsp;Protogrid introduces <s>virtually</s> no new programming paradigms, it merely strives to make the developer experience more enjoyable. &nbsp;The current form of Java interop is not something I've seen in any other language that runs on the JVM, but it is not something new or revolutionary. &nbsp;It is arguably a nicer reflection API. &nbsp;And yes, you will cringe if you look under the hood. &nbsp;The implementation is insanely naive and non-performant in every aspect imaginable.


</font><font class="Apple-style-span" style="font-size: 1.953125em; "><b>Java Interop</b></font></span></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">To start interacting with the underlying Java platform, the first step is typically to wrap a Java class.<br /></span></font></span></p><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"></span></font></span></p><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><pre class="prettyprint">var JavaString = WrapClass( java.lang.String )</pre></font><p></p></blockquote><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">The JavaString prototype now is a wrapped Java class. &nbsp;It can be used in one of two ways.<br /></span></font></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "></p><ul><li><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; line-height: 20px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">If invoked the arguments are used to determine which constructor should be called at runtime and if successful a wrapped instance is returned.</span></font></li><li><span class="Apple-style-span" style="border-collapse: collapse; font-family: 'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif; font-size: 11px; line-height: 20px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">Accessing a slot on the wrapped class will look for a field. &nbsp;If one is found a wrapped field is returned. &nbsp;If no field is found, a wrapped methods prototype is returned that wraps all the static methods on the class with the matching name. &nbsp;If this wrapped methods prototype is invoked it uses the arguments passed to it to determine at runtime which specific method should be invoked and a wrapped instance is returned with the result of the invocation.</span></li></ul><p></p><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"></span></font></span></p><pre class="prettyprint"><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">var message = JavaString.format( "Hello %s", "World!" )</font></pre><p></p></blockquote><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">There are a few points of interest here. &nbsp;There is more than one static format method on java.lang.String. &nbsp;Additionally, the String "World!" is converted to an Object[] to support the variadic version of the format method used here.

A wrapped instance is a prototype that can be used with the protogrid, but that can be coerced back to its native Java type when necessary.
</span></font></span></p><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"></span></font></span></p><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><pre class="prettyprint">println( message.toUpperCase() )</pre></font><p></p></blockquote><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" style="font-size: 1.5625em; "><b>What's missing from the interop story?</b></font></span></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">Quite a bit. &nbsp;There is currently no way to implement an interface, to extend a class or to create a new interface or class.
</span></font></span><span class="Apple-style-span" style="border-collapse: collapse; font-family: 'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif; font-size: 11px; line-height: 20px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><br /></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; line-height: 20px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" style="font-size: 1.5625em; "><b><font class="Apple-style-span" style="font-size: 1.25em; ">Show me more!</font></b></font></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" style="font-size: 1.25em; "><b><font class="Apple-style-span" style="font-size: 1.25em; ">Creating a new prototype</font></b></font><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">
Simply clone an existing prototype
</font></span></span></p><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"></span></font></span></p><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><pre class="prettyprint">var MyProto = clone( Object )</pre></font><p></p></blockquote><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">Setting and accessing slots on the prototype is trivial
</span></font></span></p><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"></span></font></span></p><pre class="prettyprint"><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">MyProto.foo = "barbaz"</font></pre><p></p></blockquote><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"></span></font></span></p><pre class="prettyprint"><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">println( MyProto.foo )</font></pre><p></p></blockquote><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">Inspecting the prototype</span></font></span></p><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"></span></font></span></p><pre class="prettyprint"><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">println( MyProto.slots() )</font></pre><p></p></blockquote><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" style="font-size: 1.5625em; "><b>Viewing the AST</b></font></span></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">
At any point, the built in ast function can be called to print out a readable form of the Abstract Syntax Tree if there is every any doubt about what the interpreter is seeing.
</span></font></span></p><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"></span></font></span></p><pre class="prettyprint"><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">ast( 2 + 3 * 4 ^ 5 % 6 )</font></pre><p></p></blockquote><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">This will result in the following AST
</span></font></span></p><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"></span></font></span></p><pre class="prettyprint"><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">( &nbsp;2 &nbsp; + &nbsp;( ( &nbsp;3 &nbsp; * &nbsp;( &nbsp;4 &nbsp; ^ &nbsp; 5 &nbsp;) &nbsp;) &nbsp; % &nbsp; 6 &nbsp;) &nbsp;)</font></pre><p></p></blockquote><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" style="font-size: 1.5625em; "><b>Loading code from a file</b></font></span></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">When loading code from a file, any side effects will occur at load time and a scope object with all the top level definitions from the file will be returned. &nbsp;This can be assigned to a variable and values and functions can be accessed without worrying about collisions within the current scope.

Suppose we have a file located at src/hello_world.grid relative to the current directory with the following content.
</span></font></span></p><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"></span></font></span></p><pre class="prettyprint"><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">var sayHelloTo = [name] { println( strf( "Hello %s" List(name) ) ) }</font></pre><p></p></blockquote><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">To load this file, simply call the built in load function.
</span></font></span></p><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"></span></font></span></p><pre class="prettyprint"><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">var ns = load( "src/hello_world.grid" )</font></pre><p></p></blockquote><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"></span></font></span></p><pre class="prettyprint"><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">ns.sayHelloTo( "Flynn" )</font></pre><p></p></blockquote><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">If you do not want to namespace any particular functions it is possible to map them into the curent scope by simply assigning them to a variable.
</span></font></span></p><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"></span></font></span></p><pre class="prettyprint"><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">var sayHelloTo = ns.sayHelloTo</font></pre><p></p></blockquote><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" style="font-size: 1.5625em; "><b>Operators</b></font></span></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">Math + - * / % ^

Logic &amp;&amp; ||

Comparison == != &lt; &lt;= &gt; &gt;=
<br /></span></font></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" style="font-size: 1.5625em; "><b>Control Flow</b></font><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><br /></font></span></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">There are built in functions for conditionals, looping, exceptions and exception handling.

Conditionals
</font></span></span></p><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"></font></span></span></p><pre class="prettyprint"><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">if ( true println( "true" ) println( "false" ) )</font></pre><p></p></blockquote><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"></font></span></span></p><pre class="prettyprint"><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">if ( &lt;cond&gt;&lt;true expr&gt; &lt;false expr&gt; )</font></pre><p></p></blockquote><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">Looping
</font></span></span></p><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"></font></span></span></p><pre class="prettyprint"><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">loop( &lt;structure&gt; &lt;function&gt; )</font></pre><p></p></blockquote><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">The function passed to loop must have two parameters, the value for each iteration and in the index number of the iteration (zero based).
</font></span></span></p><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"></font></span></span></p><pre class="prettyprint"><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">while( &lt;condition&gt; &lt;block&gt; )</font></pre><p></p></blockquote><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">Exceptions
</font></span></span></p><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"></font></span></span></p><pre class="prettyprint"><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">var err = error( "Uh oh" )</font></pre><p></p></blockquote><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"></font></span></span></p><pre class="prettyprint"><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">raise( err )</font></pre><p></p></blockquote><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"></font></span></span></p><pre class="prettyprint"><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">try ( &lt;block&gt; &lt;finally-block&gt; )</font></pre><p></p></blockquote><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">But what about catching the exceptions? &nbsp;A try block does not return the result of the block, it returns an object that contains a boolean indicating whether or not an exception was thrown and either the exception or the resultant value. &nbsp;It is therefore possible to access slots on the resultant prototype to perform whatever error handling is necessary.
</font></span></span></p><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"></font></span></span></p><pre class="prettyprint"><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">var t = try( socket.write() socket.close() )</font></pre><p></p></blockquote><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"></font></span></span></p><pre class="prettyprint"><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">if ( t.hasError raise( t.error ) t.result )</font></pre><p></p></blockquote><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" style="font-size: 1.5625em; "><b>Composite Data Structures</b></font><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><br /></font></span></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">There are lists. There is a built in function to construct them and they can contain an object of any type. &nbsp;Lists are zero indexed for access operations.
</font></span></span></p><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"></font></span></span></p><pre class="prettyprint"><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">var names = List( "Kevin", "Sam", "Quorra" )</font></pre><p></p></blockquote><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"></font></span></span></p><pre class="prettyprint"><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">println( names.get( 1 ) )</font></pre><p></p></blockquote><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" style="font-size: 1.953125em; "><b>Because I have to...</b></font><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><br /></font></span></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">Hello World
</font></span></span></p><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"></font></span></span></p><pre class="prettyprint"><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">println( "Hello world!" )</font></pre><p></p></blockquote><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">Factorial
</font></span></span></p><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"></font></span></span></p><pre class="prettyprint"><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">var fac = [n] {<br />&nbsp;&nbsp;&nbsp;&nbsp;if ( n == 0 || n == 1<br />&nbsp;&nbsp;&nbsp;&nbsp;1<br />&nbsp;&nbsp;&nbsp;&nbsp;n * recur( n - 1 )&nbsp;&nbsp;)<br />}<br /></font></pre><p></p></blockquote><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">In protogrid, recursion is achieved by calling the recur function instead of the current function by name.
<br /></font></span></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" style="font-size: 1.953125em; "><b>Getting started</b></font><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif"><br /></font></span></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">The best way to get started is to download the executable protogrid jar and start experimenting with the REPL. &nbsp;Syntax highlighting for IntelliJ IDEA and TextMate will be added to github in the very near future.
<br /></font></span></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="line-height: 20px; "><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font class="Apple-style-span" style="font-size: 1.5625em; "><b>Down the road</b></font><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">
</font></span></span></p><ul><li><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">Syntax highlighting</font></li><li><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">Compiled version</font></li><li><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">Debugger</font></li><li><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">Static typing</font></li><li><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">Lazy evaluation</font></li><li><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">Macros</font></li><li><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">Named arguments</font></li><li><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">Default values for parameters</font></li><li><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">Richer Java interop</font></li><li><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">De-structuring</font></li><li><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">Targeting other platforms</font></li></ul><font class="Apple-style-span" face="'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif">
<br /></font><p></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="border-collapse: collapse; font-family: 'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif; font-size: 11px; line-height: 20px; white-space: pre-wrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><br /></span></p> <p></p>
]]></description>
            <link>http://www.nearinfinity.com/blogs/bryan_weber/introducing_protogrid.html</link>
            <guid>http://www.nearinfinity.com/blogs/bryan_weber/introducing_protogrid.html</guid>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">protogrid</category>
            
            <pubDate>Mon, 18 Apr 2011 21:40:48 -0500</pubDate>
        </item>
        
        <item>
            <title>JVM Language Summit 2009 - Day 3</title>
            <description><![CDATA[Terrance Parr - ANTLR<div><br /></div><div>Terrance is entertaining and energetic. &nbsp;He showed some of the challenges ANTLR faces and had some requests from the JVM that are slightly different from most of the language implementors.</div><div><br /></div><div>Stadler - JVM Continuations</div><div><br /></div><div>Another research talk. &nbsp;The definition of continuations caused a side discussion, but I really enjoyed this talk. &nbsp;It is only implemented in the c1 client compiler. &nbsp;Security (serialization) and finally blocks are some of the unanswered questions here.</div><div><br /></div><div>Wimmer - trace-based JIT</div><div><br /></div><div>More research (UC-Irvine, but really more from Linz). &nbsp;Discussed TCO, client compiler visualization tool and trace based JIT. &nbsp;Uses traces and not just heuristics to identify hotspots for compilation. &nbsp;Works with blocks as well as methods. &nbsp;Think tracemonkey for Hotspot.</div><div><br /></div><div>Gafter - Static dynamic types</div><div><br /></div><div>Neal spoke about the new dynamic keyword in C# and the DLR. &nbsp;Described the DLR as basically a MOP. &nbsp;I would love to see a clean language implementation on the JVM with this sort of type system.</div><div><br /></div><div>Siek - Blame tracking</div><div><br /></div><div>Blame tracking is tracking type problems in dynamic languages and blaming the proper point in the code that made the initial improper call. &nbsp;It also works for mixed static/dynamic type systems. &nbsp;Currently it only identifies the outmost problem for space efficiency reasons.</div><div><br /></div><div>Field - JavaFX binding</div><div><br /></div><div>Bindings are handled by the creation of locations which can be pretty inefficient. &nbsp;This talk went through the various rounds of attempting to make bindings fast(er).</div><div><br /></div><div>Baker - Jython</div><div><br /></div><div>History of Jython. &nbsp;Optimizations. &nbsp;Mostly discussed the libraries and future direction.</div><div><br /></div><div>Remi Forax - 292 (invoke dynamic aka indy) backport</div><div><br /></div><div>Backport works via proxies and code weaving since the byte code instruction is not available. &nbsp;Two transformations occur via Java agents and the performance is very respectable. &nbsp;It works with JDK 5 and 6.</div><div><br /></div><div>The final session (not recorded) was by Slava on the Factor programming language compiler. Factor is a stack based language like Forth that does NOT run on the JVM. &nbsp;This session was awesome. &nbsp;While there weren't any new compiler optimizations that I hadn't heard of previously, it is very impressive was Slava has done with Factor. &nbsp;If you haven't ever checked it out, the url is&nbsp;<a href="http://factorcode.org/">http://factorcode.org/</a>&nbsp;&nbsp;Again, kudos to Sun for inviting non-JVM participants, it really adds to the quality of the event imho.</div><div><br /></div><div>PS Linux doesn't work well for presentations. :)</div><div>PPS People want TCO</div><div>PPPS 64k byte limit in methods is a problem</div><div>PPPPS The amount of cooperation among projects seems to have increased significantly since last year</div><div>PPPPPS Startup time needs to be improved</div>]]></description>
            <link>http://www.nearinfinity.com/blogs/bryan_weber/jvm_language_summit_2009_-_day_2.html</link>
            <guid>http://www.nearinfinity.com/blogs/bryan_weber/jvm_language_summit_2009_-_day_2.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Java</category>
            
            
            <pubDate>Fri, 18 Sep 2009 12:54:58 -0500</pubDate>
        </item>
        
        <item>
            <title>JVM Language Summit 2009 - Day 2</title>
            <description><![CDATA[<div>While day 1 focused on invokedynamic day 2 focused on time and locality. &nbsp;</div><div><br /></div>Hickey keynote<div><br /></div><div>Very thought provoking. &nbsp;Argued for immutable data structures and pure functions, but with time transitions and observers. &nbsp;Nice pragmatic response in a way to Erik Meijer's Fundamentalist Functional Programming from last year's JVM language Summit. &nbsp;This was somewhat a philosophical presentation, but much like last year it made me want to re-visit Clojure. &nbsp;Here is a better summary than I could have written:&nbsp;<a href="http://wiki.jvmlangsummit.com/Clojure_Keynote">http://wiki.jvmlangsummit.com/Clojure_Keynote</a></div><div><br /><div>Cliff Click</div><div><br /></div><div>Awesome scheduling to put this immediately after Rich's talk. &nbsp;Cliff offered up four presentations and the audience overwhelmingly chose the one about x86. &nbsp;Interestingly this had some similar theories to Rich's talk (time and locality), but at an extremely low level.</div><div><br /></div><div>Hotswap</div><div><br /></div><div>Research presentation from European students that have partnered with Sun. &nbsp;This was interesting, but the limitations make it not that useful for real production code hotswapping in my opinion.</div><div><br /></div><div>Groovy</div><div><br /></div><div>This talk by Theodorou focused on the performance of Groovy and was almost an advertisement for not using Groovy. &nbsp;Of course the performance of Groovy doesn't match Java, but it is really bad in some instances. &nbsp;The moral was use Java where performance is necessary.</div><div><br /></div><div>Sun update</div><div><br /></div><div>This was probably not recorded, but Octavian took hard questions from Josh Bloch, Neal Gafter and others. &nbsp;Hopefully the departure of key Sun employees ends up helping Sun in the long run. &nbsp;In my opinion Sun is overestimating the value of the Java store.</div><div><br /></div><div>Erik Meijer</div><div><br /></div><div>Not nearly as entertaining as last year's talk, but still interesting and based on mathematics. &nbsp;Erik was looking for solutions to concurrency and resource cleanup problems that are difficult and that currently have no "clean" solution.</div><div><br /></div><div>JRocket</div><div><br /></div><div>Frederik's talk focused mostly on anti-optimizations and basically asked the language designers to not try to implement optimizations that are also performed by the JVM. &nbsp;The audience was hoping for specific patterns more than Frederik offered up, but Frederik is clearly very knowledgeable about JRocket and the JVM specification.</div><div><br /></div><div>Ioke</div><div><br /></div><div>Ola tried to give a one hour introduction to Ioke in 30 minutes and by his own admission it did not work out that well. &nbsp;Many in the audience were not familiar with the syntax of IO which originally inspired Ioke and that did not help him very much. &nbsp;The BNF was shown much more than actual source examples.</div><div><br /></div><div>Dinner</div><div><br /></div><div>Dinner was at Faultine which has good food and terrible acoustics. &nbsp;Aside from having to scream at the people sitting near me it was a brilliant time. &nbsp;Dick Wall of the Java Posse was very friendly and a fantastic ambassador for the Java/Scala community. &nbsp;If you aren't familiar with the Java Posse podcast then I suggest you check it out on iTunes or at&nbsp;<a href="http://javaposse.com/">http://javaposse.com/</a>. Their google group and mailing list are also interesting.</div><div><br /></div><div><br /></div><div><br /></div></div>]]></description>
            <link>http://www.nearinfinity.com/blogs/bryan_weber/jvm_language_summit_2009_-_day_1.html</link>
            <guid>http://www.nearinfinity.com/blogs/bryan_weber/jvm_language_summit_2009_-_day_1.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Java</category>
            
            
            <pubDate>Fri, 18 Sep 2009 11:57:43 -0500</pubDate>
        </item>
        
        <item>
            <title>JVM Language Summit 2009 - Day 1</title>
            <description><![CDATA[Day 1 of the 2nd annual JVM language summit at Sun Microsystems has come to a close. &nbsp;Once again this conference has had excellent content in the presentations. &nbsp;My overall impression of today was that many projects (JRuby, Atilla's MOP, etc) already have done significant work on integrating invoke dynamic.&nbsp;<div><br /></div><div>And once again Sun was smart enough to invite non-JVM participants. &nbsp;Today was Allison Randal from Parrot. &nbsp;Tomorrow will include Erik Meijer of Microsoft and Haskell fame. I would love to see him top his presentation from last year, it will be difficult.<div><br /></div><div>Charlie Nutter (of Engine Yard, still not quite used to that) talked about JRuby, Duby and Surinx. &nbsp;</div><div><br /></div><div>Mark Reinhold talked about the JDK, Atilla spoke about his MOP framework, Miles Sabin spoke about Scala tooling, and David Pollack spoke about Scala basics.<br /><div><br /></div><div>The JVM presentations were interesting, but the best material was at dinner. &nbsp;Sorry to non-attendees, that won't be on InfoQ later.</div><div><br /></div><div>John Rose's breakout session was the highlight of Day 1 for me. &nbsp;It is really fun to think about the parts of the implementation of Method Handles that do not have solutions yet or where certain features could be taken in the future.&nbsp;</div><div><br /></div><div>One of the breakout sessions was on Noop.&nbsp;<a href="http://code.google.com/p/noop/">http://code.google.com/p/noop/</a>&nbsp;This reminded me of the Fan programming language from last year's event. &nbsp;Only Fan has a real implementation and noop is more or less in the vaporware phase at this point in time. &nbsp;The two goals of noop are easy testing (even of legacy code) and readability. &nbsp;As conceived today it is not going to achieve either to the degree the implementors would like IMHO. &nbsp;It almost reminds me of turning Guice into a programming language...</div><div><br /></div><div>Oh yeah, and if you didn't already know, Brian Goetz knows a lot about concurrency. &nbsp;A whole lot. &nbsp;He was able to detect a concurrency bug in sample code that fit on one slide after a few seconds of reading it. &nbsp;</div><div><br /></div><div>Tomorrow's schedule is jam packed with presentations that interest me. &nbsp;Will post more tomorrow night!</div></div></div>]]></description>
            <link>http://www.nearinfinity.com/blogs/bryan_weber/jvm_language_summit_2009_-_day.html</link>
            <guid>http://www.nearinfinity.com/blogs/bryan_weber/jvm_language_summit_2009_-_day.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Java</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">JVM</category>
            
            <pubDate>Wed, 16 Sep 2009 12:05:57 -0500</pubDate>
        </item>
        
        <item>
            <title>Day 3 of the JVM Language Summit</title>
            <description><![CDATA[<p>
By far the most entertaining and most thought provoking presentation of the JVM language summit was given by Erik Meijer (and by a <i>large</i> margin). Unfortunately, it was not recorded and will not be on InfoQ like many of the other presentations as far as I know.  His talk was called Fundamentalist Functional Programming which is basically his way of advocating pure functional languages (read: Haskell although he did mention Clean as well).  He argued that any impure functional language is NOT a functional language.  Either you are pure or you happen to have some features of functional programming languages.  And he did this in a <b>wildly</b> entertaining manner.  I've personally been looking at Haskell recently so this talk was very timely and informative.  How often do you see a presentation where someone suggests that Computer Science has gone in completely the wrong direction the past 50 years and needs to get back on track and has some ammo to back it up?  I think many people in the audience found it entertaining, but not really practical.  To that I would ask, why not?  How many times a day do you say to yourself "there must be a better way?"  Maybe this would be a quantum leap?  I'm still exploring Haskell and I think that it might not be the solution, but it might <i>inspire</i> a better way.  I've found many people on the Haskell IRC channel (which is extremely active) to be very helpful, but the documentation about Haskell will scare away most programmers.  The concepts aren't hard, but if you read the <a href="http://en.wikibooks.org/wiki/Haskell">wikibook</a> you will likely come away with the impression that only PhDs in Mathematics can learn Haskell.  <a href="http://book.realworldhaskell.org/read/">Real World Hasekll</a> seems better, but still lacks that killer intro that will grab the attention of the masses (and maybe they don't want the masses...).  Erik's presentation was passionate and you could tell that he really believes that pure functional programming is the future.
</p>

<p>
Cliff Click's demo of <a href="http://www.azulsystems.com/">Azul Systems</a> tool was very, very impressive (and only about a dozen people saw it).  His presentation was also good.  This type of low level HotSpot support is necessary for language designers who are serious about performance and $40k seemed reasonable for a machine if you get Cliff's expertise along with it!
</p>

<p>
In addition to some C# by Mads, Allison Randal spoke about the Parrot VM. I was happy to see that Sun had the openness to invite Microsoft and Parrot to take part. I think that it really added to the quality of the summit.  Google had some folks present, but didn't really talk about how they use the JVM.  Next year, I would love to see some more activity from Google.
</p>

<p>
<a href="http://www.parrotcode.org/">Parrot</a> is a register based VM which makes some things (ie continuations) easier to implement, but I think that it might be quite some time before the performance can match the HotSpot JVM for most things. Parrot has been around for 7 years so they just have not had as much time (and money?) to devote to making it as mature as the JVM.  
</p>

<p>
Thinking about going to the JVM language summit next year?  I highly recommend the event, but it is a small group of highly experienced language designers.  So the following words should not scare you:  invariant, covariance, type erasure, continuations, tail call optimization, etc.  You probably also should have some experience implementing your own language and/or working extensively at the byte code level.  It will also help to be familiar with the symbols used to describe type systems.  I don't mean to scare anyone away, but I recommend that you make an honest assessment if the event is right for you.  Otherwise you might have a good time but not be able to take part in the conversations. If this is your thing, Microsoft also has a <a href="http://www.langnetsymposium.com/">Lang.NET</a> conference you might want to check out.
</p>

<p>
My only suggestion to Sun: use a room with a screen that is elevated a little more so the entire room can see the full screen.
</p>

<h2>Summary</h2>

<ul>
<li>LINQ - Functional programming features in C#.</li>
<li>Kawa - Scheme without full continuations.</li>
<li>Fundamentalist Functional Programming - Turn your world upside down presentation.  Described in detail above.</li>
<li>NetRexx - An old IBM scripting language that has been open sourced.</li>
<li>Scalify - Library to take Java code as input and produce Scala as output.  Looking for others to join to add Java -&gt; "other JVM language" implementations as well.</li>
<li>Closures and the JVM - Mostly discussed language interoperability on the JVM and the problems languages face when trying to use libraries written in other languages (with Java being somewhat of an exception).  If you haven't heard by now, Neal is also working for Microsoft.</li>
<li>Bytecodes for fast JVMs - Showed low level metrics for Clojure, JRuby and Jython.  Cliff was able to identify areas where teams thought that something was being inlined, but in fact was not.</li>
<li>Jatha Common Lisp - What Ola Bini worked on before JRuby.</li>
<li>Parrot VM - Register based VM. </li>
</ul>

<p>
Many thanks to Sun for hosting a spectacular event.  In particular, thank you John Rose for taking the time on several occasions to chat.  I know you were very busy.
</p>]]></description>
            <link>http://www.nearinfinity.com/blogs/bryan_weber/day_3_of_the_jvm.html</link>
            <guid>http://www.nearinfinity.com/blogs/bryan_weber/day_3_of_the_jvm.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Java</category>
            
            
            <pubDate>Sat, 27 Sep 2008 13:34:12 -0500</pubDate>
        </item>
        
        <item>
            <title>Day 2 of the JVM Language Summit</title>
            <description><![CDATA[<p>Well, how often do you get to speak to an employee of Sun, Google and Microsoft in the same day?  And not just any employee, but some of their best and brightest?  Needless to say, day 2 was loads of fun.  And I got to ask Erik Meijer exactly how many tie-dye shirts does he own... I've always wondered that.
</p>

<p>
Overall impressions: many people here are "into" functional programming languages.  Concurrency is another big topic.  This conference has just the right blend of academia and "real world" for me.  It is very technical, but not so full of Greek letters that your head hurts.
</p>

<ul>
<li>Gosling keynote - History of Java.</li>
<li>JavaFX - How they use javac to compile JavaFX.</li>
<li>JRuby - How they have blazed the trail for dynamic languages on the JVM.</li>
<li>ASM - The library for byte code manipulation.</li>
<li>PHP - Not totally sure why, but they are working on it. Overall, I think its good to have as many mainstream languages on the JVM as possible.</li>
<li>MOP - Metaobject protocol for passing objects between dynamic languages on the JVM. Like the idea, not sure sure about the implementation.</li>
<li>invokedynamic backport - I can't get enough details about invokedynamic.</li>
<li>Clojure - Functional language on the JVM.  The highlight of the day for me.  It's not 100% what I would like to see, but it is the closest yet.</li>
<li>Python gradual typing - Typing notation makes your head spin, but a very good talk.</li>
<li>Jython - Sort of opposite situation from the CLR/DLR.  On the DLR IronPython came before IronRuby and Ruby.NET and really blazed the trail.  On the JVM Jython has been around, but they seem to be in a complete re-write and are really leveraging a lot from JRuby (and that is very, very good).</li>
</ul>

<p>
Final observation:  I'm very impressed with how approachable the 80 or so odd people here are, especially the Sun employees.  Granted they are the hosts, but they have really taken their time to interact with the participants (as they should because I really don't think that they would want to alienate this crowd in particular!).
</p>]]></description>
            <link>http://www.nearinfinity.com/blogs/bryan_weber/day_2_of_the_jvm.html</link>
            <guid>http://www.nearinfinity.com/blogs/bryan_weber/day_2_of_the_jvm.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Java</category>
            
            
            <pubDate>Fri, 26 Sep 2008 00:35:57 -0500</pubDate>
        </item>
        
        <item>
            <title>Day 1 of the JVM Language Summit</title>
            <description><![CDATA[<h2>JVM Language Summit - Day 1</h2>

<p>Day 1 of the JVM language summit in Santa Clara has come and gone.  The agenda can be found at <a href="http://openjdk.java.net/projects/mlvm/jvmlangsummit/agenda.html">Agenda</a>.
</p>


<p>
The highlight of day 1 for me was John Rose talking about invokedynamic.  A lot of attendees really liked the talks about Fortress and multiple dispatch, but invokedynamic was the most relevant to me.  And best of all a Sun employee said that invokedynamic would be part of Java 7.  Now, that doesn't mean anything, but it is encouraging to hear that Sun is committed to getting it included in Java 7.
</p>

<p>
The surprise of the day for me was the presentation on Fan.  I had not heard of fan prior to signing up for the event.  It seems like it is still pretty immature, but it is interesting.  The language is being created from the ground up to run on the JVM and CLR.  They have spent most of their time making libraries that can be built on top of both platforms. The big problem is that you can't call out to the multitudes of libraries available on those platforms.  This is a show stopper for now.
</p>

<p>
Stu's lightning talk started the best conversation of the day.  The open sessions, or unconference or whatever term you prefer, were not nearly as successful at getting people talking about issues as Stu's presentation.  The conversation focused on how libraries can be provided on the JVM in the best of breed language for that particular problem and just as importantly how the library can be used by other languages on the JVM.  This second part is the part that there is no clear answer for right now.  Clojure's collections and the regex library in JRuby were used as examples of libraries that could be shared by lots of languages implemented on the JVM. 
</p>

<h2>Summary</h2>
<ul>
<li>Hotspot - Just an intro to the event.</li>
<li>invokedynamic - Read <a href="http://blog.headius.com/2008/09/first-taste-of-invokedynamic.html">headius' blog</a> if you'd like to know more.</li>
<li>Maxine - An experimental VM.  Not compliant yet.  Has an API.</li>
<li>Fan - new language to run on JVM and CLR.</li>
<li>Groovy - Intro to Groovy</li>
<li>Scala - Focused on one aspect of Scala</li>
<li>Fortress - Fortran on the JVM with concurrency, lots of it.  They came the most prepared to make recommendations to Sun of features that could be added to the JVM.  The list contained things like continuations, value objects, etc.</li>
<li>Multiple dispatch - Professor's implementation of how multiple dispatch could be done on the JVM quickly and without too much disruption.</li>
</ul>]]></description>
            <link>http://www.nearinfinity.com/blogs/bryan_weber/day_1_of_the_jvm.html</link>
            <guid>http://www.nearinfinity.com/blogs/bryan_weber/day_1_of_the_jvm.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Java</category>
            
            
            <pubDate>Wed, 24 Sep 2008 23:57:52 -0500</pubDate>
        </item>
        
        <item>
            <title>Code Reviews</title>
            <description><![CDATA[<h2>Proposed code review process</h2>

<ul>
<li>Identify piece(s) of code to review</li>
<li>Notify reviewers</li> 
<li>Assign grades based on the following criteria</li>
<ul>
<li>Design</li>
<li>Cleanliness</li>
<li>Test Quality and Coverage</li>
<li>Documentation</li>
<li>Accuracy Against Estimate</li>
<li>Simplicity</li>
<li>Meets Requirements</li>
<li>Working as Designed</li>
<li>Positive User Experience</li>
</ul>
<li>Meet to discuss the grades</li>
<li>Take corrective action</li>
</ul>

<h3>Comments</h3>
<ul>
<li>The list of criteria is not set in stone or some magical list of categories.  These are based on my own personal experiences. You should modify the list as you see fit for your team.  For example, if performance or security is critical to your mission, then they should receive special attention!
</li>

<li>
The categories can be weighted to stress certain areas.  This can be useful if a team (NOT an individual) needs to stress one area versus other areas.  The weights may change over time.
</li>

<li>
Use a grading system that you feel best applies to your software team's practices.  This can be a letter grade (A,B,C,D,F), a numerical score (1,2,3,4) or something completely different.
</li>

<li>
The focus should be on the code and not the developer(s).  This is not an assessment of team member(s), it is a review of the code after all!  Therefore, do not select pieces of code worked on by a developer, rather select code related to your user stories. 
</li>

<li>
Use a tool (such as a wiki, issue tracking tool or planning tool) to track your code reviews AND technical debt that is discovered as a result of the code review. 
</li>

<li>
DO SOMETHING ABOUT IT.  Many organizations conduct code reviews and little corrective action is taken.  Be sure to schedule time to address issues uncovered in code reviews!
</li>
</ul>

<h2>Looking for feedback!</h2>
I'm looking for feedback on this topic.  So if you have any comments please either add a comment to this blog post or shoot me an email at bweber at the domain of this website.]]></description>
            <link>http://www.nearinfinity.com/blogs/bryan_weber/code_reviews.html</link>
            <guid>http://www.nearinfinity.com/blogs/bryan_weber/code_reviews.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">General</category>
            
            
            <pubDate>Thu, 24 Jul 2008 11:01:21 -0500</pubDate>
        </item>
        
        <item>
            <title>Well formed parenthesis pairs</title>
            <description><![CDATA[<p>
A friend came to me recently and posed an interesting problem.  Given a number n how many valid balanced open/close parenthesis combinations are there?
</p>

<p>
Examples:<br />

<br />
n == 4<br />

</p><ol>
<li>()()</li>
<li>(())</li>
</ol>

<br />
n == 6<br />

<ol>
<li>()()()</li>
<li>(()())</li>
<li>()(())</li>
<li>(())()</li>
<li>((()))</li>
</ol>


<p>
His solution:
</p><ul>
<li>The number n must be even</li>
<li>Treat '(' as 1</li>
<li>Treat ')' as 0</li>
<li>The minimal value will be "10" n/2 times. ie 101010</li>
<li>The maximum value will be "1" n/2 times followed by "0" n/2 times. ie 111000</li>
<li>The odd parity must be n/2</li>
<li>The even parity must be n/2</li>
<li>The combinations must be well formed ie (()) and not ))((</li>
</ul>


<p>
The algorithm to solve the problem went like this:  Say n is 8, loop from 10101010 to 11110000 by 2's (to exclude odd numbers), make sure that the even parity equals n/2 and that the odd parity equals n/2.  For each number loop over the bits and add +1 for 1 and subtract -1 for 0.  Throw out any number that goes below 0 at any point.
</p>

<p>
This algorithm will get you to the correct solution but the solution involved heuristics and considered some invalid combinations.  I was sure that there was a way to solve this problem without considering any invalid combinations and I was right.  Here is my solution (with an implementation in ruby):
</p>

<p>
Note: I would not be surprised if there is a mathematically more efficient way to solve this problem, but this is what I came up with.
</p>

<p>
</p><ol>
<li>Create a grid of all the possibilities.</li>
<li>Create a directed graph.</li>
<li>Walk the graph from the end to the beginning.</li>
</ol>


<p>
I am including four figures now that I will reference below.
</p>

<span class="mt-enclosure mt-enclosure-image" style="display: inline;"><a href="http://www.nearinfinity.com/blogs/assets/bweber/parenthesis%20blog%20slide%201.png"><img alt="parenthesis blog slide 1.png" src="http://www.nearinfinity.com/blogs/assets_c/2008/12/parenthesis%20blog%20slide%201-thumb-600x776.png" class="mt-image-none" style="" height="776" width="600" /></a></span>

<br /><br />

<span class="mt-enclosure mt-enclosure-image" style="display: inline;"><a href="http://www.nearinfinity.com/blogs/assets/bweber/parenthesis%20blog%20slide%203.png"><img alt="parenthesis blog slide 2.png" src="http://www.nearinfinity.com/blogs/assets_c/2008/12/parenthesis%20blog%20slide%203-thumb-600x776.png" class="mt-image-none" style="" height="776" width="600" /></a></span>

<p>
Create a grid of all the possibilities.  Thinking in terms of a turn based stack, the blue squares in figure A can be ruled out as invalid.
</p>

<p>
Create a directed graph.  Again thinking in terms of our stack, there are only two possible operations, push and pop.  So as we move from turn 1 to turn 2 we must go either up and to the right OR down and to the right.  I also consider the two possible incoming points because my directed graph is bi-directional (think in terms of a doubly linked list).  So for the point (0,0) we can see the four possibilities in figure B.  They are (-1,1), (-1,-1), (1,-1) and (1,1).  Of these four only the point (1,1) falls in a yellow square and is therefore "valid". We then move on to this point and repeat the process until we end up at point (n,0) which is always our last point.  At this point our data structure looks like diagram C.
</p>

<p>
Finally, we have to walk our structure to determine all the valid combinations.  My first thought was to walk from the point (0,0) to (n,0) but I ended up walking from the end to the beginning!  (Either way works, but I found the code easier to write going in the opposite direction).  Using the labels from diagram D we see the valid combinations are:

</p><ul>
<li>J I H F D B A</li>
<li>J I H E D B A</li>
<li>J I H E C B A</li>
<li>J I G E D B A</li>
<li>J I G E C B A</li>
</ul>

Note 1: My algorithm to walk the data structure is not perfect.  The algorithm is recursive but not tail recursive so for very large data structures memory could be an issue. The maximum number of stack frames will be equal to n.
Note 2: The algorithm takes a long time for large numbers because there are many, many valid combinations to consider.  In real life, this algorithm would have to be modified to parallelize the effort across processors/machines.


<p>
And finally, the ruby code!

</p><pre class="prettyprint">class DirectedBinaryGraphNode
  attr_accessor :last_lower, :last_higher, :next_lower, :next_higher, :x, :y
  def initialize(x,y)
    @x = x; @y = y
  end
  def to_s()
    "#{x}, #{y}"
  end
end

def validate_node(n,index)
  x = index[0]; y = index[1]
  width = x &gt;= 0 and x &lt;= n
  vertical = (x &lt; (n/2)) ? x : (n-x)
  height = (y &gt;= 0 and y &lt;= vertical)
  x &lt;= n and width and height
end

def ensure_node(index,n) 
  if ( @nodes[index] ) then
    node = @nodes[index]
  else
    node = DirectedBinaryGraphNode.new(index[0],index[1])
    @nodes[index] = node
    create_node(n,node)
  end
  node
end

def create_node(n,node)
  puts "creating node #{node}"
  last_lower = [node.x-1,node.y-1]
  last_higher = [node.x-1,node.y+1]
  node.last_lower = ensure_node(last_lower,n) if validate_node(n,last_lower)
  node.last_higher = ensure_node(last_higher,n) if validate_node(n,last_higher)
  next_lower = [node.x+1,node.y-1]
  next_higher = [node.x+1,node.y+1]
  node.next_lower = ensure_node(next_lower,n) if validate_node(n,next_lower)
  node.next_higher = ensure_node(next_higher,n) if validate_node(n,next_higher)
end

def create_data_structure(n)  
  @nodes[[0,0]] = DirectedBinaryGraphNode.new(0,0) 
  create_node(n,@nodes[[0,0]]) 
end

def walk_data_structure(str,last)
  if ( last.last_lower) then
    walk_data_structure("(" + str,last.last_lower)
  end
  if ( last.last_higher) then
    walk_data_structure(")" + str,last.last_higher) 
  end 
  unless last.last_lower or last.last_higher then
    @cnt = @cnt + 1
    puts "Valid combo: #{str}"
  end
end

n = ARGV[0].to_i
unless ( n % 2 == 0 ) then
  puts "invalid parameter #{n} [it must be even]"
  exit -1
end
@nodes = {}; @cnt = 0
create_data_structure(n)
walk_data_structure("",@nodes[[n,0]])
puts "Total number: #{@cnt}"

</pre>
]]></description>
            <link>http://www.nearinfinity.com/blogs/bryan_weber/well_formed_parenthesis_pairs.html</link>
            <guid>http://www.nearinfinity.com/blogs/bryan_weber/well_formed_parenthesis_pairs.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">General</category>
            
            
            <pubDate>Mon, 16 Jun 2008 00:08:59 -0500</pubDate>
        </item>
        
        <item>
            <title>Configuring easyb with maven 2 (maven-easyb-plugin)</title>
            <description><![CDATA[If you aren't familiar with BDD then this blog isn't for you.  If you've used RSpec or you have read a little about BDD and you want to kick the tires with a very simple BDD implementation in Groovy (aka easyb) and you want to use maven 2, then maybe you will get a tiny bit of use from this.

<br /><br />
Here is a fully functional pom file that works with easyb 0.8 and maven-easyb-plugin 0.8.  
<pre class="prettyprint lang-xml">
&lt;project&gt;

  &lt;modelversion&gt;4.0.0&lt;/modelversion&gt;
  &lt;groupid&gt;com.trial.easyb&lt;/groupid&gt;
  &lt;artifactid&gt;easyb-trial&lt;/artifactid&gt;
  &lt;version&gt;0.1&lt;/version&gt;

  &lt;dependencies&gt;
    &lt;dependency&gt;
        &lt;groupid&gt;org.easyb&lt;/groupid&gt;
        &lt;artifactid&gt;easyb&lt;/artifactid&gt;
        &lt;version&gt;0.8&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupid&gt;junit&lt;/groupid&gt;
        &lt;artifactid&gt;junit&lt;/artifactid&gt;
        &lt;version&gt;4.4&lt;/version&gt;
    &lt;/dependency&gt;
  &lt;/dependencies&gt;

  &lt;repositories&gt;
    &lt;repository&gt;
      &lt;id&gt;easyb&lt;/id&gt;
      &lt;url&gt;http://www.easyb.org/repo/&lt;/url&gt;
    &lt;/repository&gt;
  &lt;/repositories&gt;
  &lt;pluginrepositories&gt;
    &lt;pluginrepository&gt;
      &lt;id&gt;easyb&lt;/id&gt;
      &lt;url&gt;http://www.easyb.org/repo/&lt;/url&gt;
    &lt;/pluginrepository&gt;
  &lt;/pluginrepositories&gt;

  &lt;build&gt;
    &lt;plugins&gt;
      &lt;plugin&gt;
        &lt;groupid&gt;org.easyb&lt;/groupid&gt;
        &lt;artifactid&gt;maven-easyb-plugin&lt;/artifactid&gt;
        &lt;version&gt;0.8&lt;/version&gt;
        &lt;executions&gt;
          &lt;execution&gt;
            &lt;goals&gt;
              &lt;goal&gt;test&lt;/goal&gt;
              &lt;goal&gt;storyReport&lt;/goal&gt;
            &lt;/goals&gt;
          &lt;/execution&gt;
        &lt;/executions&gt;
        &lt;configuration&gt;
          &lt;easybtestdirectory&gt;${basedir}/src/test/stories&lt;/easybtestdirectory&gt;
          &lt;storyreport&gt;${project.build.directory}/easyb-stories.txt&lt;/storyreport&gt;
          &lt;xmlreport&gt;${project.build.directory}/easyb/report.xml&lt;/xmlreport&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;
  &lt;/build&gt;  

&lt;/project&gt;
</pre>


Gotchas (at least it got me). For the maven-easyb-plugin easyb:storyReport goal:
<br /><br />
The pom file xmlReport configuration has a default value which is:
<br /><br />
          <xmlreport>${project.build.directory}/easyb/report.xml</xmlreport>

<br /><br />
If you change it (as per the maven-easyb-plugin documentation) be sure to change the the storyReport which is being renamed to xmlReport to help avoid confusion:
<br /><br />
          <xmlreport>${project.build.directory}/easyb-report.xml</xmlreport>
<br /><br />
So, to recap, if you change the value in the pom.xml file you MUST also pass in the storyReport (soon to be renamed to xmlReport) parameter to maven and they have to match.]]></description>
            <link>http://www.nearinfinity.com/blogs/bryan_weber/configuring_easyb_with_maven_2.html</link>
            <guid>http://www.nearinfinity.com/blogs/bryan_weber/configuring_easyb_with_maven_2.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Groovy</category>
            
            
            <pubDate>Tue, 29 Apr 2008 17:29:31 -0500</pubDate>
        </item>
        
        <item>
            <title>Addition to scala pattern matching</title>
            <description><![CDATA[I recently posted a blog post about <a href="http://www.nearinfinity.com/blogs/page/bweber?entry=scala_pattern_matching">scala pattern matching</a>.  It is intended to be an introduction to pattern matching concepts using Scala as the implementation.  I have been writing more scala code recently and I have come to the conclusion that pattern matching is missing one thing to really make it developer friendly, useful error messages!

<br />
<h1>Pattern Matching: What is missing?</h1>
<p>
Useful error messages.  Huh?  Why?  What are you proposing?
</p>

<br />
<h2>When all goes well</h2>
<p>
The code block associated with the case is executed.  All is fine here.
</p>

<br />
<h2>When there is no match</h2>
<p>
A scala.MatchError exception is thrown.  Herein lies the problem.  As a developer, I get a MatchError exception with a string that says that there was a match error.   If I look at the stack trace I can even figure out where things went wrong in the code.  But why can't I provide the match statement a String with a more developer/user friendly error message?  Why can't I say what there was no match for?  For example, suppose I am matching days of the week.  Wouldn't a message like "Unable to match the day of the week." be more useful then a general error simply stating that a MatchError was thrown?
</p>



<br />
<h2>When there is a type mismatch</h2>
<p>
If the data type of the thing being matched cannot be applied to any case in the match that gets executed a scala.MatchError is thrown.  Since this is a different type of error I would contend that it is fine as is.
</p>




<br />
<h2>Proposed modification</h2>
<p>
What if the match was passed a string with a user/developer friendly error message?  It <b>might</b> look something like this:

</p><pre class="prettyprint">  val user = "harry"
  user match "Unable to match the name against the list of Weasley boys" {
    case "fred" =&gt;
      println("this would not be good")
    case "george" =&gt;
      println("this also would not be good")
    case "ron" =&gt;
      println("again, not good")
    case "percy" =&gt;
      println("still not good")
  }
</pre>

So instead of seeing:<br />

<br />
Caused by: scala.MatchError: harry<br />

<br />
You could see:<br />

<br />
Caused by: scala.MatchError: Unable to match the name against the list of Weasley boys<br />

<br />
Hmmm... it seems that we are still missing the value that wasn't matched, so what about a Function?<br />

<pre class="prettyprint">  val user = "harry"
  user match (n) =&gt; "Unable to match the name " + n + " against the list of Weasley boys" {
    case "fred" =&gt;
      println("this would not be good")
    case "george" =&gt;
      println("this also would not be good")
    case "ron" =&gt;
      println("again, not good")
    case "percy" =&gt;
      println("still not good")
  }
</pre>

<br />
Or the ultimate version:<br />

<br />
Caused by: scala.MatchError: Unable to match the name harry against the list of Weasley boys<br /> 

<br /><br />
So to summarize, I would like to see match modified to be 1 of 3 possibilities:
<ol>
<li>As is :)</li>
<li>Match would take a string and use that as the message</li>
<li>Match would take a callback function and pass it the value not matched</li>
</ol>

PS If there are more Weasley boys.. fine, that's beside the point!]]></description>
            <link>http://www.nearinfinity.com/blogs/bryan_weber/addition_to_scala_pattern_matching.html</link>
            <guid>http://www.nearinfinity.com/blogs/bryan_weber/addition_to_scala_pattern_matching.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">General</category>
            
            
            <pubDate>Tue, 22 Apr 2008 17:51:25 -0500</pubDate>
        </item>
        
        <item>
            <title>Scala Pattern Matching</title>
            <description><![CDATA[Scala has pattern matching... so what's the big deal?  If you are a Java developer the power of pattern matching will probably be lost on you at first, but after you gain some experience with it a light will go on inside your head.  And if you are a functional programmer, then you would expect Scala to have nothing less than excellent support for pattern matching since it is a new language that is partially a functional language.  So what is pattern matching?  I don't know a formal definition, but it does several things and I will give an example of each.  But before we go any further, there are 2 concepts that work well with pattern matching (but are not required); tuples and case classes.  Both of these topics have been explained in numerous other blog posts so I will just post very short summaries here, but familiarizing yourself with these topics will further your understanding of the power of pattern matching.

<br />
<h2>Tuples</h2>
A tuple is a fixed size data structure that allows data to be of different types.  Scala has a convenient syntax for tuples that looks like this:  

<pre class="prettyprint">(1, 2.0, "three")
</pre>

Tuples are typically used instead of Lists or Arrays when the data types of the objects are not all the same.

<br />
<h2>Case Classes</h2> 
In scala a case class is a special type of class (with some restrictions) that "exports its constructor parameters".  So what does that mean?  It means that you conveniently create and compare instances of the class.  Pattern matching will even allow for some of the values to be compared and others to be set in one operation!

<pre class="prettyprint">case class Foo(firstData:Int, secondData:Int)
</pre>

<h2>Pattern Matching</h2>

<h3>First, pattern matching is a glorified switch statement.</h3>
<pre class="prettyprint">x match {
  case 1 =&gt;
    println("x is 1")
  case _ =&gt;
    println("x is not 1")
}
</pre>

<pre class="prettyprint">val x = Foo(3,5)
x match {
  case Foo(z,5) =&gt;
    println(z)
  case _ =&gt;
    println("we didn't have a match")
}
</pre>

This says try to match the value of x and when you find a case that is true, execute the code block associated with that case.  Don't forget that _ in Scala is like a wildcard character so it is like a set of all values except for the values from the previous case blocks because they were executed earlier. Scala's only advantage over Java here is that you can use objects and not just primitives or Enums for comparison.

<h3>Second, pattern matching is like built in assertions (well, sort of).</h3>

<pre class="prettyprint">x match {
  case 0 =&gt;
    println("x is 0")
  case 1 =&gt; 
    println("x is 1")
}
</pre>

So in this contrived binary checker, we check x for a value that is either 0 or 1.  So what would happen if x contained a value that was NOT 0 or 1?  A scala.MatchError exception would be thrown!  This allows for a clean form of defensive programming in that the developer does not have to handle all of the possible error conditions right here in the code.  The developer can code the "sucess cases" and let exceptions be thrown for the exception cases and those exceptions can be handled by an error handling layer someone else in the code.

<h3>Third, pattern matching is useful for variable assignment</h3> 
(assigning multiple variables on one line, assigning only certain variables, etc)  This is where tuples enter the picture again.

<pre class="prettyprint">val a = (1,2.0,"three")
val (d,e,f) = a
println(d)
println(e)
println(f)
</pre>

This will produce the following results:

<pre class="prettyprint">1
2.0
three
</pre>

Additionally, you could do:

<pre class="prettyprint">val a = (1,2.0,"three")
val (b,2.0,"three") = a
println(b)
</pre>

This will print out 1 as expected.  But NOTE that if the values in the second and third positions of the tuple did NOT match then an exception would have been thrown!  So you could NOT do:

<h3>The following example would throw an exception!</h3>
<pre class="prettyprint">val a = (1,2.0,"three")
val (b,2.0,"3") = a
println(b)
</pre>

<br /><br />
Many people like to think of pattern matching in this way. 
<ul>
<li>Do all of the bound variable values match?</li>
<li>If yes, then we have a match!</li>
<li>If not, what could the code do to make the statement true? (ie assign a value to an unbound variable...)</li>
</ul>

That's it for my brief intro to pattern matching.  Hopefully this helps shed some light if it is a new concept to you.]]></description>
            <link>http://www.nearinfinity.com/blogs/bryan_weber/scala_pattern_matching.html</link>
            <guid>http://www.nearinfinity.com/blogs/bryan_weber/scala_pattern_matching.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">General</category>
            
            
            <pubDate>Thu, 03 Apr 2008 23:06:49 -0500</pubDate>
        </item>
        
        <item>
            <title>Scala and Maven with maven-scala-plugin</title>
            <description><![CDATA[Ok, so the documentation for maven-scala-plugin isn't quite perfect.  To save you some time, here is a fully functional pom.xml file that works as of March 6, 2008.

<pre class="prettyprint">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;

    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;groupId&gt;mvn.scala.test&lt;/groupId&gt;
    &lt;artifactId&gt;mvn.scala.test&lt;/artifactId&gt;
    &lt;name&gt;Maven Scala Plugin Test&lt;/name&gt;
    &lt;packaging&gt;jar&lt;/packaging&gt;
    &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
    &lt;description&gt;
		Test for Maven Scala Plugin.
    &lt;/description&gt;
  
  &lt;repositories&gt;
    &lt;repository&gt;
      &lt;id&gt;scala-tools.org&lt;/id&gt;
      &lt;name&gt;Scala-tools Maven2 Repository&lt;/name&gt;
      &lt;url&gt;http://scala-tools.org/repo-releases&lt;/url&gt;
    &lt;/repository&gt;
    &lt;repository&gt;
        &lt;id&gt;jline&lt;/id&gt;
        &lt;name&gt;JLine Project Repository&lt;/name&gt;
        &lt;url&gt;http://jline.sourceforge.net/m2repo&lt;/url&gt;
    &lt;/repository&gt;
  &lt;/repositories&gt;  
  
  &lt;pluginRepositories&gt;
    &lt;pluginRepository&gt;
      &lt;id&gt;scala-tools.org&lt;/id&gt;
      &lt;name&gt;Scala-tools Maven2 Repository&lt;/name&gt;
      &lt;url&gt;http://scala-tools.org/repo-releases&lt;/url&gt;
    &lt;/pluginRepository&gt;
  &lt;/pluginRepositories&gt;

  &lt;dependencies&gt;
    &lt;dependency&gt;
	&lt;groupId&gt;org.scala-lang&lt;/groupId&gt;
	&lt;artifactId&gt;scala-library&lt;/artifactId&gt;
	&lt;version&gt;2.6.1&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
	&lt;groupId&gt;jline&lt;/groupId&gt;
	&lt;artifactId&gt;jline&lt;/artifactId&gt;
	&lt;version&gt;0.9.94&lt;/version&gt;
    &lt;/dependency&gt;
  &lt;/dependencies&gt;
  
  &lt;build&gt;
    &lt;sourceDirectory&gt;src/main/scala&lt;/sourceDirectory&gt;
    &lt;testSourceDirectory&gt;src/test/scala&lt;/testSourceDirectory&gt;

    &lt;plugins&gt;

      &lt;plugin&gt;
        &lt;groupId&gt;org.scala-tools&lt;/groupId&gt;
        &lt;artifactId&gt;maven-scala-plugin&lt;/artifactId&gt;
		&lt;version&gt;2.4&lt;/version&gt;
        &lt;executions&gt;
          &lt;execution&gt;
            &lt;goals&gt;
              &lt;goal&gt;compile&lt;/goal&gt;
              &lt;goal&gt;testCompile&lt;/goal&gt;
            &lt;/goals&gt;
          &lt;/execution&gt;
        &lt;/executions&gt;
	    &lt;configuration&gt;
	      &lt;mainClass&gt;org.example.HelloWorld&lt;/mainClass&gt;
	    &lt;/configuration&gt;
      &lt;/plugin&gt;
	
    &lt;/plugins&gt;

  &lt;/build&gt;
 
&lt;/project&gt;

</pre>

<h2>Some points of interest</h2>

<p>
Ok, so the first thing you might notice is that I have to have two explicit dependencies: jline and scala itself.  maven-scala-plugin will compile your code without the scala dependency, but it cannot run the classes unless the jar is provided at runtime via a dependency.  Jline I determined was required by simple trial and error.
</p>

<p>
The scala-maven-plugin site's documentation is incorrect. The group id is not "scala" as they claim, it is in fact: &lt;groupId&gt;org.scala-tools&lt;/groupId&gt;
</p>

<p>
The sourceDirectory and testSourceDirectory do not have to be specified if you decide to use src/main/scala and src/test/scala (at least according to their documentation) but I have chosen to explicitly state them here anyway.
</p>

<p>
So, you need to put your scala code in src/main/scala and your tests in src/test/scala.  The typical HelloWorld example could be saved to src/main/scala/HelloWorld.scala which looks like:
</p>
<pre class="prettyprint">package org.example {
  object HelloWorld extends Application {
    println "hello"
  }
}
</pre>

Then from the command line run:

<pre class="prettyprint">mvn clean compile
</pre>

<pre class="prettyprint">mvn scala:run
</pre>

And voila, you should see "hello" print to the console.]]></description>
            <link>http://www.nearinfinity.com/blogs/bryan_weber/scala_and_maven_with_maven.html</link>
            <guid>http://www.nearinfinity.com/blogs/bryan_weber/scala_and_maven_with_maven.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">General</category>
            
            
            <pubDate>Fri, 07 Mar 2008 00:01:33 -0500</pubDate>
        </item>
        
        <item>
            <title>JVM Concurrency with Scala Actors</title>
            <description><![CDATA[<p>
Concurrency in Java is a nightmare.  I used to think that when I first started using threads.  After getting the hang of it a little I thought maybe, just maybe it wasn't so bad.  Then I saw Brian Goetz speak at No Fluff and I realized that the state of concurrency in Java is impossible for a mere mortal to comprehend.  Whenever a topic becomes too difficult, I have learned to step back and look at the big picture.  There must be something that I am fundamentally doing wrong.  I think that this is one of those situations, only it took over a decade for most of us to figure out, while a small group of people were shaking their heads the whole time.
</p>  

<p>
That small group of people are the developers who understand functional programming languages.  Functional programming languages do not have shared state.  This makes concurrency in them a joy when compared to Java and most OOP languages.  I recently took some time to start learning Erlang (Pragmatic Studio, very well done Joe and Dave!) and I was very impressed with what I saw.  I really loved some of the aspects of Erlang.  It is well known for having concurrency baked into its DNA, but I was impressed with several other things (things I had seen before, but just felt so natural in Erlang).  Higher order functions, list comprehensions, hot deployment, and most importantly pattern matching.  This isn't an blog about any of those topics however.  This is about concurrency and in the title I mentioned concurrency on the JVM.  
</p>  

<p>
One of the things that I did NOT like about Erlang was that the sequential programming features seemed incomplete to me coming from an OOP world.  Not to mention commas, semi-colons, periods and nothing... and when to use which!  I remember wishing in class that Erlang ran on the JVM so I could use it for all my concurrency needs and call out to Java/JRuby/Groovy/SISC/etc for the meat of my application logic.  Using the xmerl library (I know that there is a better one out there, but c'mon no xml library should be this difficult) made me really long for something better.  So once again I took a step back and tried to look at the big picture.
</p>  

<p>
Before going to the Erlang Pragmatic Studio I had started to read up on Scala (which I find difficult because I find the documentation to be very sparse and fairly poor) and Scala's actor library in particular.  I admit that when I first looked at it I didn't fully get it.  Learning Erlang helped cement some concepts that make looking at the Actor library much, much simpler.  While I still prefer the Erlang way of receiving messages in particular I found the Scala Actor library to be decent.  It is also worth nothing that the Scala actor library works with threads or with processes (actors, not OS processes).  To me, the whole reason to use the actor library is to NOT be using threads, so I highly recommend the event based actors.
</p>  

<h2>Actor concepts</h2>
<p>
In an actor based concurrency model, there are 3 fundamental concurrency primitives.  First, there is spawn.  Spawn creates a new actor which has a mailbox where it can receive messages.  In Erlang spawn spawns functions and in Scala the equivalent is creating a new Actor and starting it.  (Think creating a new thread and starting it). 
The second primitive is send (!).  This is pretty similar in both Erlang and Scala.  receiver ! message means send message "message" to "receiver".
Scala actually has some additional methods for sending messages but we won't cover them here.
Finaly  there is receiving messages where a message is pulled from the mailbox if it matches a pattern and can be acted upon.  Erlang blows away Scala on pattern matching from what I can tell, but I am admittedly not an expert on Scala pattern matching.
</p>  

<p>
So some important topics to discuss now: What is an Actor, immutable state and pattern matching, and process linking.
</p>  

<h2>What is an actor?</h2>
<p>
An actor is like a thread but without shared state.  I sometimes refer to it as an programming language process because an actor is a process, but not an operating system process.  It is a process that is managed by the runtime process and therefore must be very lightweight.  Erlang has spent a lot of time getting processes very light weight.  Erlang doesn't use the term actor, it just has processes, but they are the same thing.  Each process or actor has a mailbox where it receives messages from other processes.  Messages are the ONLY way that processes can communicate since they have no shared state.
</p>  

<h2>Immutable state and pattern matching</h2>
<p>
Immutable state is key to functional programming languages as they are intended to have no side effects and immutable state means that no function can change the value of something (a variable) and thus introduce a side effect. Pattern matching in Erlang is brilliant.  It matches the left side and the right side of the =.  Conceptually there are 3 things that can happen here.  If the left is unbound it will be bound with the value from the right side.  This looks like variable assignment from OOP.  If the left side is bound it must match the value from the right side or an exception will be thrown.  This is because variables are immutable and they cannot be "assigned" another value.  Finally, if the left side has a partial match it can assign values to unbound variables that match the pattern.  A tuple is the simple way of understanding this.  
</p><pre class="prettyprint">A = "a",
B = "b",
{A,C} = {A,B}
</pre>
This will match because the left side and right side are tuples of the same size and none of the matching values would change state.  Since A equals A we are OK.  And since C is unbound it will be assigned the value from B.  

<pre class="prettyprint">A = "a",
B = "b",
{A,B} = {A,C}
</pre>

This would not match because C is unbound.

Likewise, the following would not match because the values of B and C do not match:
<pre class="prettyprint">A = "a",
B = "b",
C = "c",
{A,C} = {A,B}
</pre>

<h2>Fault tolerance</h2>
<p>
So if you have heard of Erlang, you have probably heard that it makes concurrency and fault tolerance easy.  We've looked at the concurrency primitives, but what about the fault tolerance primitives?  They are link, unlink and process_flag.  These are conceptually simple.  If a process A links to process B then they are linked.  If one dies then it will send a signal to all the processes that it is linked to prior to its own death.  The linked processes can be system processes depending on whether or not they set their process_flag. If they did then they can trap exit messages from dying processes, if not then this process will die as well.  So as you can probably imagine it is easy to create graphs of processes that will die when certain failures occur and that can be restarted or resurrected by some system processes.  Scala's actors have these concepts as well.  I won't go into any more detail about them here, but if you read the links at the bottom of this blog you can find some additional information in the Scala actor api.
</p>  

<p>
So now that I have given a very long winded ill-explained description of actors, let's look at a real example in Erlang and in Scala:

</p><h2>Erlang</h2>

<pre class="prettyprint">-module (blog).
-compile(export_all).
			
client(Pid) -&gt;
	Pid ! {self(),request,foo},
	receive 
		{Pid,response,Response} -&gt;
			io:format("got response ~p~n",[Response]),
			Pid ! exit
	end,
	io:format("client done~n").
		
server() -&gt;
	receive
		{From,request,Request} -&gt;
			io:format("got request ~p~n", [Request]),
			sleep(1000),
			From ! {self(),response,bar},
			server();
		_ -&gt;
			io:format("server done~n")
	end.
	
sleep(Time) -&gt;
	receive
	after Time -&gt; void
  end.

foo() -&gt;
	Pid = spawn(fun server/0),
	spawn(fun() -&gt; client(Pid) end),
	exit.

</pre>

<h2>Scala</h2>

<pre class="prettyprint">import scala.actors.Actor
import scala.actors.Actor._
import scala.actors.OutputChannel

case class Request(data:Object)
case class Response(data:Object)
case object Exit

class Client(server:Actor) extends Actor {
  def act() {
    server ! new Request("foo")
    react {
      case Response(data) =&gt; 
        Console.println("got response " + data)
        server ! Exit
		println("client done")
        exit()
    }
  }
}

class Server() extends Actor with Sleeper {
  def act() {
    loop {
      react {
        case Request(data) =&gt;
		  println("Got request " + data)
          sleep(1000,(sender:OutputChannel[Any]) =&gt; {
			sender ! new Response("bar")
		  },sender) 
        case _ =&gt;
		  println("server done")
          exit()
      }
    }
  }
}

trait Sleeper {
  def sleep(time:Long,fun:(OutputChannel[Any])=&gt;Unit,sender:OutputChannel[Any]) {
    reactWithin(time) {
      case _ =&gt;
        fun(sender)
    }
  }
}

object Foo extends Application {
  var s = new Server()
  var c = new Client(s)
  s.start
  c.start
  println("exit")
}

</pre>

<h2>So what does it do?</h2>
<p>
This code spawns two actors, 1 as a client and 1 as a server. The server listens for request messages and responds with response messages after sleeping for 1 second.  If a message comes in that is not a request message, then the server exits.  The client sends a request message to the server and then listens for the response.  Once it receives its response it sends a message to the server that is not a request as a shutdown command. Not particularly interesting, but it does demonstrate some of the key differences between Erlang's processes and Scala's actors.  One of the biggest differences is that a receive in Scala is a method that does not return.  This means that any logic must be present in the receive and all code after the receive will never be executed.  Erlang can pattern match on atoms and tuples and Scala pattern matches on case classes. One of Erlang's strong points is distributed code.  In Erlang, when a process is spawned there can be no knowledge of whether or not that process is running on the same machine or remotely. It simply doesn't matter.  Scala has remote actors as its equivalent, but the things I've covered here so far are really for replacing threads within a single JVM.  The concepts don't change and maybe that will be the topic of a future blog post.
</p>

<h2>
Resources:
</h2>
  <ul>
  <li>
  Scala
    <ul>
    <li>
    <a href="http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-1">Tutorial</a>
    </li>
    </ul>
  </li>
  <li>
  Scala Actors
    <ul>
    <li>
    <a href="http://www.scala-lang.org/docu/files/api/">Actors Doc</a>
    </li>
    <li>
    <a href="http://lamp.epfl.ch/%7Ephaller/actors.html">Actors tutorial</a>
    </li>
    <li>
    <a href="http://www.scala-lang.org/docu/examples/files/pingpong.html">Actors Example</a>
    </li>
    </ul>
  </li>
  <li>
  Erlang
    <ul>
    <li>
    <a href="www.erlang.org">erlang</a>
    </li>
    </ul>
  </li>
  <li>
  Ruby Actors
    <ul>
    <li>
    <a href="http://www.infoq.com/articles/actors-rubinius-interview">InfoQ with MenTaLguY</a>
    </li>
    <li>
    <a href="http://revactor.org/">Revactor</a>
    </li>
    </ul>
  </li>
  </ul>  

<h2>Update</h2>

<p>
If you did not need the sleep function, you could use this shorthand notation to define the actors.  Notice that the server actor is assigned to a variable that the client actor uses.
</p>

<pre class="prettyprint">import scala.actors.Actor
import scala.actors.Actor._

case class Request(data:Any)
case class Response(data:Any)

object Foo extends Application {

	actor {
		server ! new Request("foo")
		react {
		  case Response(data) =&gt; 
		    Console.println("got response " + data)
		    server ! "Exit"
		    exit()
		}
	}

	var server = actor {
	    loop {
	      react {
	        case Request(data) =&gt; 
	          Console.println("got request " + data)
	          sender ! new Response("bar")
	        case _ =&gt;
	   		  println("exiting server")
	          exit()
	      }
	    }
	}

}

</pre>]]></description>
            <link>http://www.nearinfinity.com/blogs/bryan_weber/jvm_concurrency_with_scala_actors.html</link>
            <guid>http://www.nearinfinity.com/blogs/bryan_weber/jvm_concurrency_with_scala_actors.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">General</category>
            
            
            <pubDate>Fri, 22 Feb 2008 23:43:32 -0500</pubDate>
        </item>
        
        <item>
            <title>Generated code...</title>
            <description><![CDATA[So most developers, especially Java developers because of its verbose syntax, have played around with generated code at one point or another.  For those of you who haven't, it is a very, very, very easy concept to understand.
<br/>

<br/>
<h3>The most pathetic diagram you will ever see</h3>
<pre class="code">
Inputs -> Generator -> Generated
</pre>

<br/>
Some inputs, a template and some values for example, are passed into a generator and it generates some output.  This could really be anything; XML, source files, view components, etc.  One of the first rules of generators is do not modify the generated content.  Why you ask?  Playing devil's advocate, I could say that once the material is generated I won't ever need to generate again.  Any changes to the material I make will already be present so they will build on top of each other. In some, possibly even many, cases this is very true. However, there are times when you will want to regenerate something or to generate another object that may require many of the same changes that you already made to previously generated objects.  All of those changes have to be made to the generated material one at a time because the generator does not support them.
<br/>

<br/>Well, OK, it may be acceptable to modify generated content when you are testing something out because it might be much faster than going through the entire generation process again.  But beware, your changes are not repeatable and will be lost as soon as the generator runs again.  So the general rule of thumb is, modify the inputs, not the generated material.
<br/>

<br/>
Let's introduce one additional component, some sort of runtime environment.  
<br/>

<br/>
<h3>Pathetic diagram + Runtime</h3>
<pre class="code">
Inputs -> Generator -> Generated  <= Runtime
</pre>
<br/>

<br/>
This pathetic chain symbolizes the same thing, but at the end of the process some "runtime" uses the generated objects.  So, why would you ever modify the generated material aside from some quick step to verify that the generated material was ok in the context of the runtime?  Well, its probably not a good idea.  You are much better off modifying the inputs, thus creating a repeatable process.
<br/>

<br/>
Now, let's introduce a wrinkle to all this lovely over-simplification.  What if the generator or runtime needs to be updated and is not fully backwards compatible? Well, if the runtime is updated then the generated objects have to be updated to work with the new runtime.  If you modified the generated objects then you will either have to continue down this path or you will have to modify your inputs to update your generated objects with not only the new changes required by the updated runtime but also the changes you made prior to the upgrade.  
<br/>

<br/>
If the generator is updated, then we have to change the inputs.  Any changes that were made to the generated objects will be lost.  
<br/>

<br/>
So here is the important question.  Why in the world am I harping on all this hypothetical drivel?  Well, because if you are using Rails or Grails as your web framework then most likely you are doing exactly what I am suggesting is a bad idea.  Readers familiar with g/rails might say that this is not true because of the scaffolding support offered in both frameworks.  But this leads to my exact point.  Using scaffolding is good, but it only takes you so far.  At some point you have to move beyond what you get out of the box.  At this point, users are expected to go modify the generated material and hope that they never need to generate again.  To me, using generators to get started is a good idea, but once you move away from the scaffolding you have crossed the point of no return.  
<br/>

<br/>
So what can be done to prevent modifying generated code?  Well, just like I suggested in my verbose drivel above, modify the inputs!  In grails, for example, this means providing your changes not to the generated content, but in plug-ins that determine how your content is generated.  Now, I don't believe that grails plug-ins are robust enough at the moment (I could be wrong about this) to really make this feasible, but I would like to see g/rails adopt this type of pattern.  Both frameworks have strong runtime environments and very good generators.  But let's change the focus from modifying the generated content to modifying the inputs so we have a repeatable code generation framework.
<br/>]]></description>
            <link>http://www.nearinfinity.com/blogs/bryan_weber/generated_code.html</link>
            <guid>http://www.nearinfinity.com/blogs/bryan_weber/generated_code.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Groovy</category>
            
            
            <pubDate>Thu, 24 Jan 2008 22:39:02 -0500</pubDate>
        </item>
        
    </channel>
</rss>

