CBCL / DocumentationDocs v0.3.1

Shapes and types

A shape specifies the mandatory and optional fields for a verb. It specifies which values each field accepts. Two or more shapes can use the same named type.

(define parcel-label (cbcl) @warehouse
  (type label (string (length (>= 1) (<= 8)) (matches "[A-Z]+")))
  (extend mark (to code) (tell to :code code))
  (shape mark
    (require :code label)
    (optional :priority (one-of "normal" "urgent") (default "normal"))))

The code "AB" satisfies the label contract. The code "Ab" fails the pattern. The code "ABCDEFGHI" exceeds the length limit.

On this page

Field rules

FormMeaning
(require :key type)The field must exist. Its value must satisfy the type.
(optional :key type)If the field exists, its value must satisfy the type.
(optional :key type (default value))Declare a default for the optional field. The default must satisfy its contract.
(max-depth n)Set a depth limit for this shape.

The type is optional in a field rule. Child rules can follow the type and any default. For example, (require :details list (require :code string)) checks a field in the details list.

Built-in types

TypeAccepted values
integer, nonnegativeSigned 64-bit integers. The second type accepts only zero and positive integers.
float, decimalFinite binary64 and exact decimal values, respectively.
numberInteger, float, or decimal values.
string, symbol, keyword, bool, listThe corresponding CBCL value.
hlcA string with the canonical hybrid logical clock format, such as "hlc-0000000000000001-00000000".

See Text and values for the literal forms.

Type expressions

ExpressionMeaning
(one-of "red" "blue")Accept one of the listed scalar literals. A symbol here is a literal.
(integer (> 0) (<= 20))Apply all numeric comparisons. Numeric bases are number, integer, float, and decimal.
(string (matches "[A-Z]+"))Match the entire string with an I-Regexp pattern.
(string (length (<= 32)))Count Unicode scalar values in a string.
(list (length (>= 1)))Count elements in a list.
(and a b), (or a b)With and, the value must satisfy all expressions. With or, it must satisfy one or more expressions. Each form must contain two or more expressions.

Length and numeric bounds use <, <=, >, or >=. Use nonnegative integers for length bounds. A local type name starts with a lowercase letter. It can contain lowercase letters, digits, and hyphens, up to 48 characters. Built-in names and reserved type operators are unavailable as local names.

A shape checks the message fields. A state domain can also restrict which values contribute to a projection. For example, a choice can be a valid string but absent from the poll options.