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:
# Module A
var
lastId = 0
template genId*: untyped =
inc(lastId)
lastId
# Module B
import A
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.
当前内容版权归 nim-lang.org 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 nim-lang.org .