is Ben Rudgers

Learning to Read Lisp: Part A

I’ve always struggled to look at Lisp and figure out what was going on, and so I was working through Quick: An Introduction to Racket with Pictures in preparation for the upcoming course Introduction to Systematic Program Design at Coursera [it starts June 3rd 2013] when I typed in this code:

  (define (series mk)
      (hc-append 4 (mk 5) (mk 10) (mk 20)))

and I went “huh?”

My next thought was, I should rewrite it like this so that I understand it:

  (define (series mk)                        ;Series takes a procedure as its argument
      (hc-append 4 (mk 5) (mk 10) (mk 20)))  ;mk is a procedure

I often feel a need to add this level of comment to any code I write. It was only later, as I was walking the dog, that I realized how unnecessary the comments are in this case – (mk 5) gives the game away. It’s position as first element in an unquoted list means that it has to be a procedure.

This does not mean that the converse – that position insures us that something is not a procedure – is true:

  (define (pork pie)
      (series pie))

So maybe I am back to all my comments. But at least now there are cases where I can read someone else’s code more fluently.