Symbol binding in templates

A template is a hygienic macro and so opens a new scope. Most symbols are bound from the definition scope of the template:

  1. # Module A
  2. var
  3. lastId = 0
  4. template genId*: untyped =
  5. inc(lastId)
  6. lastId
  1. # Module B
  2. import A
  3. echo genId() # Works as 'lastId' has been bound in 'genId's defining scope

As in generics symbol binding can be influenced via mixin or bind statements.