@Vindaar \-- your implementation of `enumFields` is exactly what I was looking
for. Thank you very much and it's also a nice example of computing on the
language itself with macros.
If I understand you correctly, here you go:
import macros
type
Foo = enum
foo = "Foo"
bar = "Bar"
more = "More"
macro enumFields(n: typed): untyped =
let impl = getType(n)
expectKind impl[1], nnkEnumTy
result =
There is
[https://nim-lang.org/docs/iterators.html#fieldPairs.i%2CS%2CT](https://nim-lang.org/docs/iterators.html#fieldPairs.i%2CS%2CT)
but I have never used it, and it seems to be not intended for enums.
If I have an enumeration type, how can I retrieve the field names associated
with that enumeration?
e.g. Given this:
type
Foo = enum
foo = "Foo"
bar = "Bar"
Run
I'd like to be able to iterate over the field something like: