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. 🙂