Ruby’s Lisp Heritage

There’s an article The Ruby VALUE on O’Reillynet today. It shows a rather neat hack whereby ruby uses a few bits of an integer to specify extra information, like whether the value is nil or not.

It does mean that FixNums only go up to 230 instead of 232, but that’s not a serious limitation, because it transparently turns them into BigNums instead.

All of this reminded me of a very similiar situation in another piece of software: Emacs. Like ruby, it uses a few extra bits in the word to signify the type of an object (Integer Type).

Note that Lisp is unlike many other languages in that Lisp objects are self-typing: the primitive type of the object is implicit in the object itself. For example, if an object is a vector, nothing can treat it as a number; Lisp knows it is a vector, not a number.

But it’s not only Emacs, lisps in general have a history of doing this. This leads to the lovely notion that the data has a type as opposed to the variable, which seems to confuse C programmers so much. 🙂



Top top for using irb, the interactive ruby environment. Stick this in your ~/.bashrc or equivalent.

irb --readline -r irb/completion

And now you get nice completion of class and method names inside ruby. Lovely! Just like Python’s rlcompleter.

More info from Why’s Poignant Guide (which could use a few anchor’s).

As a side note, Ubuntu really needs to learn to install a few more Ruby packages by default. It’s missing webrick, yaml, irb, ri, erb and a lot of other stuff that should be standard in ruby 1.8. Grrr. Oh, it’s a bigger problem



Rake is Ruby’s equivalent of make(1). Martin fowler has just posted an excellent article, Using the Rake Build Language, which explores how it works, using his own site’s build file as a comparison. It also compares it to make and ant. I find it really nice how easily Ruby lets you build your own little Domain Specific Language. It doesn’t necessarily look much like Ruby, but that’s because Ruby really doesn’t have much syntax itself.

It’s worth remembering this introduction because if you play with Rails, then you get a Rakefile thrown in for free.