James Bond, Logo, and Trees

The latest “James Bond” release of minigrace (version 0.0.7.1010, thus James Bond) includes experimental support, written by Tim Jones, for generating Java code and calling Processing. Unfortunately this support really is very experimental, and will probably go away in the next release.

The main things we learned from the experiment is that while we can just about compile Grace to Java as a prototype, anything more serious either needs a global analysis to map Grace’s structural types to Java’s nominal types (a nice PhD thesis) or to generate byte codes and use invokedynamic to build Grace’s calling conventions (an MSc at least), or perhaps a mixture of the two.

Tim’s current plan – unless anyone volunteers to take over the Java side of things – is to concentrate on the JavaScript backend. Compiling to a dynamically typed substrate will be so much easier, and as a consequence, perhaps quicker too. Since Processing has a JavaScript implementation, if we can bind to that, we hope to be able to port Grace code calling the Processing API over to JavaScript without any change on the Grace side.

While playing with the experimental Java-backend I revisited some examples that was all the rage when I was starting out, fractal graphics done in Logo style. Stealing shamelessly from motivate.maths.org, all the images in this post were generated in Grace via the Processing API hosted on top of Java, running on a Mac OS 10.7.4. If you download the tarballs and install the files, you could play with something like this too – I mean, this is an example of Grace code that might actually be used, someday, to teach programming.



This article is translated to Serbo-Croatian language by Jovana Milutinovich from Webhostinggeeks.com.

Minigrace, a prototype compiler for Grace

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/gracelang/minigrace.git. The git repository knows how to bootstrap itself by compiling the tarball. 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 and student programs 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. Bug reports and suggestions can also be filed using the github issue tracker.

Pedagogical IDEs

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

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

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

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:

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

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.

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!