Common Lisp Package: CL-ALGEBRAIC-DATA-TYPE

README:

FUNCTION

Private

Undocumented

ENSURE-CAR (X)

ENSURE-LIST (X)

FIELD (NAME N)

GEN-NAMES (N)

GET-CONSTRUCTORS (ADT)

INTERNAL (S)

SET-CONSTRUCTORS (ADT CONSTRUCTORS)

UNWRAP-SINGLETONS (LIST)

WILD? (S)

MACRO

Public

DEFDATA (ADT-NAME &BODY CONSTRUCTORS)

Define a new ADT. ADT-name has the following grammar: ADT-NAME := <symbol> | (<symbol>) | (<symbol> :MUTABLE) There is no difference between specifying it as a symbol or as a singleton list. Specifying :MUTABLE will make DEFDATA mutable, allowing the use of SET-DATA. Constructors is a list of clauses with the following grammar: <clause> := <symbol> | (<symbol> <type-specifier>*) Each clause defines a constructor for the ADT. Nullary constructors will define constants and all other constructors will define functions.

MATCH (ADT OBJ &BODY CLAUSES)

Perform pattern matching on OBJ with (adt-type) ADT. Each clause must have the following syntax: <var> := <symbol> | '_' <lhs> := '_' | (<symbol> <var>*) <clause> := (<lhs> <lisp code>) The symbol '_' denotes a wildcard, as well as a fallthough. Note that pattern matching is only shallow (patterns are one-level deep).

SET-DATA (OBJ (NAME &REST NEW-VALUES))

Mutate the fields of the ADT value OBJ whose constructor is NAME and whose updated values are NEW-VALUES based on order. If the symbol '_' is used as a value, that field is not updated. Trailing '_' may be omitted.

WITH-DATA ((NAME &REST VARS) OBJ &BODY BODY)

Destructure the ADT value OBJ, whose constructor is NAME. VARS must be symbol which will be bound, or they must be the symbol '_', which means the value will not be bound.

Private

Undocumented

DEFINE-CONSTANT (NAME VALUE)

VARIABLE

Private

Undocumented

*CONSTRUCTORS*