Version 0.7 of the Heron Programming Language
I've just released version 0.7 of the Heron interpreter.
Version 0.7 of Heron is now available at http://code.google.com/p/heron-language/. This version implements over 90% of the language features I plan for version 1.0, and has a reasonable set of tests.
Today I implemented the Sieve of Eratosthenes as a test program, which I thought would be a good way to talk a bit about some of the features of Heron, and its current status. The sieve is an ancient algorithm for computing primes. Here is the Heron implementation:
<table border="0" style="border-collapse: collapse; padding: 0px; margin: 0px"><tbody><tr id="sl_svn89_1" style="padding: 0px; margin: 0px"><td class="source" style="font-size: 12px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 4px; white-space: pre; vertical-align: top; margin: 0px">script Sieve;<br /></td></tr><tr id="sl_svn89_2" style="padding: 0px; margin: 0px"><td class="source" style="font-size: 12px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 4px; white-space: pre; vertical-align: top; margin: 0px"> </td></tr><tr id="sl_svn89_3" style="padding: 0px; margin: 0px"><td class="source" style="font-size: 12px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 4px; white-space: pre; vertical-align: top; margin: 0px">var max = 10;<br /></td></tr><tr id="sl_svn89_4" style="padding: 0px; margin: 0px"><td class="source" style="font-size: 12px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 4px; white-space: pre; vertical-align: top; margin: 0px"> </td></tr><tr id="sl_svn89_5" style="padding: 0px; margin: 0px"><td class="source" style="font-size: 12px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 4px; white-space: pre; vertical-align: top; margin: 0px">Main() <br /></td></tr><tr id="sl_svn89_6" style="padding: 0px; margin: 0px"><td class="source" style="font-size: 12px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 4px; white-space: pre; vertical-align: top; margin: 0px">{<br /></td></tr><tr id="sl_svn89_7" style="padding: 0px; margin: 0px"><td class="source" style="font-size: 12px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 4px; white-space: pre; vertical-align: top; margin: 0px"> var primes = 0..(max * max);<br /></td></tr><tr id="sl_svn89_8" style="padding: 0px; margin: 0px"><td class="source" style="font-size: 12px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 4px; white-space: pre; vertical-align: top; margin: 0px"> foreach (i in 2..max)<br /></td></tr><tr id="sl_svn89_9" style="padding: 0px; margin: 0px"><td class="source" style="font-size: 12px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 4px; white-space: pre; vertical-align: top; margin: 0px"> primes = select (j from primes) j % i != 0; <br /></td></tr><tr id="sl_svn89_10" style="padding: 0px; margin: 0px"><td class="source" style="font-size: 12px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 4px; white-space: pre; vertical-align: top; margin: 0px"> foreach (i in primes)<br /></td></tr><tr id="sl_svn89_11" style="padding: 0px; margin: 0px"><td class="source" style="font-size: 12px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 4px; white-space: pre; vertical-align: top; margin: 0px"> Console.WriteLine(i); <br /></td></tr><tr id="sl_svn89_12" style="padding: 0px; margin: 0px"><td class="source" style="font-size: 12px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 4px; white-space: pre; vertical-align: top; margin: 0px">}<span style="border-collapse: separate; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; white-space: normal; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px" class="Apple-style-span"> </span></td></tr></tbody></table>Heron programs are either modules containing a class named "Main" or a script. When executing a module Heron instantiates an instance of the class named Main. When executing a script, the function named "Main()" is executed first (after the variables are initialized).
Variable declarations in Heron are identified via the keyword "var". The type annotation is optional, and is written in the Pascal style with the name following a colon (':'). The same syntax and optional typing is used for function definitions.
The '..' operator is called the range operator and is currently only supported on integers. It creates a sequence (also known as a generator), which is a lazily evaluated collection. Each value in the collection is retrieved as needed.
The 'select' keyword is a list operator. It takes a sequence or list, and a boolean expression which represents a predicate condition. The result is a new list that only contains the elements of the list that satisfy the condition. The 'select' keyword is not guaranteed to be executed, if the expression semantics are preserved. The impact of this is that side-effects should not be relied upon in the predicate expression. This was done so that optimizers can perform list-based optimizations.
The call to 'Console.WriteLine()' executes a .NET library function which was exposed to the interpreter. .NET libraries are currently exposed to the library on an ad-hoc basis. I haven't yet formalized how the foreign function interface (FFI) is going to work.
I'd love to hear your thoughts and questions about Heron. I am hoping that it turns out to be relatively easy for the majority of programmers to understand intuitively. If you are interested please download the source and look at the test files, and the unit tests (HeronTests.cs).

