Nanyx

Attributes

Metadata annotations such as @entry and @workflow

Attributes are annotations that start with @ and modify how the compiler treats the declaration that follows.

Basic syntax

Place an attribute immediately before the declaration it applies to:

@entry
def main = { ... }
@workflow
def optionChain = (...)

A declaration can have one or more attributes, each on its own line. An attribute may also precede a field inside a record literal.

Common attributes

@entry

Marks the program entry point: the function the runtime calls when the package is run. A package may contain at most one @entry.

module main

@entry
def main = {
  println("Hello, World!")
}

See Hello, World! and Entrypoints.

@workflow

Marks a workflow builder definition and enables workflow helper generation.

@workflow
def optionChain = (
  try = { ... }
  return = { value -> #some(value) }
  zero = #none
)

See Option chaining and Workflows.

@customKeywordType(...)

Used in workflow builders to specify how a custom keyword behaves. It is placed before the field of the builder record that implements the keyword.

def async = (
  @customKeywordType(#bind)
  await = { m, continuation -> ... }
)

See Workflows.

@baseUnit

Marks a unit declaration as a base unit of its dimension. Base units name the dimension and are never defined in terms of other units.

@baseUnit unit(s) Seconds: Time

See Units and dimensions, which is currently a design proposal.

Notes

  • Attributes are compile-time metadata.
  • Their meaning is defined by the compiler and language features that consume them.
  • Prefer using documented attributes and patterns from the language guides.