tpassthruarith.nim 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. discard """
  2. output: '''
  3. [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
  4. [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  5. [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  6. [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  7. [1, 2, 3, 4]
  8. '''
  9. """
  10. # https://github.com/nim-lang/Nim/issues/4880
  11. proc `^^`(x: int): int = x * 2
  12. type
  13. Foo[x: static[int]] = array[x, int]
  14. Bar[a, b: static[int]] = array[b, Foo[^^a]]
  15. var x: Bar[2, 3]
  16. echo repr(x)
  17. # https://github.com/nim-lang/Nim/issues/2730
  18. type
  19. Matrix[M,N: static[int]] = distinct array[0..(M*N - 1), int]
  20. proc bigger[M,N](m: Matrix[M,N]): Matrix[(M * N) div 8, (M * N)] =
  21. discard
  22. proc bigger2[M,N](m: Matrix[M,N]): Matrix[M * 2, N * 2] =
  23. discard
  24. var m : Matrix[4, 4]
  25. var n = bigger(m)
  26. var o = bigger2(m)
  27. echo repr(m)
  28. echo repr(n)
  29. echo repr(o)
  30. type
  31. Vect[N: static[int], A] = array[N, A]
  32. proc push[N: static[int], A](a: Vect[N, A], x: A): Vect[N + 1, A] =
  33. for n in 0 ..< N:
  34. result[n] = a[n]
  35. result[N] = x
  36. echo repr(push([1, 2, 3], 4))