cl-algebraic-data-type

API Reference

cl-algebraic-data-type

A library for algebraic data types.

CL-ALGEBRAIC-DATA-TYPE

A package for defining algebraic data types.
  • Struct ALGEBRAIC-DATA-TYPE
    Abstract type for all algebraic data types, primarily used to identify such types.
    No slots.
  • Function ALGEBRAIC-DATA-TYPE-P (type)
    Is TYPE a known algebraic data type?
  • Function ALGEBRAIC-DATA-VALUE-P (value)
    Is the value VALUE that of some algebraic data type?
  • Function GET-CONSTRUCTORS (adt)
    Get the constructors and their arity for the adt ADT. Two values will be returned: 1. If the ADT exists, then a list of pairs (CONSTRUCTOR-SYMBOL ARITY). If the ARITY is zero, then the CONSTRUCTOR-SYMBOL is a value as opposed to a function. 2. T if the ADT exists, NIL otherwise. This mimics the behavior of GETHASH.
  • Variable *PRINT-ADT-READABLY*
    t
    Print preceding #. when printing ADT values.
  • Macro DEFDATA (adt-name &body constructors)
    Define a new ADT. ADT-name has the following grammar: ADT-NAME := <symbol> | (<symbol> <options>*) There is no difference between specifying it as a symbol or as a singleton list. There are two possible options, specified as a property list: * :MUTABLE {T, NIL} (default: NIL): Specifies whether the fields of the type are mutable, allowing the use of SET-DATA. * :INCLUDE <adt-type>: Specifies whether another defined ADT should be inherited. 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.
  • Macro 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.
  • Macro 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.
  • Macro 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).