Blog: 2009-11

Latest  2014  2013  2012  2011  2010  2009  2008  2007  2006  2005  2004  2003  2002  2001
-12  -11  -10  -09  -08  -07  -06  -05  -04  -03  -02  -01

srfi-9-plus

I had some old Scheme code that I wanted to make use custom writing for data types it defined, but it was using SRFI-9, and I didn't want to make it terribly nonportable by using PLT struct directly. So I hacked up the srfi-9-plus library.

Basically, this:

(define-record-type/write foo
  (make-foo aaa bbb)
  foo?
  foo-write-proc
  (aaa foo:aaa)
  (bbb foo:bbb foo:set-bbb!)
  (ccc foo:ccc))

expands to this:

(define-values (foo make-foo foo? foo:aaa foo:set-bbb! foo:bbb foo:ccc)
  (let-values (((type constructor predicate struct-accessor struct-mutator)
                (make-struct-type (quote foo)
                                  #f
                                  (+ 1 1)
                                  (+ 1)
                                  #f
                                  (if foo-write-proc
                                      (list (cons prop:custom-write
                                                  foo-write-proc))
                                      '()))))
    (values
     type
     (begin (%check-constructor 'define-struct-type/write
                                constructor
                                (quote (aaa bbb))
                                (quote (aaa bbb ccc)))
            (let ((make-foo (lambda (aaa bbb)
                              (constructor aaa bbb))))
              make-foo))
     (let ((foo? (lambda (x) (predicate x)))) foo?)
     (let ((foo:aaa (lambda (x) (struct-accessor x (+))))) foo:aaa)
     (let ((foo:set-bbb! (lambda (x v)
                           (struct-mutator x (+ 1) v))))
       foo:set-bbb!)
     (let ((foo:bbb (lambda (x) (struct-accessor x (+ 1))))) foo:bbb)
     (let ((foo:ccc (lambda (x) (struct-accessor x (+ 1 1))))) foo:ccc))))

I used syntax-rules just for fun, to relax on Saturday.

My Coffee Mug

 [photo of coffee mug that has on its surface a photo of teddy bear in bow tie and holding a champagne bottle and a red rose] When I was a little kid, our grandmother gave us all coffee mugs on Christmas or some other traditional gift-giving occasion. At the time, I thought this was a really lousy present for a kid, so it sat unused in its box for years.

When, as a teenager, I went to my first job at a company, I finally unboxed the mug and brought it in. For water, since it would be years before I tried coffee.

Over the years, the mug followed me from job to job, through multiple grad schools, and then more jobs. It was once swiped, and then recovered after I'd feared it was gone for good. It's probably seen a literal ton of water, and it's been stained by perhaps ten thousand cups of coffee, hot chocolate, and herbal tea. It even helped get me through a couple leaner years, when Lipton "chemical soup" packets were free at one job. The mug currently sits on my desk at MIT, and sees active use. I think it's the only material possession I've had for more than 10 years.

My grandmother passed away years ago. In hindsight, the mug wasn't at all a lousy present. Eventually, it'll probably break in an accident, but that will be OK, since it's led a full and exciting life. I no longer have the equipment to shoot a proper portrait of the mug (the mug's mug, ha), but I wanted to at least take a snapshot.

Lisp Manga

 [fragment of a page of Japanese manga comics, with cartoon character apparently explaining Lisp cons cells, including CAR pointer of a cell diagram pointing to a drawing of a car] I heard that MIT was no longer doing SICP, but I had no idea that CS education had become quite so... different.


Remember Your HTML alt Attributes

A while ago, I started trying to be good about adding alt attributes to the img elements in the HTML of this site, for the benefit of the vision-impaired.

I had actually used alt attributes from the early days of the Web, so that pages would display well in a text-only Web browser, such as lynx.

Lately, I assume that the vast majority of people are seeing the images, so I've switched to using alt and title to describe the contents of each image. The emphasis is now on people who can't see any images, rather than to make my pages look pretty to people who could see images, but whose browsers are not showing images at the time.

HtmlPrag 0.19 Changes Tokenizing Behavior

I just released HtmlPrag 0.19, which changes some tokenizing behavior that's probably been there since the beginning.

Specifically, whitespace is no longer allowed after opening `<' for it to be a valid tag. For example, old behavior:

(html->shtml "< a>") ⇒ (*TOP* (a))

New behavior:

(html->shtml "< a>") ⇒ (*TOP* "<" " a" ">")

The motivation was to match what Firefox currently does. I couldn't recall observing a browser tolerate the whitespace, so that might just have been me being overly generous in 2001.


Scheme is Likely Fast Enough for You

I needed to process a corpus of HTML files, which involved a bunch of parsing, XPath-ing, simple pattern-matching, a little regexp-ing, and HTML generation.

Using PLT Scheme, Oleg Kiselyov's and Kirill Lisovsky's SXPath, Jim Bender's sxml-match, HtmlPrag, and WebScraperHelper, I banged it together in a day for a sample of the data, then spent another day tweaking it to run through the entire corpus. Most of the second day was due to some strangely bad HTML buried in some of the 40,000+ files, and having to juggle remote computers.

Afterwards, half tongue-in-cheek, I played fanboy for the benefit of a colleague who still wants to do symbolic processing in C++, laboriously...

And, for people who think Scheme is slow... Wall clock time for the conversion (which was doing lots of parsing, XPath, simple pattern-matching, and a little regexp-ing) was only a little more than twice the wall clock time of "dd" doing comparable file I/O [to local disk]. I didn't bother to optimize the Scheme algorithms, nor compile it to native code. I used PLT Scheme, which isn't a particularly fast Scheme. At the end of a week, when I imagine that a Java or C++ programmer would finish coding, I suspect you'd find that the Scheme runtime performance compares favorably. :)

I don't do much advocacy, but capturing even loose anecdotal evidence of productivity boosts as they happen can be helpful.

BigSkinny Sport Wallets on Sale

If you want a wallet that is not only skinny but also vegan-friendly, the Big Skinny Sport Wallets are on sale for $10 plus $2 shipping.

I got a black one the last time they were on sale (coincidentally, on sale the day after I emailed DIFRWear to inform them that their wallet is too darn big), and mostly like it. The two drawbacks are that I'd rather not have the logo, and only the card at the front of a stack is visible.

First Dates Behavin'

One could write a trashy blog on first dates -- full of the cute, the bizarre, the rude, and the unmentionable -- but that doesn't seem very decent. I can think of only one first date story I feel reasonably comfortable telling here. It was a couple years ago, and rather public...

It was a winter evening, and I had a first date at a coffeehouse in Harvard Square, with an actress who'd already impressed me with her wit.

The upstairs of the coffeehouse has only half a dozen people in it, and I pick a spot in the corner, a couple tables away from this gray-haired couple.

After my date arrives, and we've been chatting a while over tea, the nice gray-haired man asks if we'd mind if he played his acoustic guitar for his companion. We don't mind, and he starts playing "Over the Rainbow." My date remarks that's cool, and we continue talking.

His next song was "Ain't Misbehavin'," (incidentally, a song once given to me on a mix tape), and my date says she loves this song. She kinda whisper-sings a few words here and there, and she's fidgeting and visibly struggling to contain herself.

Suddenly, the floodgates burst open, and she starts really singing, a verse and chorus. And she's excellent (though she cracks a little on a high note at the end). They finish at the end of the chorus, people in the coffeehouse clap heartily, and the guitar guy clearly loves it.

We exchange pleasantries with the other couple. My date says something about not having being warmed up. The guy starts playing again, bringing it down a key(?). Then he prompts her with "ba-doo-ba-doo..." while gesturing towards her with the guitar and a nod.

Then, if anyone wasn't impressed before, suddenly she's really belting it out, in a different style, a class above what she just did, all over the range, total lounge singer, with a little growl and everything, this Irish girl from Boston.

Of course, I'm sitting across from her in the coffeehouse, sipping my tea, and hoping she pulls it off. Which she utterly did.

When they're done, guitar guy gives her the card for his band, and invites her to jam with them sometime.

The girl is flushed afterwards, and suggests we go get some air. We come across the seasonal ice-skating rink in front of the Charles Park Hotel, and end up skating til it closes.

I just now searched for online videos of good female performances of this song, but none I've found do it so skillfully as the impromptu girl in the coffeehouse did.

Earlier to... 2009-10

© Copyright Neil Van Dyke      Contact