tgenericlambda.nim 370 B

123456789101112131415161718192021222324
  1. discard """
  2. output: "10\n10\n1\n2\n3\n15"
  3. """
  4. proc test(x: proc (a, b: int): int) =
  5. echo x(5, 5)
  6. test(proc (a, b: auto): auto = a + b)
  7. test do (a, b: auto) -> auto: a + b
  8. proc foreach[T](s: seq[T], body: proc(x: T)) =
  9. for e in s:
  10. body(e)
  11. foreach(@[1,2,3]) do (x: auto):
  12. echo x
  13. proc foo =
  14. let x = proc (a, b: int): auto = a + b
  15. echo x(5, 10)
  16. foo()