summary refs log tree commit diff stats
path: root/tests/showoff/tonce.nim
blob: ed2684dcf5b749daeebe62635a255d0fe756d413 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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()