Re: Retrieving field names of an enumeration or other types?

2019-11-09 Thread pmags
@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.

Re: Retrieving field names of an enumeration or other types?

2019-11-09 Thread Vindaar
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 =

Re: Retrieving field names of an enumeration or other types?

2019-11-08 Thread Stefan_Salewski
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.

Retrieving field names of an enumeration or other types?

2019-11-08 Thread pmags
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: