tonce.nim 293 B

1234567891011121314151617181920212223
  1. discard """
  2. output: '''first call of p
  3. some call of p
  4. new instantiation
  5. some call of p'''
  6. """
  7. template once(body) =
  8. var x {.global.} = false
  9. if not x:
  10. x = true
  11. body
  12. proc p() =
  13. once:
  14. echo "first call of p"
  15. echo "some call of p"
  16. p()
  17. once:
  18. echo "new instantiation"
  19. p()