Friday, March 7, 2008

Regular Expressions

In perl (and bash and lots of other places) there are these things called regular expressions. This is a letter written to regular expressions.

Dear Regular Expressions,

You are the best friend a girl could have. You find everything I want for me. You find just what I want and nothing I don't. You are the reference librarian of the programming world. You are complex and arcane and definitely nerdy -- but that's why you're so good at what you do and why I love you so much, and after all I'm pretty arcane and nerdy too, so that's no barrier to our friendship.

There's just one little thing about you that I think could be better. Don't take this the wrong way -- like I said I love you dearly and I wouldn't change your substance for anything in the world. ... But, I think it would be easier to introduce you to my other friends and you would be better served by a different name.

Because if this is what you mean by a regular expression:

s/^(\s*)(\S+)(\s+)(\S+)/\1\4\3\2/

I can't even imagine what would qualify as an irregular expression.

kthxbai,
Jenny


PS: I thought about it some more and maybe it would be something extraordinary like the expressions in this academic article:

Some Unusual Hittite Expressions for the Time of Day
Charles Carter
Journal of the American Oriental Society, Vol. 94, No. 1. (Jan. - Mar., 1974), pp. 138-139.
Stable URL: http://links.jstor.org/sici?sici=0003-0279%28197401%2F03%2994%3A1%3C138%3ASUHEFT%3E2.0.CO%3B2-K

Or maybe it would be koans from the Principia Discordia and Zen Buddhism, like these:

Greater Poop: Is Eris true?
Malaclypse the Younger: Everything is true.
GP: Even false things?
M2: Even false things are true.
GP: How can that be?
M2: I don't know man, I didn't do it.

OR:

Hakuin used to tell his pupils about an old woman who had a teashop, praising her understanding of Zen. The pupils refused to believe what he told them and would go to the teashop to find out for themselves.

Whenever the woman saw them coming she could tell at once whether they had come for tea or to look into her grasp of Zen. In the former case, she would serve them graciously. In the latter, she would beckon to the pupils to come behind her screen. The instant they obeyed, she would strike them with a fire-poker.

Nine out of ten of them could not escape her beating.


I think I know how to express the first one in code but the second one is way beyond my programming skills.

# Greater Poop: Is Eris true? Assuming Eris can be used in a scalar context

%everything = ("Eris" => "the big question");

foreach $thing keys(%everything)
{
$everything{$thing} = "1"
}

Actually, this is more complicated than I thought so I'll have to return to it later. Trying to figure out how to express "return true if value is true or false". I have confidence that there's some way to do it. Perl is very koan.

No comments: