Archive for the ‘School’ Category.

Reflection in Scheme

I’ve been mulling over this idea for a while.

Now that I’ve been programming (exclusively) in Scheme for the past two years, I realized that I have slowly — but surely — learned to accept and embrace one of the most controversial surface syntax in a programming language: the S-Expression.

The criticism to sexpr syntax are numerous, and most of them can be seen as silly once you have gotten used to it, however here lies the problem: most people never get past their initial reaction to sexpr. They see the parenthesis and just freeze up.

Lispers and Schemers are the first to point out the advantages to having such a syntax: it’s simple, easy to understand and parse, and concise. In the end, however, it actually all boils down to just one single thing: We know how to write awesome macro systems with a sexpr surface syntax.

And this is all well and good.

However, now that we have decided to stick with this syntax, and we have used it to our advantages to write many wonder macro systems, what else can we do with this decision?

In Scheme, when you write down a list of four elements, beginning with the word list like this:

(list 'apple 'banana 'cactus) => '(apple banana cactus)

You get a list with three elements. You can query it in the following ways:

(list?  '(apple banana cactus)) => #t
(length '(apple banana cactus) => 3
(first  '(apple banana cactus))   => apple
(last   '(apple banana cactus))   => cactus

So you are able to find out that it is a list, and from that, its length and its first and last element.

This is elementary stuff, and anyone learning Scheme would know this by the end of their first week in class. However, what about this?

(define hello (lambda () (display "Hello")))

This is again a list, of three elements. The first element is define, then hello and last is another list (which begins with the word lambda).

In R5RS Scheme, there’s virtually nothing you can do to query this structure. The most that you can do, as far as I know, is with MIT Scheme’s procedure? and procedure-arity procedures, which corresponds to list? and length for lists.

Wouldn’t it be cool if one could manipulate Scheme code (procedures) as easily as one could manipulate Scheme data (lists, vectors)? I don’t mean that there should be a procedure-car and procedure-cdr, but something more specific, like procedure-name and procedure-body. This can be extended to other constructs as well. Given:

(if (list? l) (length l) 0)

We could have

(expression-type? ##) => <if-expression>
(if-test          ##) => (list? l)
(if-then-clause   ##) => (length l)
(if-else-clause   ##) => 0

Why hasn’t this been done before? I did some literature research, and am surprised to see so little on this topic.

Recently, I came across Charlotte Herzeel’s talk at the S3 workshop, but I think she’s going about it in the wrong way because she’s only thinking about the manipulation of code as lists, using variations of car and cdr instead of something with more specific semantics attached to it. Perhaps her background in Common Lisp (instead of Scheme) maybe have something to do with that.

Digging the Scheme Underground

Now that I’m blogging again, I ought to write down what I have been doing for the past few months.

When I got back to the US last spring, I went to talk to Olin Shivers about my idea of implementing R5RS on top of Alan and Ian’s COLA runtime. While I think that is still a good idea, it didn’t pan out then and I moved on to work on something else.

Instead I have been working with Olin to restart the Scheme Underground effort that has (pretty much) been abandoned since the early 90s. Our initial plan was to work on a nice interactive shell that’s based on Olin’s work on scsh, however that idea was abandoned after realizing that the Tüebingen crew already did something similar with Commander S. However, with its customizable viewers, Commander S is actually quite a bit more than just a normal interactive shell, so I still think it’s interesting to implement our original (simpler) concept.

To get up to speed on Scheme, I learned about Termcap and Terminfo and ported Paul Foley’s terminfo.lisp to Scheme. I also took another Common Lisp project, Linedit, as inspiration and wrote my own Scheme version from scratch.

Lately, I have been working on porting MIT Scheme’s Edwin editor to Scheme48. I hope to get a terminal-based text-only version done before the beginning of the summer. Wish me luck.

A New Beginning

Didn’t feel like working this afternoon, so instead, I updated my blog software to WordPress 2.5.

Here’s some Scheme code for all of you fans out there:

(define-record-type keystroke
  (%make-keystroke %value %meta?)

  (%value char-value)
  (%meta? meta?))

(define-record-discloser keystroke
  (lambda (k)

 Keystroke ,(keystroke->sexpr k) ,(keystroke-hash k) )))


  (parse-key form)
  (if (list? form)
      (let ((tag (car  form))

            (val (cadr form)))
        (case tag

 control) (

 %control  (parse-key val)))
          ((meta)    (

 %meta     (parse-key val)))

      (%key     val))


       (error "This is not a valid key form " tag))))
      (%key form)))

An Update from Me

Haven’t been writing for quite a while. I just upgraded my installation of WordPress to the new and spiffy 1.5, so I figured I should write an update.

I have been pretty busy at school lately. On top of normal school stuff , tutoring (and grading) CSU 213, I’ve been also teaching my twice a week class on XML. I also did a guest appearance in Prof. Lorenz’s Object-Oriented Design class last week, so that got me to download a new Squeak image and brush up my Smalltalkin’


On the Mono front, I plan on tackling Bug 63360 this weekend (hopefully), after talking to Carl (at XDevConf) and Prof. Rasala from school. It will also be nice to finish up the work on 68711 that has been lingering since Christmas as well.

I had dinner with Anthony last night at my favorite Thai place in Coolidge Corner , it’s good to see him. I wish him good luck in SoCal.

Election Day

I tried to install a Wiki this afternoon, for organizing the work I’m doing for Professor Lorenz. I tried PhpWiki, MoinMoin and PmWiki.

In the end, I chose PmWiki, cuz it’s so much easier to install than the others. The rest of them are a mess.

There was a scare just now. All my entries disappeared. I thought I had messed up the MySQL database and lost all my entries. I was just about to start re-importing the old entries from LiveJournal, but I popped into #wordpress and asked for some help. Turns out it was a simple cookie/cache problem. Whew!

Here’s a link to My Wiki.