Zig
Zig
Using Zig 0.11 in 2023
Zig has a package manager
As of this writing, October 6 2023, the package manager is currently being worked on for the next release: 0.12.
Here are some relevant Github links detailing that work:
- https://github.com/ziglang/zig/pull/17392
- https://github.com/ziglang/zig/issues/14298
- https://github.com/ziglang/zig/pull/17277
- https://github.com/ziglang/zig/pull/14603
“To use a package that’s been prepared for the new Zig package manager, you just need to list it in the dependencies section.”
Zon. It uses files such as build.zig.zon
which contains a zig anonymous struct. Example:
1// because zon file is really just a zig struct2// comments are really done in the same way using 2 forward slashes3.{4 // the name of your project5 .name = "my-wtf-project",6 // the version of your project7 .version = "0.0.1",8
9 // the actual packages you need as dependencies of your project10 .dependencies = .{11 // the name of the package12 .zap = .{13 // the url to the release of the module14 .url = "https://github.com/zigzap/zap/archive/refs/tags/v0.1.7-pre.tar.gz",15 // the hash of the module, this is not the checksum of the tarball16 .hash = "1220002d24d73672fe8b1e39717c0671598acc8ec27b8af2e1caf623a4fd0ce0d1bd",17 },18 }19}
- run
zig init-exe
- edit files
zig build
- See dir
zig-out/bin
Zig concurrency
TODO
Zig Memory alocation
TODO
For loops
For loops recently changed in Zig
1const std = @import("std");2
3pub fn main() void {4 const name = "Josey";5 for (name, 0..) |char, i| {6 _ = char;7 std.debug.print("{c}\n", .{name[i]});8 }9
10 var elems = [_][]const u8{ "water", "earth", "fire", "air" };11 var nats = [_][]const u8{ "tribes", "kingdom", "nation", "nomads" };12
13 for (elems, nats) |e, n| {14 std.debug.print("{s} {s}\n", .{ e, n });15 }16}