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
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:
There is also
[json.to](https://github.com/nim-lang/Nim/blob/devel/lib/pure/json.nim#L1201)
as an example.
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 ?
> 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
> 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
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
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)
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
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
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)
11 matches
Mail list logo