SBCL User Manual
Prev | Chapter 4. Beyond The ANSI Standard | Next

# Idiosyncrasies

The information in this section describes some of the ways that SBCL deals with choices that the ANSI standard leaves to the implementation.

Declarations are generally treated as assertions. This general principle, and its implications, and the bugs which still keep the compiler from quite satisfying this principle, are discussed in the chapter on the compiler.

SBCL is essentially a compiler-only implementation of Common Lisp. That is, for all but a few special cases, `eval` creates a lambda expression, calls `compile` on the lambda expression to create a compiled function, and then calls `funcall` on the resulting function object. This is explicitly allowed by the ANSI standard, but leads to some oddities, e.g. collapsing `functionp` and `compiled-function-p` into the same predicate.

SBCL is quite strict about ANSI's definition of `defconstant`. ANSI says that doing `defconstant` of the same symbol more than once is undefined unless the new value is `eql` to the old value. Conforming to this specification is a nuisance when the "constant" value is only constant under some weaker test like `string=` or `equal`. It's especially annoying because `defconstant` takes effect not only at load time but also at compile time, so that just compiling and loading reasonable code like

    (defconstant +foobyte+ '(1 4))

runs into this undefined behavior. Many implementations of Common Lisp try to help the programmer around this annoyance by silently accepting the undefined code and trying to do what the programmer probably meant. SBCL instead treats the undefined behavior as an error. Often such code can be rewritten in portable ANSI Common Lisp which has the desired behavior. E.g., the code above can be given an exactly defined meaning by replacing `defconstant` either with `defparameter` or with a customized macro which does the right thing, possibly along the lines of the `defconstant-eqx` macro used internally in the implementation of SBCL itself.

SBCL gives style warnings about various kinds of perfectly legal code, e.g.

- `defmethod` without `defgeneric`

- multiple `defun`s of the same symbol

- special variables not named in the conventional `*foo*` style, and lexical variables unconventionally named in the `*foo*` style

This causes friction with people who point out that other ways of organizing code (especially avoiding the use of `defgeneric`) are just as aesthetically stylish. However, these warnings should be read not as "warning, bad aesthetics detected, you have no style" but "warning, this style keeps the compiler from understanding the code as well as you might like." That is, unless the compiler warns about such conditions, there's no way for the compiler to warn about some programming errors which would otherwise be easy to overlook. (related bug: The warning about multiple `defun`s is pointlessly annoying when you compile and then load a function containing `defun` wrapped in `eval-when`, and ideally should be suppressed in that case, but still isn't as of SBCL 0.7.6.)

Prev | Home | Next
Beyond The ANSI Standard | Up | Extensions