A more uniform variant syntax
Hey, have you considered a syntax where variant acts similarly to object, concept etc?
e.g.
type
..
A* = variant
B(b: int)
..
It can return a ref object / object node and it will replace variantp
It will make it easier to use with other types too: what happens now if one has a field T which has itself a field ourVariant? You can't define them in the same section
The syntax I am using is the simplest one I was able to make work with macros. :-) For instance the reason I introduced variantp is that I was not able to make variant A* work.
If you manage to make a better syntax work, please make a PR!
The newly released Nim version 1.2 seems to introduce support for macro pragmas in type sections; I don't have a clear idea yet how exactly this could be used for patty, but I wonder if it could make something possible here? ^v^
Thank you, this is interesting. Right now, I am having issues with nimble after the upgrade to 1.2, but as soon as I get it to work again, I will have a look.
Good luck! Seemed to work relatively painlessly for me on Windows, but we all know too well that computery stuff likes to break in weird ways :/
Hello I run into this problem when I need to define recursive type with variant associated. Because the type is recursive I have to force them to be in the same type block. Is there any workaround?
Thank you.
Hi @glyh , I am not sure what is the issue exactly, and how it is related to the present issue.
Can you share an example of what you would like to achieve and what you have tried so far?
We can't simply do recursive ADT if we can't declare a type first before using it. But someone on the discord point out I can use templates, it does work but it make my code uglier.
If I understand your problem correctly, it is completely unrelated to this issue. I invite you to open a new one and give an example of what you are trying to do, what you tried, and how it failed