Initializing objects from proc parameters

2021-03-17 Thread ElegantBeef
Yea the `construct` macro handles that, though it still requires writting the fields twice.

Initializing objects from proc parameters

2021-03-17 Thread Stefan_Salewski
> As the author of constructor Yes, Yardanico already told us. But from my current understanding your macro currently can initialize objects only with default constants. Which I need rarely as my defaults are generally binary zero. What I sometimes need is initialization with runtime values as

Initializing objects from proc parameters

2021-03-17 Thread treeform
Wow I really like your defaults. Should be part of nim!

Initializing objects from proc parameters

2021-03-17 Thread ElegantBeef
As the author of constructor I really have to agree with the "Oh god it's so tedious to right it so many times" so I solved it. Recently just made my new `defaults` macro which makes it so you only have to type the definition once! Feast your eyes on macro magic! import constructo

Initializing objects from proc parameters

2021-03-17 Thread Araq
If only we had a macro system so that you could have any amount of syntax sugar you need...

Initializing objects from proc parameters

2021-03-17 Thread alexeypetrushin
Yea, I'm also annoyed with the need to type code twice. Actually it's the types typed twice, the keys typed **4 times** , 1) in object definition 2) in `init` args 3 and 4) in object initialisation as `key: key` type HedgedStock* = object id*: string evol*:

Initializing objects from proc parameters

2021-03-17 Thread Yardanico
You should check out , it does something similar to this

Initializing objects from proc parameters

2021-03-17 Thread DavidKunz
That's very similar to what was proposed by @alexeypetrushin here:

Initializing objects from proc parameters

2021-03-17 Thread Stefan_Salewski
I am converting some Ruby code to Nim and got proc initialize(s: Step; prev, nxt, id: int) = s.prev = prev s.next = next s.id = id s.radius = 0 # default for incident net s.outer = false Run The first 3 assignments in the proc are a pattern