@define
Defines a template: a new construct whose uses expand to the Chalk written in its body.
On this page
#Attributes
nodeThe new construct's name, written as the implicit value:
:card. It may not be a library construct's name or alias.Can be written as shorthand:
:value#Allowed content
Body { }The template — the Chalk that replaces each use, with {{param}} splices and {{body}}/{{detail}} for the use’s own sections
#Examples
@define:swatch{
square(x: 0; y: 0; radius: 1; colour: {{colour}})
}(
colour: !colour(default: blue)
)
graph{
swatch(colour: red)
}@define:finding{
note{
{{body}}
}
}
finding{Richness scales as roughly the cube root of area.}@define:reading{
point(x: {{at}}; y: {{value}}; label: {{name}})
}(
at: !number(required; implicit)
value: !number(required)
name: !string(default: —)
)
graph{
reading:2(value: 4.1; name: Baltra)
}#Notes
- Each attribute is declared
name: !type(…), the brackets written even when empty;required,default,implicitandaliasesinside them describe the attribute, everything else refines the type. bodyanddetaildeclare the use's{…}and[…]with a content policy —!all(),!none(),!children(…),!inline(…)or!literal()— and default tobody: !all()anddetail: !none().- A value is parsed by its attribute's type where the use is written: node
tile: attributex:abcis not a valid number. - An id written in the template is private to each use; one spelled through an attribute,
square#{{name}}, is the caller's. - An entry whose key starts with
_is an export, read without the underscore as#id.nameon a use with an id. - A template is known after its
@define, inside the construct that holds it; declaring the name again replaces it. - A use takes no
preset:, and the constructs it expands to are checked where they land. - A
@definewith no body is refused: @define: requires a {template} body. - A name that is not an identifier is refused:
2tagis not a valid node identifier. - A library construct's name is refused:
curveis already a library node (canonical name or alias). - A type written without brackets is refused:
!numberonxneeds a declaration group — write!number()even when it is empty. - An unknown type is refused: attribute
von nodetagreferences unknown typeboolean. - A refinement on a named type is refused:
paintis a named type onvand cannot be refined further (min). - A refinement the base type does not have is refused:
numberdoes not define a refinementrequired(it defines: class, min, max). - An attribute both required and defaulted is refused: attribute
von nodetagcannot be both required and defaulted. - A default the type cannot parse is refused: default for attribute
von nodetagis invalid:abcis not a valid number. - A facet written twice is refused:
defaultis written twice onv— and across a union's branches, declaresdefaulton more than one variant. - Two implicit attributes are refused:
implicitis declared on bothaandb— a node has at most one head:slot. - An alias that clashes with another attribute is refused: alias
ncollides with another attribute. - An attribute named
presetis refused:presetcannot be an attribute name. - Union branches that accept the same text are refused: branches
stringandnumberaccept the same text. fieldson a record is refused:fieldsis not written in a declaration group.- A section given a value type is refused:
!string(…)is not a content policy on noderule. - An export that reads a later entry is refused:
_arearefers toside, which is declared after it. - A use that leaves out a required attribute is refused: required attribute
vis missing. - A use with a section the template does not accept is refused: node
carddoes not allow detail content. - A section of constructs spliced inside a line is refused:
{{body}}holds constructs — … declare it a value. - A template that reaches itself as it expands is refused: circular define expansion.