Symbols in Lisp

Joe Marshall over at Abstract Heresies has a post that makes a point that’s easy to forget: Lisp has symbols and those symbols should be used in preference to strings or integers to represent arbitrary state constants. Most other languages don’t have symbols so you’re forced to use strings or enums for those state constants.

For example, a file-reading function in a non-Lisp language might return -1 or some other integer on end-of-file. In Lisp, you would simply return a symbol such as ’eof. As Marshall says, strings are composite objects with their own functions to manipulate them. Symbols are atomic objects that don’t really have any structure. Symbols are basically pointers to a memory location so it’s very efficient to implement things like comparisons.

It’s a short and simple post but, as I said, a useful reminder.

This entry was posted in General and tagged . Bookmark the permalink.