nim-cookbook/undefining_variable.nim

16 lines
347 B
Nim
Raw Permalink Normal View History

2020-08-27 07:53:24 +00:00
# Context
#
# Discussion with PMunch on IRC to disallow the use of some variable
# in a code block
template undef(symbol: untyped{nkIdent}, body: untyped{nkStmtList}): untyped =
block:
template `symbol`(): untyped = {.error: "Cannot use `" & astToStr(`symbol`) & "` in this undef context".}
body
var x = 100
echo x
undef(x):
echo x