mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-30 01:44:37 +00:00
23 lines
293 B
Nim
23 lines
293 B
Nim
discard """
|
|
output: '''first call of p
|
|
some call of p
|
|
new instantiation
|
|
some call of p'''
|
|
"""
|
|
|
|
template once(body) =
|
|
var x {.global.} = false
|
|
if not x:
|
|
x = true
|
|
body
|
|
|
|
proc p() =
|
|
once:
|
|
echo "first call of p"
|
|
echo "some call of p"
|
|
|
|
p()
|
|
once:
|
|
echo "new instantiation"
|
|
p()
|