Lisp Types

There's been a lot of talk lately about static versus dynamic typing. The partisans on both sides are adamant in their positions and absolutely secure in their righteousness. It has, in other words, become a religious issue.

Although I've used many languages over my career, these days I do virtually everything in either Lisp or C so I have a foot in each camp. I believe, as do most who can shake off their religious fervor, that either paradigm is fine and that each has advantages—and disadvantages—and one should pick the most appropriate choice for the situation at hand.

Lisp, especially, has a bad rap because of it's supposed dynamic typing but the reality is much for complex. Bob Krzaczek over at The Bit Bucket has an excellent post on the Lisp type system and how it works. Although Common Lisp is nominally dynamically typed, you can, in fact, specify types at compile time. That, of course, means that the compiler can use the additional information to generate better code. Often the code will be essentially the same as a C compiler will generate.

Krzaczek's post starts with an example that demonstrates an important point: Lisp will do everything it can to compute the correct result given the arguments it's passed. That's something that, say, C won't necessarily do. For example if you tell C that an input argument is a 32-bit integer and pass it a 64-bit integer, the chances are that C will truncate the input to the lower 32 bits.

Read Krzaczek's post for an explanation of the Lisp type system and how sophisticated it is. If you're a static type partisan, it may be counter-intuitive but Lisp's type system is much more intelligent and flexible than what's found in the typical C compiler.

This entry was posted in Programming and tagged , . Bookmark the permalink.