closure factory proc #93
-
I have this nim code in factory.nim 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)
Without the
Is this supposed to work or a known limitation? Edit: code highlighting |
Beta Was this translation helpful? Give feedback.
Answered by
GillesRamstein
Feb 27, 2024
Replies: 1 comment
-
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. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
GillesRamstein
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adding parenthesis around the return type did the trick.