values.zig (1255B) - Raw
1 // Top-level declarations are order-independent: 2 const print = std.debug.print; 3 const std = @import("std"); 4 const os = std.os; 5 const assert = std.debug.assert; 6 7 pub fn main() void { 8 // integers 9 const one_plus_one: i32 = 1 + 1; 10 print("1 + 1 = {}\n", .{one_plus_one}); 11 12 // floats 13 const seven_div_three: f32 = 7.0 / 3.0; 14 print("7.0 / 3.0 = {}\n", .{seven_div_three}); 15 16 // boolean 17 print("{}\n{}\n{}\n", .{ 18 true and false, 19 true or false, 20 !true, 21 }); 22 23 // optional 24 var optional_value: ?[]const u8 = null; 25 assert(optional_value == null); 26 27 print("\noptional 1\ntype: {}\nvalue: {?s}\n", .{ 28 @TypeOf(optional_value), optional_value, 29 }); 30 31 optional_value = "hi"; 32 assert(optional_value != null); 33 34 print("\noptional 2\ntype: {}\nvalue: {?s}\n", .{ 35 @TypeOf(optional_value), optional_value, 36 }); 37 38 // error union 39 var number_or_error: anyerror!i32 = error.ArgNotFound; 40 41 print("\nerror union 1\ntype: {}\nvalue: {!}\n", .{ 42 @TypeOf(number_or_error), 43 number_or_error, 44 }); 45 46 number_or_error = 1234; 47 48 print("\nerror union 2\ntype: {}\nvalue: {!}\n", .{ 49 @TypeOf(number_or_error), number_or_error, 50 }); 51 } 52 53 // exe=succeed