Using statement

The using statement provides syntactic convenience in modules where the same parameter names and types are used over and over. Instead of:

  1. proc foo(c: Context; n: Node) = ...
  2. proc bar(c: Context; n: Node, counter: int) = ...
  3. proc baz(c: Context; n: Node) = ...

One can tell the compiler about the convention that a parameter of name c should default to type Context, n should default to Node etc.:

  1. using
  2. c: Context
  3. n: Node
  4. counter: int
  5. proc foo(c, n) = ...
  6. proc bar(c, n, counter) = ...
  7. proc baz(c, n) = ...
  8. proc mixedMode(c, n; x, y: int) =
  9. # 'c' is inferred to be of the type 'Context'
  10. # 'n' is inferred to be of the type 'Node'
  11. # But 'x' and 'y' are of type 'int'.

The using section uses the same indentation based grouping syntax as a var or let section.

Note that using is not applied for template since untyped template parameters default to the type system.untyped.

Mixing parameters that should use the using declaration with parameters that are explicitly typed is possible and requires a semicolon between them.