Search code examples
typescommon-lispfirst-class

In what sense are types in Common Lisp first-class?


Peter Norvig famously claimed that many OOP design patterns are trivial or redundant in Lisp. Slide #10 here claims that first-class types replace many of them.

In what sense are types first-class in Common Lisp? For reference, Structure and Interpretation of Computer Programs gives the following as the conditions that an element of a programming language must satisfy to be considered first-class:

  1. They may be named by variables.

  2. They may be passed as arguments to procedures.

  3. They may be returned as the results of procedures.

  4. They may be included in data structures

a demonstration that types in Common Lisp satisfy the above conditions would be a wonderful answer.


Solution

  • Types are not first-class in Common Lisp: the language exposes no object which represents a type and thus trivially fails all the requirements you give.

    Classes are first-class and classes correspond to a subset of types.

    Type specifiers are also first-class: a type specifier like integer or (integer 0 (10)) is obviously first-class because symbols and lists are first-class. But type specifiers are not types, any more than the symbol cons or the list (lambda (x) x) is a function.

    So Norvig is wrong about this.