mirror of
https://github.com/ziglang/zig.git
synced 2024-11-26 23:22:44 +00:00
e3424332d3
* `doc/langref` formatting * upgrade `.{ .path = "..." }` to `b.path("...")` * avoid using arguments named `self` * make `Build.Step.Id` usage more consistent * add `Build.pathResolve` * use `pathJoin` and `pathResolve` everywhere * make sure `Build.LazyPath.getPath2` returns an absolute path
54 lines
1.2 KiB
Zig
54 lines
1.2 KiB
Zig
// Top-level declarations are order-independent:
|
|
const print = std.debug.print;
|
|
const std = @import("std");
|
|
const os = std.os;
|
|
const assert = std.debug.assert;
|
|
|
|
pub fn main() void {
|
|
// integers
|
|
const one_plus_one: i32 = 1 + 1;
|
|
print("1 + 1 = {}\n", .{one_plus_one});
|
|
|
|
// floats
|
|
const seven_div_three: f32 = 7.0 / 3.0;
|
|
print("7.0 / 3.0 = {}\n", .{seven_div_three});
|
|
|
|
// boolean
|
|
print("{}\n{}\n{}\n", .{
|
|
true and false,
|
|
true or false,
|
|
!true,
|
|
});
|
|
|
|
// optional
|
|
var optional_value: ?[]const u8 = null;
|
|
assert(optional_value == null);
|
|
|
|
print("\noptional 1\ntype: {}\nvalue: {?s}\n", .{
|
|
@TypeOf(optional_value), optional_value,
|
|
});
|
|
|
|
optional_value = "hi";
|
|
assert(optional_value != null);
|
|
|
|
print("\noptional 2\ntype: {}\nvalue: {?s}\n", .{
|
|
@TypeOf(optional_value), optional_value,
|
|
});
|
|
|
|
// error union
|
|
var number_or_error: anyerror!i32 = error.ArgNotFound;
|
|
|
|
print("\nerror union 1\ntype: {}\nvalue: {!}\n", .{
|
|
@TypeOf(number_or_error),
|
|
number_or_error,
|
|
});
|
|
|
|
number_or_error = 1234;
|
|
|
|
print("\nerror union 2\ntype: {}\nvalue: {!}\n", .{
|
|
@TypeOf(number_or_error), number_or_error,
|
|
});
|
|
}
|
|
|
|
// exe=succeed
|