2. Fields, blocks, and comments

The two structural pieces every document is made of, plus how to annotate them.

After this lesson you can

- Bind names to expression values with = - Author block instances with one or more labels - Comment WCL source with //

Before you start: Install wcl and check your first file

A field binds a name to a value with =, and the value is any expression — a literal, a reference to a sibling field, a call, or arithmetic. A block is a named group of fields that can nest further blocks; its positional labels map to fields via the schema's @inline slots, so route "GET" "/users" fills two fields at once.

Line comments start with // and run to the end of the line. The formatter preserves them, so comment freely — they survive wcl fmt.

§ 1Exercise: Author blocks against a schema

Given a two-label route block kind, author two endpoints and validate them.

wcl
// The API surface — one route block per endpoint.
@block("route")
type Route {
  @inline(0) method: utf8
  @inline(1) path:   utf8
  handler: utf8
}

@document
type Api {
  @children("route") routes: list<Route>
}

route "GET"  "/users" { handler = "list_users" }
route "POST" "/users" { handler = "create_user" }

Expected result

wcl check prints OK — each route block contributes one Route, its labels filling method and path.

Hint

Labels are positional: slot 0 is the first label after the kind. Swap the two strings and the block still checks — WCL can't know a verb from a path — so keep the order the schema documents.