November 20, 2008 -- fifty thousand orbits around the Earth

masak on 2008-11-20T22:58:22

Ten years ago today, the first module of the International Space Station (ISS) was launched. Its name, Zarya (Заря), means "dawn" in Russian. Wikipedia:

Although only designed to fly autonomously for six to eight months, Zarya was required to fly autonomously for almost two years due to delays to the Russian Service Module, Zvezda. Finally, on July 12, 2000, Zvezda was launched and docked on July 26 using the Russian Kurs system.
Zarya initially had problems with battery charging circuits, but these were resolved. It will eventually require supplemental micro meteor shielding, as it was given an exemption to the ISS rules when it launched.
Zarya passed the 50,000-orbit mark at 15:17 UTC. on August 14, 2007, during the STS-118 mission to the International Space Station.

I was going to write today about all the branches we're working on nowadays, but I got so involved in doing markup parsing and (because of that) finding Rakudo bugs, so I'll have to write about that instead.

Having realised that the first letter in MediaWiki links is automatically upcased, I needed to do something about the link-producing closure that I sent along to the formatting routine. It looked like this:

my $link_maker = { "$^page" }

Nice, huh? Might be even nicer once we get better quoting constructs.

(For those who haven't buried their noses in the Perl 6 specifications, that $^page variable is called a placeholder parameter, a positional parameter that you don't have to declare in your routine, but which sort of "declares itself" when you mention it the first time. Think of them as the sane version of the special variables $a and $b in sort blocks.)

So the above line creates a closure that expects one parameter and returns strings: if I call the closure like this: $link_maker('main_page'), I get '<a href="?page=main_page">main_page</a>' back. The closure is a machine that makes links.

But I needed to tweak the machine; I needed to upcase the first letter in the link. So I came up with this, which seemed reasonable:

my $link_maker = { "$^page" }

(Ah, that new ucfirst function is handy at times.)

I should note here that in Perl 6.0.0, I shouldn't have to use the curlies, because method calls are handled just as well as variables. (I'd have to end with () though. But Rakudo isn't Perl 6.0.0-compatible, not yet. Getting there. So I did it with closure curlies instead.

And that's why it didn't work. I got this error:

too few arguments passed (0) - 1 params expected

Can you guess why? What's getting zero arguments here instead of the one it expected?

That's right, my new closure. It's almost too obvious in retrospect. The $^page in the closure is not the same variable reference as the $^page outside. Why? Well, because each closure has its own right to placeholder params. Note that there's no way to pass such params to a closure in a string, but at least we're consistent!

I turned to #perl6, and then to p6l, asking whether we prefer DWIM or consistency in this case. It was just a while ago, so the jury is still out.

In the meantime, I have to write this:

my $link_maker = { my $l = $^page.ucfirst; "$^page" }

That was today's bedtime story. I found another bug too, I think, but I haven't boiled it down to its essentials yet. It occurs when, in my second link test, I don't pass in the link maker as a named argument, but the formatter goes on and uses a link maker anyway. (How does it do that?) I'll know more tomorrow.


second link test

ChrisDolan on 2008-11-21T05:33:06

I predict that the failure in your second link test is caused the familiar lexical bug. I think the formatter from the first link test is mistakenly being carried over to the second test.

Re:second link test

masak on 2008-11-21T10:22:13

Aye. That's what pmichaud++ said as well: "yet another lexicals bug."

He also said that his lex fixes covered this, which sounds excellent to me.