Minigrace, a prototype compiler for Grace

May 13th, 2012

Minigrace is a compiler for Grace, supporting most of the language specified so far and itself written in Grace. It compiles to native code via C and to JavaScript that runs in a web browser.

Minigrace is distributed as downloadable tarballs that require only a C compiler to build, or via `git clone git://github.com/mwh/minigrace.git`. The git repository knows how to bootstrap itself by compiling the Grace source code. Documentation is included inside the source tree, including a description of unimplemented or additional features versus the specification. The test suite also provides an overview of implemented functionality.

The compiler should work on any POSIX-compatible system with GCC, and is known to work on Linux, NetBSD, and Mac OS X.  There is a client-side web front end suitable for quick experimentation that should work in any modern web browser with JavaScript enabled.

Once built, the most important Minigrace command line is:
./minigrace file.grace
which will compile and execute the given file. Other options are described in the documentation.

There is a Minigrace mailing list for discussing issues relating to the implementation. Release and update announcements will be sent to that list.

Pedagogical IDEs

May 8th, 2012

A very important part of support for novices is a supportive interactive development environment (IDE), so we are planning on porting one or more of the existing pedagogical environments to support our language.  Not surprisingly, we are most interested in open-source, platform-independent IDEs that we can adapt to Grace

We are very familiar with (and have been investigating) BlueJ and DrRacket.  However, we thought it might be useful to check to see if there are others out there that people like that we should consider.  While I use Eclipse in my own intro classes at the moment, we are interested here in environments specifically designed to be supportive for novice programmers, so please don’t suggest IDE’s aimed at professional programmers.

Thanks in advance for your suggestions.

The absence of (inessential) difficulty

May 7th, 2012

We recently submitted a paper on Grace to the Onward! conference at SPLASH 2012. You can read a draft: please do send comments or attach them below. To whet your appetite, here is the abstract:

Grace: the absence of (inessential) difficulty

by Andrew Black, Kim B. Bruce, Michael Homer, and James Noble

We are engaged in the design of a small, simple programming language for teaching novices object-oriented programming.  This turns out to be far from a small, simple task.  We focus on three of the problems that we encountered, and how we believe we have solved them.  The problems are (1) gracefully combining object initialization, inheritance, and immutable objects, (2) reconciling apparently irreconcilable views on type-checking, and (3) providing a family of languages, each suitable for students at different levels of mastery, while ensuring conceptual integrity of their designs.  In each case our solutions are based on existing research; our contribution is, by design, consolidation rather than innovation.

Loop with exits revisited

May 2nd, 2012

I was recently talking to one of programmers moving some Java code into Grace. He was refactoring Java code that uses “break” and “continue” statements, and wondered why Grace doesn’t support them. I answered that even if break and continue aren’t in the standard library the can certainly be written by a programmers.

The only infelicity is that rather than being commands, “break” and “continue” in Grace will be blocks, supplied as arguments into loops — to take one of these exits the program must apply the appropriate block argument. Here’s a simple loop using both “break” and “continue” — not exactly the best style but hopefully illustrativ

var foo := 0

loopWithExits { break, continue ->
   foo := foo + 1
   print "A {foo}"
   if (foo == 2) then {continue.apply}
   if (foo == 4) then {break.apply}
   print "B {foo}"
}

running this code produces:

A 1
B 1
A 2
A 3
B 3
A 4

as you might expect.

How is this implemented? Well first, here’s a simpler case: a “doWithExit” statement that takes a block and exits when the block is applied:

doWithExit { exit ->
 print "A"
 print "B"
 exit.apply
 print "C"
}
print "Done"

this will print “A”, “B”, and then “Done” because “exit.apply” exits the block. The definition of the “doWithExit” statement is quite straightforward:

method doWithExit (block) {
 block.apply { return "doWithExit Return" }
}

we just run the block supplied to the method, passing a second block as an argument, this second block calls return and so exits from the method, consequentially exiting the argument block early.

We can then build upon “doWithExit” to build up the “loopWithExits” statement above. The trick here is we inject two blocks into the looping code. The first of these, the “break” exit, returns from the whole “loopWithExits” statement, stopping the loop (just like C or Java’s break) — the implementation here is just the same as the single exit in the “doWithExit” method. The second injected argument comes from a “doWithExit” inside the loop proper to exit from only the code being looped. When that inner code returns, the control flows out of the “doWithExit” block, into the block controlled by the “loop” statement. Since we’re at the end of the loop, the control flows around to the next iteration of the loop — just like C or Java’s continue.

method loopWithExits (block) {
 def break = { return "loop return" }
 loop {
   doWithExit { continue ->
     block.apply( break, continue )
   }
 }
}

This isn’t the simplest Grace code — frankly I wouldn’t teach it at all to first year students — but hopefully it does show the kind of things that programmers can write in a simple, language based on “a small number of underlying principles that can be applied uniformly”. In Grace, “loopWithExits” is just a method, like any other. The “loopWithExits” method is implemented using nothing but objects, blocks, requests, and returns, without any macro processing or explicit metaprogramming

Finally, it’s interesting to realize that we talked about this on the blog over a year ago and outlined what we hoped the basic Grace code for doing this would be. It’s gratifying to realize that the code above, that works on our current prototype Grace systems, is pretty much the same as last year’s sketches. And it’s even more gratifying to see last year’s sketches made flesh and running this year!

Grace at Lang.Next

April 19th, 2012

Andrew Black and Kim Bruce presented an invited talk on Grace at the Lang.Next workshop at Microsoft a few weeks ago.  A video of the talk is available on Channel 9 at Microsoft and the slides are here.



The next day Mads Torgersen interviewed Kim about Grace. The video is available.