-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Macro to generate variant objects #5
Comments
Hey, thank you! I'd be sad to see patty deprecated, but I'd be very happy to welcome you as a contributor. My goal was to create the initial several version(s) but if other people have serious interest in co-developing/maintaining it to move the repo to an organization (making it a community effort), but of course that's if you or other people have time/interest in that. I actually thought about the ADT problem these days. Gara actually includes a let a = ~Commit.Normal(name: "A", diff: "b")
let b = ~Commit.Normal("A", "b") I wondered if I can somehow add to the compiler a compile time helper which can do something like let a = ~Normal(name: "A", diff: "b")
let b = ~Normal("A", "b") Of course Now, why? I love patty's variant(ADT) syntax but the problem is that a lot of nim code already defines variants with object definition. I wanted to still have something that makes all those existing variants easier to use. (Another option would be to just have Now, about the definition of new ADT: I wondered if there is a way to add your macro to type sections. (I even opened an issue once in patty before I knew well how macros work :D ) I doubt that Araq will want a new builtin macro variant*(definition: untyped): untyped {.typeSection.} =
# I want to generate a (NimNode, NimNode): one for the type section and one for the code section
.. and be used like type
A* = variant #usually with : but Araq said we might be able to have macro invocations without colon
commonField: Type
Circle(..)
Square(..) Of course even if we can't have a typeSection macro, we should definitely include the current variant macro then. |
No need to be sad for patty, your solution is 1000 times more complete! :-) In the last year I was not able to work much on Nim projects, save for keeping them up to date with latest Nim. If/when I find time, I would be happy to contribute, though! I don't like especially the syntax to declare algebraic data types in patty ( |
Well, I mostly followed your patty todo list, honestly I guess that could be probably added to patty, but it just seemed easier for me to start from scratch.(not a good thing in general :D). What do you find is ilimited with Yeah, I'll think about it, I actually think stuff like this might be easier to directly be added to the stdlib than the pattern matching |
About |
Also, a limitation of the import gara
type
ShapeKind = enum Rectangle, Circle
Shape = object
case kind: ShapeKind
of Rectangle:
w, h: float
of Circle:
cx, cy, r: float
echo(~Shape.Rectangle(w: 1, h: 2).w) |
Yeah, in this case something like Shape.Rectangle(w: 1, h: 2).init.w Still, I think that's a non-issue actually, because how often would you create a variant to immediately access a field / method on it and throw it away in the process? |
for now a RFC in https://github.com/nim-lang/Nim/issues/9139 |
@andreaferretti after some discussions with Araq, I have a plan for supporting shared names with your macro: I'll try to port it to gara these days. (but maybe also submit a PR to patty) |
ok, i have to remember what i meant, i remember something about generating if-s for subcases and that one can generate |
The newly released Nim version 1.2 seems to introduce support for macro pragmas in |
First, kudos for your new library!
As you probably know, patty consists of two macros: one to generate algebraic data types and the other one to do the actual pattern matching. Since you have generalized a lot the pattern matching capabilities of patty, I would like to deprecate it in favour of gara. Is there any chance that the other functionality may be included here in some form? Otherwise it would remain orphan.
The text was updated successfully, but these errors were encountered: