code • words • emotions

Daniel Janus’s blog

A quirk with JavaScript closures

15 May 2011

I keep running into this obstacle every now and then. Consider this example:

> q = []
> for (var i = 0; i < 3; i++)
    q.push(function() { console.log(i); });
> q[0]()

I wanted an array of three closures, each printing a different number to the console when called. Instead, each prints 3 (or, rather, whatever the value of the variable i happens to be).

Continue reading

The Dijkstran wheel of fortune: SPSS, Excel, VBA

28 March 2011

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.

— Edsger W. Dijkstra, EWD 498

Continue reading

Hello world, again

11 March 2011

I’ve been quiet on the front of blogging in English recently. But that doesn’t mean I’ve given up.

After more than a year, I had become tired of maintaining a Blosxom installation. I greatly admire Blosxom, its minimalism and extensibility, but the default installation is just too minimal for my needs. And the plugins tend to have rough edges. Like the Disqus comments that I’ve enabled at one time on the otherwise static blog pages: the correct number of comments appears in some places but not all; besides, they just don’t feel right.

Continue reading

Last post here

10 March 2011

I’ve decided to move my English blog to Posterous. The new address is This URL ( will point to the new blog in about a week’s time.

I’m only posting this to let people update their RSS feeds to the new address, which is

Continue reading

Keyword arguments

4 May 2010

There’s been an ongoing debate about how to pass optional named arguments to Clojure functions. One way to do this is the defnk macro from clojure.contrib.def; I hesitate to call it canonical, since apparently not everyone uses it, but I’ve found it useful a number of times. Here’s a sample:

Continue reading


18 April 2010

The program I’ve been [writing about recently][1] has come to a point where I think it can be shown to the wide public. It’s called [Sunflower][2] and has its home on GitHub. It’s nowhere near being completed, and of alpha quality right now, but even at this stage it might be useful.

Continue reading

A case for symbol capture

5 April 2010

Clojure by default protects macro authors from incidentally capturing a local symbol. Stuart Halloway describes this in more detail, explaining why this is a Good Thing. However, sometimes this kind of symbol capture is called for. I’ve encountered one such case today while hacking a Swing application.

Continue reading

Hiking in the Apennines

4 April 2010

I’ve recently done a week-long hike in the Umbria-Marche region of the Italian Apennines (the vicinity of Monte Catria, near Cantiano, to be more precise), and here are some tips I’d like to share.

  • The Umbria-Marche Apennine doesn’t seem to be frequented by a lot of tourists, especially in mid-March. The information offices, although helpful, are often closed (this is not only the case with the mountain region: contrary to information available on the Web, the tourist information at Forlì airport was closed on Sunday morning), and most of the Italians we’ve met didn’t speak English.
  • The tourist trails in the region are not well marked. Direction marks are nowhere to be found, nor are the signs visible on junctions. We had to ask the locals when leaving Cantiano for Monte Tenetra (and ended up on M. Alto instead anyway).
  • There are a lot of rifugi (mountain huts), but most of them are closed at this time of year. We passed by six or seven, out of which only one was available for sleep: Rifugio Fonte del Faggio (depicted), merely a small bothy with one worm-eaten bunk bed. Another one, Cupa delle Cotaline, with restaurant facilities and situated by a station of a local skilift, opened in the morning, but was closed for the night.

Continue reading

The pitfalls of lein swank

31 March 2010

A couple of weeks ago I finally got around to acquainting myself with [Leiningen][1], one of the most popular build tools for Clojure. The thing that stopped me the most was that Leiningen uses [Maven][2] under the hood, which seemed a scary beast at first sight — but once I’ve overcome the initial fear, it turned out to be a quite simple and useful tool.

Continue reading

Downcasing strings

16 February 2010

I just needed to convert a big (around 200 MB) text file, encoded in UTF-8 and containing Polish characters, all into lowercase. tr to the rescue, right? Well, not quite.

$ echo ŻŹŚÓŃŁĘĆĄ | tr A-ZĄĆĘŁŃÓŚŹŻ a-ząćęłńóśźż

Continue reading