teffectsmisc.nim 670 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. discard """
  2. output: '''
  3. printing from adder
  4. '''
  5. """
  6. import std/sugar
  7. block:
  8. proc makeAdder(a: int): (int) -> void =
  9. proc discard_adder(x: int) {.closure.} =
  10. discard a + x
  11. proc echo_adder(x: int) {.closure.} =
  12. echo("printing from adder")
  13. if a > 0:
  14. discard_adder
  15. else:
  16. echo_adder
  17. let newAdder = makeAdder(0)
  18. newAdder(5)
  19. block:
  20. proc makeAdder(a: int): (int) -> void =
  21. proc discard_adder(x: int) {.closure.} =
  22. discard a + x
  23. proc echo_adder(x: int) {.closure.} =
  24. echo("printing from adder")
  25. if a > 0:
  26. echo_adder
  27. else:
  28. discard_adder
  29. let newAdder = makeAdder(0)
  30. newAdder(5)