Skip to content

closure factory proc #93

Closed Answered by GillesRamstein
GillesRamstein asked this question in Q&A
Discussion options

You must be logged in to vote
proc factory*(): (proc(x: int)) {.exportpy.} =
  var state: int = 1
  proc inner(x: int) =
    state = state + x
    echo state
  return inner


when isMainModule:
  let innerProc = factory()
  innerProc(2)
  innerProc(3)

Adding parenthesis around the return type did the trick.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by GillesRamstein
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant