Typed vs untyped parameters
An untyped parameter means that symbol lookups and type resolution is not performed before the expression is passed to the template. This means that for example undeclared identifiers can be passed to the template:
template declareInt(x: untyped) =
var x: int
declareInt(x) # valid
x = 3
template declareInt(x: typed) =
var x: int
declareInt(x) # invalid, because x has not been declared and so has no type
A template where every parameter is untyped is called an immediate template. For historical reasons templates can be explicitly annotated with an immediate pragma and then these templates do not take part in overloading resolution and the parameters’ types are ignored by the compiler. Explicit immediate templates are now deprecated.
Note: For historical reasons stmt was an alias for typed and expr was an alias for untyped, but they are removed.
当前内容版权归 nim-lang.org 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 nim-lang.org .