Bind statement

The bind statement is the counterpart to the mixin statement. It can be used to explicitly declare identifiers that should be bound early (i.e. the identifiers should be looked up in the scope of the template/generic definition):

  1. # Module A
  2. var
  3. lastId = 0
  4. template genId*: untyped =
  5. bind lastId
  6. inc(lastId)
  7. lastId
  1. # Module B
  2. import A
  3. echo genId()

But a bind is rarely useful because symbol binding from the definition scope is the default.

bind statements only make sense in templates and generics.