From 73dc057cbccc20255345031c86fd8b7a28b2e8f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mamy=20Andr=C3=A9-Ratsimbazafy?= Date: Thu, 27 Aug 2020 09:53:24 +0200 Subject: [PATCH] Undefining variable --- undefining_variable.nim | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 undefining_variable.nim diff --git a/undefining_variable.nim b/undefining_variable.nim new file mode 100644 index 0000000..0fffc31 --- /dev/null +++ b/undefining_variable.nim @@ -0,0 +1,15 @@ +# 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