kivikakk.ee

47 results —

This has come up a few times recently, so a little note:

/./ will match any character—except a newline.

/[\s\S]/, /[\w\W]/ and so forth are the only way to portably match every character including newlines.

what about /./m?

/./m does not match a newline (usually—see below).

The m modifier does not alter . in any way (usually—see below).

m changes what ^ and $ match—normally they’ll match only the start and end of the string, but m alters them to also match the start and end of any line, i.e. immediately after and prior a newline.

Mnemonic: m for “multiline”.

what about /./s?

Yes, that will do what you want—unless you’re using Ruby or JavaScript.

In Ruby, the s modifier is inexplicably unused—in 1.8, it stays on the Regexp object, but in no way affects matching, and in 1.9, it doesn’t even stay on the object, it just disappears. Note that these behaviours are different to using a complete nonsense modifier, like f, which causes a SyntaxError1.

Even more inexplicable, this feature has been rolled into m instead! So in Ruby, you can use /./m to match a newline, and you can also use /^a/m to match an a at the beginning of the string, or after any newline in the string.

In JavaScript, the s modifier is absent entirely, and it’s not rolled into anything else. Use /[\s\S]/.

Mnemonic: s for “single line” (the string is treated as one line, in a twisted sense).

conclusion

Yay, regular expressions. Be sure what you mean.

To match any character including newlines:

  • In JavaScript or any other language lacking the s modifier, use /[\s\S]/.
  • In Ruby, use /./m, but be aware that this also modifies ^ and $. If unsure, use /[\s\S]/.
  • If you have true PCREs, you may safely use /./s.

Note that this is often what you really want—rarely do you want to explicitly match every character except newlines. If you do that on purpose, at least leave a comment to that effect, otherwise your coworkers will just assume you didn’t know what you were doing.

  1. Or just gets thrown away if you use Regexp.new directly.

Writers of all stripes enjoy engaging in the most cynical readings of human behavior because they think it makes them appear hyper-rational. But in fact here is a perfect example of how trying to achieve that makes you irrational. Human emotion is real. It is an observable phenomenon. It observably influences behavior. Therefore to fail to account for it when discussing coupling and relationships is the opposite of cold rationality; it is in fact a failure of empiricism.

L’Hote on Kate Bolick’s “All the Single Ladies”.

coworker: If it were a critical task, how long to get that UI up and running?
me: Probably about the same amount of time if it were non-critical, all things considered
me: Maybe a little longer
me: Stress tends to make tasks drag out

Reference.

An employee of the company who mantains Mongo, who appears to be assigned Erlang driver maintenance lately, seems to deduce that the tests fail1, and so changes an API which has been stable for 2 years in order to “make the tests pass”, despite also changing the tests.

WAT.

  1. they don’t.

book cover of Practical Common Lisp Practical Common LISP by Peter Seibel

My rating: 4 of 5 stars

Just what Common Lisp needed: a book that doesn’t bubble at the mouth, frothing over how every other language is attempting to be CL but failing; a book that doesn’t tell you how macros mean you can write EVERY LANGUAGE EVER in CL; a book that doesn’t tell you how CL’s macros are the best thing since sliced bread, then follow it up with totally shit examples of what macros are actually used for; a book that actually tours the standard library in a semi-sensical fashion, and covers practical things you might actually want to do, and in the meantime does a pretty decent justice to the rather large language that is Common Lisp.

In short, a rather good book, suitable for total beginners to Lisp and Common Lisp.

I found that it lost traction at times—sometimes it degenerated into a little bit of a reference, and you felt like you were reading a dictionary—but fairly quickly it recovered and had your attention again (while still being didactic). Similarly, the practicals in the last few chapters were almost too well-architected; I really just felt like I was building the target application, sort of learning the techniques, but ultimately it wasn’t necessarily interesting.

Finally, the topics glossed over in the conclusion are probably more important to someone wanting to build real applications with Common Lisp (i.e. relating to “practical Common Lisp”) than some of the stuff that could probably be gleaned from an evening with the HyperSpec—finding libraries and deploying applications are two very big question marks for any Lisp developer. This is partly a result of developments in these areas being even more recent than the book (e.g. QuickLisp development began in 2010, after the book’s last copyright year of 2009).

All in all, an excellent introduction to the world of Common Lisp.

Go — awesome. Lack of support for “generics” kinda sucks. (list mapping sucks) []interface{} is useless sometimes. Damnit, I really just want a map function.
Haskell — lovely. Hard to get things to “just work” sometimes due to fun inherent in IO/monads.
OCaml — great. Haskell without the monad crap, but a crappier syntax. begin/end blocks uglify much. Try to go too functional and you run into the limitations of impurity.

The previous post is a message to myself, so I don’t need to justify it. But I’ll justify it here for anyone else:

These are the experiences of my gender I always wanted but never had. Like anything you identify with, there are these moments where you realise that you’re experiencing some fundamental part of that identity which makes you feel like you’re really a part of it. And for me, this is part of it.

natsu

sairyx

You know what’s an awesome combination for a summer’s night?

Lying on your bed with your skirt down to your knees, stripy socks keeping your legs comfortable (and hair hidden!), liking who you are and how you feel.

Lots of love,

Not Afraid To Say Things Just As They Are

Timing

sairyx

I have an issue which maybe will one day not be so dire.

Advance warning: I’m talking about sex, and specifically my behaviours regarding it, so you may regard part of this as “TMI”. Reader discretion is advised.

As you may know, my (wider) moods are largely dictated by cyclothymia, a mood disorder which shares a spectrum with bipolar. I didn’t really realise fully myself my own nature until I came to live with my friend, Alex. He’d heard about my problems for years prior to then, but once we were living together, regularly going for walks together, he started to tell me more and more about the patterns he was seeing.

I’ve certainly come a long way since then, in terms of managing my behaviour. That’s not to say I let the label define me, but nonetheless I take certain precautions when I understand that my mood is taking a turn (for no other reason that it wants to—and that is the frustrating thing), and usually my life isn’t taken apart by myself once I start to come back up.

Unfortunately, sexual drive is nearly impossible to regulate, as I’m messed up no matter what mood I’m in. As in any depressive state, I have nearly zero interest in sex when I’m in a down period. The thought never enters my mind, and if raised by my partner, it feels (to me) like she’s talking about something that’s just not installed. The concept makes sense, but actually doing anything like that? On reflection, it seems crazy just how asexual I feel. I guess I didn’t really realise that could happen to me, until I realise it does, all the time (eg. now!).

Of course, when I’m up, it’s a different thing, and it’s even more problematic. I don’t experience mania per se, but something like that watered down. Correspondingly, my sex drive increases. So too do my hormone levels (or my awareness thereof). So, too does my feeling of acute dysphoria. I know exactly how I’d like my body to feel, to myself, and it feels in so many ways the polar opposite. Disgusting is a word I rarely have need to use seriously, but I really do feel that way about myself at these times, because of my sex drive.

And thus it occurs that it’s really hard for me to enjoy what should otherwise be a nice way to bond with my partner, and sometimes difficult to live with myself.

My programming lately has sort of stagnated; not (entirely) in the traditional sense that I’ve just stopped or lost the inspiration, but that I tend to have been doing lots of smallish or trivial things that maybe don’t actually warrant my time.

The most recent project was writing the Erlang::Parser module for Perl, now distributed on the CPAN. This was a really great way to get to grips with Perl, Moose, and another excuse to write a parser. The resulting module may also prove handy in my line of work, where it might be beneficial to extend Erlang’s syntax with our own additions without having to modify Erlang’s own parser. I also wanted an excuse to have a module on CPAN, and I hope this isn’t the last module I release there.

While it was fun, and a lovely result for the test case—verifying that all of MochiWeb parses correctly—to finally pass on CPAN Testers, the original purpose for which I wanted to parse Erlang code has now gone.

I was toying around with an idea for an OS that implemented Erlang-style light-weight processes with mailboxes (and little else) as the core process type. Rather than inventing a new syntax, or indeed, language, I thought it might also be an idea to parse Erlang (which I thought couldn’t be that hard).

First, I started a prototype in Go, then decided I’d do a quicker and hackier one in Ruby; I cooked my own lexer, and my own not-very-LALR(1) parser generator, but ran out of steam shortly after my home-grown parser started having to deal with precedence issues—or not deal, as it ended up. When my Perl proficiency started to pick up, I started pawing through the Parse:: namespace and realised, in the Perl spirit of things, that I could build on some giants’ shoulders and probably end up with a parser in short order. Thus was born Erlang::Parser.

The first release of E::P such that one of its then 3 modules would end up being module #100,000, at least according to the small count in the lower-left corner of search.cpan.org. From what I could tell, I think I was successful; I uploaded E::P 0.1 to PAUSE when the number read 99,999; it updates quite slowly, but the next update was 100,002, so it was either E::P, or some other 3-module distribution that made #105.

I couldn’t leave the job half finished; even if it did parse enough Erlang at 0.1 to suit my needs, I wanted to do the job properly, now that it was on the CPAN. So I selected MochiWeb as the test case, assuming it would end up using every syntactic quirk of the language at least once. 0.2 ended up being able to fully parse (and verify that it did so to some degree of correctness) MochiWeb.

Now I was parsing code correctly, but the interface of E::P sucked; the AST nodes were just arrays, with the first element being a string describing the type of node, and the remaining elements differing (somewhat arbitrarily) according thereto. If I wanted the module to be really usable (and maintainable), I’d have to make the node types better defined. So I learned to cook a Moose, and then OO-ified the AST nodes. I also spent a lot of time writing POD for every node kind, which I’m glad I did now. That was 0.3. 0.4 was including the Parse::Yapp-generated parser in the distribution, as my Makefile.PL-fu is weak and most CPAN Tester reports were failing due to the generated parser’s absence.

A bit before that, I was enjoying exercising in Golang, and so a few weeks’ spare time were spent writing enwd, a Go DNS server. The name is a pun(?): ‘enw’ is Welsh for ‘name’, and the most popular DNS servers tend to be referred to as ‘named’ (name daemon). Getting things like compression was an exercise in following RFCs.

enwd still seems to disagree with some upstream servers, and doesn’t support recursion, but otherwise it’s a fully functional DNS server. The only thing it lacks is a sufficient administration interface to actually create the zone (!). My plan was for it to support interactive zone editing via HTTP—which it has the beginnings of—but doing that kind of front-end UI work for me is, frankly, pretty boring.

I pushed myself along for a bit, but commits become fewer and further between. The work stopped once I was in the thick of the admin interface.

Other recent-ish projects include golex, a lexical analyser-generator for Go (which makes use of Go’s nifty Go parser and AST manipulation libraries—a must for any language worth its salt!), kotaete, a not too-seriously open-sourced project in PHP which I used to quiz friends on which baby names they preferred.. and somehow not too much else. I suppose HaeSeun also counts—her source isn’t open, however.

The more I look at this paltry(!) list, the more I wonder where my time has been going.. outside of work, family, Loki, etc. I made a few abortive attempts at reviving very old game ideas, and messed around a bit with programming language ideas. Really, though, I’ve been gearing so much thought towards systems programming.

Rob Pike’s “Systems Software Research is Irrelevant” talk from 2000 continues to exact as much of an effect on my thoughts about the subject as it did when I first read the slides (the contention of which, if you hadn’t guessed it, is other to that which the title suggests). See page 6: the software and language stacks we used in 1990 (Unix, X Windows, Emacs, TCP/IP, C, C++) were still used in 2000, with the addition of Netscape, Java, and a little Perl. What’s changed in 2011? Netscape lives on as Firefox, and programming languages fade out of and back into obscurity. The web has probably been the single biggest change in ‘software’ since 2000, which is fitting (with regards to the talk) as it actually largely escapes the realm of the concerns of systems software. I still think systems software research is really important.

In a future post1, I’ll expand on why I’m thinking that microkernels will probably be a large part of how I choose to spend my free time. I want to stop frittering away my spare time on aimless (though fun) projects, and start trying to actually stretch my creativity, and maybe make something novel while I do it.

  1. famous last words?