API Reference › Annotations › @Namespace
annotation

@Namespace

"@Namespace(Name) function name_method(…) -> T { … }"

@Namespace(Name) registers Name as a namespace a package provides, so a caller can write Name.method(…) and the compiler dispatches it to the bare function name_method(…) (the namespace lowercased, an underscore, then the method). It is the package-declarable form of the built-in Foo.* stdlib namespaces (Regex.*, Grid.*, …): a third-party package ships the same call shape without editing the compiler. The alias goes through the same generic call path the core namespaces use and preserves the target function's return type; it only applies after every built-in namespace, so it never shadows a core one. Mark each function that backs a method (the registration is idempotent — one mark is enough to open the namespace, but marking each provider documents the surface).

Example

program NamespaceDemo {
  @Namespace(Coach) function coach_bonus() -> int { return 99 }
  @Namespace(Coach) function coach_double(n: int) -> int { return n + n }

  entry {
    print(Coach.bonus())        # 99  — dispatches to coach_bonus
    print(Coach.double(21))     # 42  — dispatches to coach_double
  }
}
← All symbols