Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/42loco42/nim-adtmacro
A macro for easy ADT declaration
https://github.com/42loco42/nim-adtmacro
nim nim-lang
Last synced: 26 days ago
JSON representation
A macro for easy ADT declaration
- Host: GitHub
- URL: https://github.com/42loco42/nim-adtmacro
- Owner: 42LoCo42
- License: gpl-3.0
- Created: 2022-01-23T12:21:33.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-01-23T12:26:27.000Z (about 3 years ago)
- Last Synced: 2024-11-13T17:46:57.100Z (3 months ago)
- Topics: nim, nim-lang
- Language: Nim
- Homepage:
- Size: 14.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
```nim
# A call like this...
adt Foo:
Var1:
foo: int
bar: string
Var2:
baz: float
quux: char
# ...will generate the following types:
type
Foo = ref FooObj
FooKind = enum
Var1,
Var2
FooObj = object
case kind: FooKind
of Var1:
foo: int
bar: string
of Var2:
baz: float
quux: char
# and you can do this:
let abc = Foo(kind: Var1, foo: 42, bar: "ADTs are cool")
let def = Foo(kind: Var2, baz: 13.37, quux: '*')
echo abc.repr, ", ", def.repr
```