Re: Iterate over fields

2020-04-20 Thread Clonk
I think i understand most of it. Now, I just need to practice macros more so I can come up with the solution my self next time :). Thanks again

Re: Iterate over fields

2020-04-17 Thread Vindaar
First of all see of course the docs here: [https://nim-lang.github.io/Nim/macros.html#quote%2Ctyped%2Cstring](https://nim-lang.github.io/Nim/macros.html#quote%2Ctyped%2Cstring) and the macro tutorial, specifically:

Re: Iterate over fields

2020-04-17 Thread b3liever
There is also [json.to](https://github.com/nim-lang/Nim/blob/devel/lib/pure/json.nim#L1201) as an example.

Re: Iterate over fields

2020-04-17 Thread Clonk
I didn't about the quote do tricks, that's useful ! Why do you have to use backtick "`" inside quote do ? Is it to interpret macro inside a block of code ?

Re: Iterate over fields

2020-04-16 Thread Vindaar
> I'll look into your solution since I may need to adapt a few things (I've > simplified the real uses cases to summarize it into a single problems). The > goal is also to learn Nim's macro as well. I've now spent probably as much > time on macros than it would have took to write the solution

Re: Iterate over fields

2020-04-16 Thread Clonk
> If all of your procs are going to look like newFooBar above there, it's > possible to generate with a macro. Yes, it's exactly what I'm looking for. A way to generate several procedure that follow a pattern. I've been trying my hand at writing macros that generate proc but there is a lot to

Re: Iterate over fields

2020-04-16 Thread Vindaar
If all of your procs are going to look like newFooBar above there, it's possible to generate with a macro. import macros, tables type Tensor[T] = object discard Model = object field1: string field2: string field3: int

Re: Iterate over fields

2020-04-15 Thread treeform
Field fieldPairs are great! I use it to print arbitrary structures and deserialize json in a more looser way: [https://github.com/treeform/print/blob/master/src/print.nim#L79](https://github.com/treeform/print/blob/master/src/print.nim#L79)

Re: Iterate over fields

2020-04-15 Thread Stefan_Salewski
I have never used that iterators myself. But I would strongly assume that we can only iterate over one object at a time. As we can only iterate over one string or over one sequence at a time. But of course we can collect the results of each iteration is some way, and finally output all

Re: Iterate over fields

2020-04-15 Thread Clonk
I thought fields could only iterate over element of the same type. If not, how do you use fields to iterate over fields of 2 different type ? type FooObj = object field1: Tensor[float] field2: Table[string, float] field3: int Model = object

Re: Iterate over fields

2020-04-14 Thread Stefan_Salewski
There are iterators fields and fieldPairs: [https://nim-lang.org/docs/iterators.html#fieldPairs.i%2CT](https://nim-lang.org/docs/iterators.html#fieldPairs.i%2CT)