Skip to content

Instantly share code, notes, and snippets.

@GULPF
Created July 17, 2018 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GULPF/72fb92717d83f194c3c8c835d72051a3 to your computer and use it in GitHub Desktop.
Save GULPF/72fb92717d83f194c3c8c835d72051a3 to your computer and use it in GitHub Desktop.
import typetraits
iterator foo(i: int): int {.closure.} =
yield i + 1
yield i + 2
let f = foo
echo f(1) # 2
echo f(2) # 4
when false:
echo foo() # Error: attempting to call undeclared routine: 'foo'
echo type(f) # iterator (i: int): int{.closure, noSideEffect, gcsafe, locks: 0.}
echo type(foo) # iterator (i: int): int{.closure, noSideEffect, gcsafe, locks: 0.}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment