We like parsers. One of the things that really kills the vibe with parsers is a rubbish error message.
Given the technical interestingness of parsing with derivatives, can we get useful error messages out of them?
Since the dark ages of yesteryear Squeak has had a very interesting button in its Debugger – “create”. Today we’re going to teach it a new trick.
Squeak 4.4 Ulam Spiral is finally ready to be born. I semi-volunteered to be its release manager, and I’d like to look back over the last six months and talk a bit about what’s happened.
When I wrote my Smalltalk deriving-with-parsers library, I ran into an issue with compaction: cycles in the parser. Self-referencing parsers (corresponding to left- and right-recursive rules) occur naturally, so I couldn’t hide from the problem. I investigated two ways to introduce circularity as well as how to compact these graphs: delegates, and “sutures”.
I did the Coursera Natural Language Processing course at the beginning of the year. Apart from the introduction to probability it gave me, the thing that sticks most in my mind comes from one of the exercises. In the exercise we had to define a probabilistic parser to parse (an extremely limited subset of) English. That’s not the fun bit though. The fun bit was using the information in the parser to generate “English” sentences. The idea of a grammar generating sentences is right in the standard way of defining languages, but for some reason it hadn’t occured to me to actually build such a thing.
The idea’s simple enough: complicated parsers (language generators) are made up of simpler parsers (language generators) until you hit trivial parsers (language generators).
Of course we don’t want just one sentence, so it makes sense to build streams (we’ll use my favourite stream implementation, Xtreams) so that we may – if desired – generate as many different sentences as we’d like.
We use many different languages writing software. Not just the usual kinds – Ruby, Haskell – but data formats like HTML or JSON, and protocols like SIP or HTTP. We have a lot of tools dealing with these languages – yacc, bison, ANTLR. And Matt Might and his colleagues have added a new spanner to the toolbox.
The Ulam spiral is a well-known mystery to mathematicians: draw a 1 in a grid, 2 in the cell to the right, 3 above the 2, and so on in a spiral:
Colour the primes:
For reasons unknown, long diagonal chains of primes appear. In this very small Ulam spiral, we don’t really see them (19, 7, 23), but we will.
Methods in a Smalltalk object live in the method dictionary of its class. A method dictionary maps
s. From the virtual machine’s perspective, anything that understands
is compatible with a
, in the sense that the VM sends this message to things that it will execute.
As a result, it’s easy enough to put arbitrary objects (that understand
) in a class’s method dictionary. In fact, there’s a library for it.
With this hammer in hand, it becomes trivial to perform all manner of intercessions on code, without instrumenting code through a rewrite+compile cycle: wrap the
(or several) and away you go. What might you do? Pre- and post-condition checking, flagging which methods execute for coverage analysis, profiling, and so on. Today we’re going to turn a method into a memoised one.
Back in the dark years of 2003, Avi Bryant and Colin Putney tried to use CVS to version their Smalltalk code and failed dismally. They decided to scratch their itch, and Monticello was born, a DVCS centred around managing the structured text of Smalltalk code.
Years have passed, and nowadays we have Mercurial and Git providing succour to so many. How can Smalltalk leverage these tools, instead of maintaining its own custom version control system?
You are currently browsing the archives for the Smalltalk category.