Skip to content

Instantly share code, notes, and snippets.

@TheFox
Last active March 27, 2025 16:19
Show Gist options
  • Save TheFox/84771747203b9d2854cef525a9a27ffb to your computer and use it in GitHub Desktop.
Save TheFox/84771747203b9d2854cef525a9a27ffb to your computer and use it in GitHub Desktop.
Zig Error
// Using Zig 0.14.0
pub const Node = struct {
allocator: Allocator,
children: ArrayList(Node),
parent: ?*Node,
max_level: usize,
...
pub fn init(allocator: Allocator, value: u8, level: usize) Node {
const children = ArrayList(Node).init(allocator);
return Node{
.allocator = allocator,
.children = children,
.parent = null,
.max_level = 0,
...
};
}
pub fn reportLevel(self: *Node, max_level: usize) void {
print("reportLevel: {d} -> {d}\n", .{ self.level, max_level });
self.max_level = max_level;
if (self.parent) |parent| {
print("Parent exists at: {*}---\n", .{parent});
parent.reportLevel(max_level);
print("Parent exists OK\n", .{});
} else {
print("No parent, stopping recursion.\n", .{});
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment