technology from back to front

Archive for January, 2011

Non-local returns and compound statements

Smalltalk uses closures all over the place. They’re how control structures are built up, for starters. They replace what compound statements do in other languages.

So let’s look at a simple function in C: Read more…

by
Frank Shearar
on
31/01/11

Repository crawlers for Mercurial (or why you need to learn about revsets)

Recently I needed to write a tool to crawl a Mercurial repository and look for certain things in unfinished branches that could cause us problems in the future. Given I knew that Mercurial was written in Python, my first approach to this was to start digging around in its code and see if there was anything in there I could cannibalise to build what I needed. This appeared to be bearing fruit, as I found the ancestor module pretty quickly, but I rapidly realised that in order to do something relatively simple I was going to have to copy vast reams of the Mercurial code to support it.

This is the wrong approach, or at least for most purposes it’s a really bad idea, as there’s a much easier way to write this sort of tool. Read more…

by
Tom Parker
on
30/01/11

Squeezing the F# zipper into a Monad

Not being entirely happy with my F# zipper implementation throwing exceptions I decided to investigate whether I could use option types to replace the exceptions thrown when you try to navigate off the tree – for example trying to move up when you are at the top of the tree or move down when you are positioned at a node with no children. The basic implementation is simple enough:
Read more…

by
tim
on

“Try again” with Exceptions

Like many modern languages, Smalltalk has the concept of an exception. When an exception’s signalled, the current stack of contexts – activation frames – is gradually unwound (with unwind blocks – what in Delphi would be called try-finally blocks – being executed at each stage), until a context handles that particular exception.

If no context in the stack handles the Exception, the Exception’s #defaultAction gets called. (How? The first context in the stack tries to find its nextHandlerContext, only it doesn’t have one – it’s nil. UndefinedObject (nil’s class) defines #handleSignal:, which invokes the Exception’s #defaultAction.)

Since Smalltalk has the call stack available for inspection, introspection and general mucking-about, Smalltalk also supports a Exception that can retry the action that signalled the Exception.

Read more…

by
Frank Shearar
on
04/01/11

Search

Categories

You are currently browsing the LShift Ltd. blog archives for January, 2011.

Feeds

Archives

2000-14 LShift Ltd, 1st Floor, Hoxton Point, 6 Rufus Street, London, N1 6PE, UK+44 (0)20 7729 7060   Contact us