October 22nd, 2008

From encouragement to pitfalls

Yoni Rabkin put together an elisp file of Common Lisp pitfalls. It will display one at random when slime starts up. Here are a few examples:

REMOVE- and DELETE-DUPLICATES keep the _later_ (in the sequence) of two matching items. To keep the earlier items, use :FROM-END T. Remembering that :FROM-END exists may make it easier to remember the default behavior.

READ-FROM-STRING has some optional arguments before the keyword parameters. If you want to supply some keyword arguments, you have to give all of the optional ones too. Other functions with this property: WRITE-STRING, WRITE-LINE, PARSE-NAMESTRING.

Some Common lisp operators use EQ, rather than the usual EQL, in a way that cannot be overridden: CATCH, GET, GET-PROPERTIES, GETF, REMF, REMPROP, and THROW. See table 5-11 on p 5-57 of the standard.

Many of these seem to be about having correct expectations. For example, the wording in the standard is pretty clear that you shouldn't expect a particular initial element in arrays unless you provide one explicitly. For a long time, I expected number-specialized arrays to be initialized to 0 and other arrays to be initialized to NIL. I didn't have a good reason to expect that, it's just what my implementation seemed always to do. I learned the correct expectation after using an implementation that puts random garbage into arrays that aren't explicitly initialized. I thought it might be a bug until I actually read the specification.

Take a look. Can you suggest some more to add?