patty icon indicating copy to clipboard operation
patty copied to clipboard

A more uniform variant syntax

Open alehander92 opened this issue 7 years ago • 8 comments

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

alehander92 avatar Mar 27 '18 11:03 alehander92

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!

andreaferretti avatar Mar 27 '18 12:03 andreaferretti

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^

akavel avatar Apr 03 '20 18:04 akavel

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.

andreaferretti avatar Apr 06 '20 12:04 andreaferretti

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 :/

akavel avatar Apr 06 '20 19:04 akavel

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.

glyh avatar Jun 06 '23 07:06 glyh

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?

andreaferretti avatar Jun 07 '23 06:06 andreaferretti

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.

glyh avatar Jun 07 '23 07:06 glyh

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

andreaferretti avatar Jun 07 '23 16:06 andreaferretti