Enumerated Type - Lisp

Lisp

Common Lisp uses the member type specifier, e.g.

(deftype cardsuit '(member club diamond heart spade))

that states that object is of type cardsuit if it is #'eql to club, diamond, heart or spade. The member type specifier is not valid as a CLOS parameter specializer, however. Instead, (eql atom), which is the equivalent to (member atom) may be used (that is, only one member of the set may be specified with an eql type specifier, however, it may be used as a CLOS parameter specializer.) In other words, in order to define methods to cover an enumerated type, a method must be defined for each specific element of that type.

Additionally,

(deftype finite-element-set-type (&rest elements) `(member ,@elements))

may be used to define arbitrary enumerated types at runtime. For instance

(finite-element-set-type club diamond heart spade)

would refer to a type equivalent to the prior definition of cardsuit, as of course would simply have been using

(member club diamond heart spade)

but may be less confusing with the function #'member for stylistic reasons.

Read more about this topic:  Enumerated Type

Famous quotes containing the word lisp:

    Taught me my alphabet to say,
    To lisp my very earliest word,
    Edgar Allan Poe (1809–1849)