API for types (master branch)

by Konrad Hinsen

Usage:
(ns your-namespace
  (:require clojure.contrib.types))

Overview

General and algebraic data types

Public Variables and Functions



defadt

macro
Usage: (defadt type-tag & constructors)
Define an algebraic data type name by an exhaustive list of constructors.
Each constructor can be a symbol (argument-free constructor) or a
list consisting of a tag symbol followed by the argument symbols.
The data type tag must be a keyword.
Source


deftype

macro
Usage: (deftype type-tag constructor-name docstring? attr-map?)
       (deftype type-tag constructor-name docstring? attr-map? constructor)
       (deftype type-tag constructor-name docstring? attr-map? constructor deconstructor)
Define a data type by a type tag (a namespace-qualified keyword)
and a symbol naming the constructor function. Optionally, a
constructor and a deconstructor function can be given as well,
the defaults being clojure.core/identity and clojure.core/list.
The full constructor associated with constructor-name calls the
constructor function and attaches the type tag to its result
as metadata. The deconstructor function must return the arguments
to be passed to the constructor in order to create an equivalent
object. It is used for printing and matching.
Source


deftype-

macro
Usage: (deftype- type-tag constructor-name & optional)
Same as deftype but the constructor is private.
Source


match

macro
Usage: (match value & clauses)
Given a value and a list of template-expr clauses, evaluate the first
expr whose template matches the value. There are four kinds of templates:
1) Lists of the form (tag x1 x2 ...) match instances of types
   whose constructor has the same form as the list.
2) Quoted lists of the form '(x1 x2 ...) match lists of the same
   length.
3) Vectors of the form [x1 x2 ...] match vectors of the same length.
4) Maps of the form {:key1 x1 :key2 x2 ...} match maps that have
   the same keys as the template, but which can have additional keys
   that are not part of the template.
The values x1, x2, ... can be symbols or non-symbol values. Non-symbols
must be equal to the corresponding values in the object to be matched.
Symbols will be bound to the corresponding value in the object in the
evaluation of expr. If the same symbol occurs more than once in a,
template the corresponding elements of the object must be equal
for the template to match.
Source
Logo & site design by Tom Hickey.
Clojure auto-documentation system by Tom Faulhaber.