Undefining variable

This commit is contained in:
Mamy André-Ratsimbazafy 2020-08-27 09:53:24 +02:00
parent 02ab74ac8b
commit 73dc057cbc
No known key found for this signature in database
GPG Key ID: 7B88AD1FE79492E1
1 changed files with 15 additions and 0 deletions

15
undefining_variable.nim Normal file
View File

@ -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