var input = "ABCDEFGABF".items
for c in input:
echo c
Error: undeclared field: 'items' for type system.string
whereas this passes?
var input = "ABCDEFGABF"
for c in input.items:
echo c
Default Nim iterators are always inlined, so they're not first-class. What you want are closure iterators, they are first-class and can be passed around. For example:
iterator myitems(x: string): char {.closure.} =
for elem in x:
yield x
var input = "ABCDEFGABF".myitems
for c in input:
echo c
If you want to easily convert to a closure my package slicerator contains a asClosure macro which would turn the above into:
var input = asClosure "ABCDEFGABF".items
for c in input:
echo c