tsemistatic.nim 372 B

1234567891011121314151617181920212223242526272829303132
  1. discard """
  2. msg: "static 10\ndynamic\nstatic 20\n"
  3. output: "s\nd\nd\ns"
  4. """
  5. type
  6. semistatic[T] =
  7. static[T] or T
  8. template isStatic*(x): bool =
  9. compiles(static(x))
  10. proc foo(x: semistatic[int]) =
  11. when isStatic(x):
  12. static: echo "static ", x
  13. echo "s"
  14. else:
  15. static: echo "dynamic"
  16. echo "d"
  17. foo 10
  18. var
  19. x = 10
  20. y: int
  21. foo x
  22. foo y
  23. foo 20