Something went wrong. Try again.
A general purpose .. programming language written in zig ijadux2.tngl.sh/Rinnescript
zig language
Something went wrong. Try again.
2.1 kB · 52 lines
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152@import = .{ std };// Records: `.{ .k = v }` builds an unordered map; fields read by name.const config = .{ .name = "rinne", .depth = 3, .flags = .{ .fast = true } };// `.{ .x }` is shorthand for `.{ .x = x }` — same-named variable binding.const depth = 3;const alt = .{ .depth, .extra = 99 };// Named types — struct: typed fields; a field with a default is optional,// one without is required. Both are plain runtime maps underneath.pub struct Point { x: int = 0, y: int = 0,}struct Label { title: str = "", visible: bool = true,}// Named types — enum: variants auto-number from 0; explicit tags resume.pub enum Level { low, medium = 5, high }fn main(args: []str) int { std.print("config: name={} depth={} fast={}, alt.depth={} extra={}\n", .{ config.name, config.depth, config.flags.fast, alt.depth, alt.extra }); // A var root allows field writes (const roots reject them at compile time). var state = .{ .hits = 0 }; state.hits = state.hits + 1; state.hits = 7; std.print("state.hits={} missing={}\n", .{ state.hits, state.nope }); // Field access composes with any expression producing a map. std.print("name={} len={}, now={}ms\n", .{ config.name, std.strings.len(config.name), std.time.monotonic_ms() }); // Struct declarations compile to `{ _fields: [{name, type, required}...] }`. std.print("Point._fields: {}:{} required={}, {}:{} required={}\n", .{ Point._fields[0].name, Point._fields[0].type, Point._fields[0].required, Point._fields[1].name, Point._fields[1].type, Point._fields[1].required }); // Non-pub structs work identically. std.print("Label._fields: {}:{} required={}, {}:{} required={}\n", .{ Label._fields[0].name, Label._fields[0].type, Label._fields[0].required, Label._fields[1].name, Label._fields[1].type, Label._fields[1].required }); // Enum declarations compile to variant -> tag-value maps. std.print("Level: {} {} {}\n", .{ Level.low, Level.medium, Level.high }); return 0;}