Element ยท the document

define

A named, reusable stack, written in a parts file and called like an element. Its param lines are the controls a caller can set. A definition whose stack is one thing is itself a thing: it can be placed with at= or scattered.

A tile in three strips of grass: a full lawn on the left, a thin patchy lawn in the middle, long tall blades on the right.
One definition, lawn, called three ways, left to right: with its defaults, with cover="35%" clearings=6, and through long-grass, a definition that calls lawn with longer blades. From docs/elements/demo/define.dtile.

Writing it

dharmatiles version="1.0.0"

// library/parts/grass.dtile
define lawn {
    param length "3.5dmm .. 6.5dmm"   // blade length along the ground
    param height "1.5dmm .. 2dmm"     // how tall a blade stands
    param clearings 0                 // patches of bare earth per square
    param cover "100%"                // share of the ground grassed over
    stack {
        grass length=length height=height clearings=clearings cover=cover
    }
}

define long-grass {                   // a definition can call another
    stack { lawn length="5dmm .. 9dmm" height="2dmm .. 3dmm" }
}

A tile then writes use "parts/grass" lawn and lawn cover="80%" in its stack.

Reference

WrittenTakesDefaultWhat it does
define NAMEa nameโ€”What callers write. Required.
param NAMEa default, or noneโ€”A control callers may set. Its kind is its default's: param length "3.5dmm .. 6.5dmm" is a length, param clearings 0 a count, and a caller that writes length=5 is asked for 5dmm (dt::unit). With no default, the caller must give it, and its kind is the control it fills.
stackโ€”What it makes. Exactly one.

Notes

A place given to the call (at=) pass through to the elements inside, and a call's top= is the height of the tree inside it (oak top="$bottom + 40dmm"). Expert controls, such as a tree's branch knobs, are allowed only in parts files. Definitions that call each other in a loop are an error (dt::loop). A tile has no params. A part has no tile of its own, so a point it writes ("(50%, 0.5sq)") is worked out at each place it is called, and a $ name it reads comes from its caller: check refuses a call whose context lacks one.

Seen from the language

The guide pages that use define: The tile document, Parts.