tclosure3.nim 450 B

12345678910111213141516171819202122
  1. discard """
  2. file: "tclosure3.nim"
  3. output: "success"
  4. """
  5. proc main =
  6. const n = 30
  7. for iterations in 0..50_000:
  8. var s: seq[proc(): string {.closure.}] = @[]
  9. for i in 0 .. n-1:
  10. (proc () =
  11. let ii = i
  12. s.add(proc(): string = return $(ii*ii)))()
  13. for i in 0 .. n-1:
  14. let val = s[i]()
  15. if val != $(i*i): echo "bug ", val
  16. if getOccupiedMem() > 3000_000: quit("still a leak!")
  17. echo "success"
  18. main()