mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
40 lines
670 B
Nim
40 lines
670 B
Nim
discard """
|
|
output: '''
|
|
printing from adder
|
|
'''
|
|
"""
|
|
|
|
import std/sugar
|
|
|
|
block:
|
|
proc makeAdder(a: int): (int) -> void =
|
|
proc discard_adder(x: int) {.closure.} =
|
|
discard a + x
|
|
|
|
proc echo_adder(x: int) {.closure.} =
|
|
echo("printing from adder")
|
|
|
|
if a > 0:
|
|
discard_adder
|
|
else:
|
|
echo_adder
|
|
|
|
let newAdder = makeAdder(0)
|
|
newAdder(5)
|
|
|
|
block:
|
|
proc makeAdder(a: int): (int) -> void =
|
|
proc discard_adder(x: int) {.closure.} =
|
|
discard a + x
|
|
|
|
proc echo_adder(x: int) {.closure.} =
|
|
echo("printing from adder")
|
|
|
|
if a > 0:
|
|
echo_adder
|
|
else:
|
|
discard_adder
|
|
|
|
let newAdder = makeAdder(0)
|
|
newAdder(5)
|