Strangely Consistent

Musings about programming, Perl 6, and programming Perl 6

November 19 2010 — I've got good news and bad news

69 years ago today off the coast of western Australia, two ships engaged each other in battle — the German Kormoran one and the Australian HMAS Sydney. The final outcome of the battle was that both ships were destroyed.

How and why Sydney was sunk by the weaker Kormoran has been the subject of speculation and controversy, with numerous books on the subject, along with government inquiries published in 1999 and 2009. According to the German accounts, which were accepted as truthful by their interrogators and most subsequent commentators, the cruiser sailed too close to the disguised merchant raider, negating the advantages of armour and superior gun range, and was destroyed by heavy fire and a torpedo strike after Kormoran revealed herself.

There's a lot of nifty details about the signaling before the battle, which I will not relay here. But here's one thing I didn't know before: you have to flag that you're going into battle according to international laws of war (and there is speculation whether the Germans really did this). To me as an outsider, it seems like a surprisingly honest thing to have to do in a battle situation.

Seeking to patch up .trans to handle regexes today, I failed in unexpected and interesting ways.

Having distracted myself during $dayjob with thoughts of how to go about implementing regexes in .trans, I finally dug into the task in the evening. This is what I had concluded while just thinking about it:

This is what I learned by implementing it:

The last guttural sound there was me giving up due to an exceptional amount of minutia that I hadn't anticipated in the design phase. ☺

TimToady++ on the channel understood immediately what the trouble might be.

<masak> today, I've tried to patch .trans for handling regexes.
        giving up for the day -- it was more complicated than I
        imagined it would.
<masak> time to blog about the unexpected overwhelm fail. :)
<TimToady> masak: that will be very difficult unless you know how to
           hook into the LTM implied by .trans
<masak> TimToady: yeah.
<TimToady> espcially since rakudo doesn't really do LTM yet
<masak> TimToady: the current .trans impl does it right for constant
        strings.
<jnthn> The current Rakudo does LTM right in some cases for constant
        strings. :)
<masak> TimToady: but... I found I had to special-case regexes, and
        then there were a lot of "interesting" corner cases across
        the boundary.
<masak> I think I'd be better off attacking the problem after hiding
        some of that complexity first.
<masak> essentially runtime-polymorphing on constant strings and regexes.

And that, in a nutshell, is what I intend to do if-and-when I attack this problem again. Need to build a little LTM engine that hides the complexity of handling both constant strings and regexes in the key position of the pairs sent in to .trans.

That should take care of another problem I had with the code: it wasn't fun to read. Putting an LTM engine as an API between the .trans code and the complexity should help.