Skip to content

Commit

Permalink
Updated: Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
zakarouf committed May 29, 2021
1 parent 6a9f7d3 commit 21bc9dc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ This will load on top of your syntax highlighting for every .c file.
</div>

<div align="center">
<b> Enums </b>
<img src="docs/imgs/enums/enum_preview1_fn.png">
<b> Binary tree & Enums </b>
<img src="docs/imgs/example/enum_binary_tree.png">
</div>

<div align="center">
Expand Down
Binary file added docs/imgs/enums/enum_binary_tree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/imgs/example/enum_binary_tree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions examples/enum/binarytree.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <stdio.h>
#include <z_/z_.h>

z__Enum(
BinaryTree,
(Leaf, int),
(Node, BinaryTree *, int, BinaryTree *)
);

int sum(const BinaryTree *tree) { /* 6 */
match(*tree) { /* /\ */
slot(Leaf, x) /* 2 7 */
return *x; unslot; /* /\ */
slot(Node, lhs, x, rhs) /* 1 4 */
return sum(*lhs) + *x + sum(*rhs); unslot; /* /\ */
} /* 3 5 */
return 0;
}

#define TREE(tree) ((BinaryTree *)(BinaryTree[]){tree})
#define NODE(left, numbe30, right) TREE(Node(left, numbe30, right))
#define LEAF(number) TREE(Leaf(number))

int main(int argc, char ** argv)
{
const BinaryTree *tree =
NODE(NODE(LEAF(1), 2, NODE(LEAF(3), 4, LEAF(5))), 6, LEAF(7));

printf("%d\n", sum(tree)); // 28
}

0 comments on commit 21bc9dc

Please sign in to comment.