| ... | @@ -205,7 +205,7 @@ const std = @import("std"); | ... | @@ -205,7 +205,7 @@ const std = @import("std"); |
| 205 | | 205 | |
| 206 | pub fn main() !void { | 206 | pub fn main() !void { |
| 207 | const stdout = &std.io.getStdOut().outStream().stream; | 207 | const stdout = &std.io.getStdOut().outStream().stream; |
| 208 | try stdout.print("Hello, {}!\n", "world"); | 208 | try stdout.print("Hello, {}!\n", .{"world"}); |
| 209 | } | 209 | } |
| 210 | {#code_end#} | 210 | {#code_end#} |
| 211 | <p> | 211 | <p> |
| ... | @@ -217,7 +217,7 @@ pub fn main() !void { | ... | @@ -217,7 +217,7 @@ pub fn main() !void { |
| 217 | const warn = @import("std").debug.warn; | 217 | const warn = @import("std").debug.warn; |
| 218 | | 218 | |
| 219 | pub fn main() void { | 219 | pub fn main() void { |
| 220 | warn("Hello, world!\n"); | 220 | warn("Hello, world!\n", .{}); |
| 221 | } | 221 | } |
| 222 | {#code_end#} | 222 | {#code_end#} |
| 223 | <p> | 223 | <p> |
| ... | @@ -289,41 +289,50 @@ const assert = std.debug.assert; | ... | @@ -289,41 +289,50 @@ const assert = std.debug.assert; |
| 289 | pub fn main() void { | 289 | pub fn main() void { |
| 290 | // integers | 290 | // integers |
| 291 | const one_plus_one: i32 = 1 + 1; | 291 | const one_plus_one: i32 = 1 + 1; |
| 292 | warn("1 + 1 = {}\n", one_plus_one); | 292 | warn("1 + 1 = {}\n", .{one_plus_one}); |
| 293 | | 293 | |
| 294 | // floats | 294 | // floats |
| 295 | const seven_div_three: f32 = 7.0 / 3.0; | 295 | const seven_div_three: f32 = 7.0 / 3.0; |
| 296 | warn("7.0 / 3.0 = {}\n", seven_div_three); | 296 | warn("7.0 / 3.0 = {}\n", .{seven_div_three}); |
| 297 | | 297 | |
| 298 | // boolean | 298 | // boolean |
| 299 | warn("{}\n{}\n{}\n", | 299 | warn("{}\n{}\n{}\n", .{ |
| 300 | true and false, | 300 | true and false, |
| 301 | true or false, | 301 | true or false, |
| 302 | !true); | 302 | !true, |
| | 303 | }); |
| 303 | | 304 | |
| 304 | // optional | 305 | // optional |
| 305 | var optional_value: ?[]const u8 = null; | 306 | var optional_value: ?[]const u8 = null; |
| 306 | assert(optional_value == null); | 307 | assert(optional_value == null); |
| 307 | | 308 | |
| 308 | warn("\noptional 1\ntype: {}\nvalue: {}\n", | 309 | warn("\noptional 1\ntype: {}\nvalue: {}\n", .{ |
| 309 | @typeName(@typeOf(optional_value)), optional_value); | 310 | @typeName(@typeOf(optional_value)), |
| | 311 | optional_value, |
| | 312 | }); |
| 310 | | 313 | |
| 311 | optional_value = "hi"; | 314 | optional_value = "hi"; |
| 312 | assert(optional_value != null); | 315 | assert(optional_value != null); |
| 313 | | 316 | |
| 314 | warn("\noptional 2\ntype: {}\nvalue: {}\n", | 317 | warn("\noptional 2\ntype: {}\nvalue: {}\n", .{ |
| 315 | @typeName(@typeOf(optional_value)), optional_value); | 318 | @typeName(@typeOf(optional_value)), |
| | 319 | optional_value, |
| | 320 | }); |
| 316 | | 321 | |
| 317 | // error union | 322 | // error union |
| 318 | var number_or_error: anyerror!i32 = error.ArgNotFound; | 323 | var number_or_error: anyerror!i32 = error.ArgNotFound; |
| 319 | | 324 | |
| 320 | warn("\nerror union 1\ntype: {}\nvalue: {}\n", | 325 | warn("\nerror union 1\ntype: {}\nvalue: {}\n", .{ |
| 321 | @typeName(@typeOf(number_or_error)), number_or_error); | 326 | @typeName(@typeOf(number_or_error)), |
| | 327 | number_or_error, |
| | 328 | }); |
| 322 | | 329 | |
| 323 | number_or_error = 1234; | 330 | number_or_error = 1234; |
| 324 | | 331 | |
| 325 | warn("\nerror union 2\ntype: {}\nvalue: {}\n", | 332 | warn("\nerror union 2\ntype: {}\nvalue: {}\n", .{ |
| 326 | @typeName(@typeOf(number_or_error)), number_or_error); | 333 | @typeName(@typeOf(number_or_error)), |
| | 334 | number_or_error, |
| | 335 | }); |
| 327 | } | 336 | } |
| 328 | {#code_end#} | 337 | {#code_end#} |
| 329 | {#header_open|Primitive Types#} | 338 | {#header_open|Primitive Types#} |
| ... | @@ -954,8 +963,8 @@ extern fn foo_optimized(x: f64) f64; | ... | @@ -954,8 +963,8 @@ extern fn foo_optimized(x: f64) f64; |
| 954 | | 963 | |
| 955 | pub fn main() void { | 964 | pub fn main() void { |
| 956 | const x = 0.001; | 965 | const x = 0.001; |
| 957 | warn("optimized = {}\n", foo_optimized(x)); | 966 | warn("optimized = {}\n", .{foo_optimized(x)}); |
| 958 | warn("strict = {}\n", foo_strict(x)); | 967 | warn("strict = {}\n", .{foo_strict(x)}); |
| 959 | } | 968 | } |
| 960 | {#code_end#} | 969 | {#code_end#} |
| 961 | {#see_also|@setFloatMode|Division by Zero#} | 970 | {#see_also|@setFloatMode|Division by Zero#} |
| ... | @@ -2182,7 +2191,7 @@ test "using slices for strings" { | ... | @@ -2182,7 +2191,7 @@ test "using slices for strings" { |
| 2182 | // You can use slice syntax on an array to convert an array into a slice. | 2191 | // You can use slice syntax on an array to convert an array into a slice. |
| 2183 | const all_together_slice = all_together[0..]; | 2192 | const all_together_slice = all_together[0..]; |
| 2184 | // String concatenation example. | 2193 | // String concatenation example. |
| 2185 | const hello_world = try fmt.bufPrint(all_together_slice, "{} {}", hello, world); | 2194 | const hello_world = try fmt.bufPrint(all_together_slice, "{} {}", .{hello, world}); |
| 2186 | | 2195 | |
| 2187 | // Generally, you can use UTF-8 and not worry about whether something is a | 2196 | // Generally, you can use UTF-8 and not worry about whether something is a |
| 2188 | // string. If you don't need to deal with individual characters, no need | 2197 | // string. If you don't need to deal with individual characters, no need |
| ... | @@ -2623,9 +2632,9 @@ const std = @import("std"); | ... | @@ -2623,9 +2632,9 @@ const std = @import("std"); |
| 2623 | | 2632 | |
| 2624 | pub fn main() void { | 2633 | pub fn main() void { |
| 2625 | const Foo = struct {}; | 2634 | const Foo = struct {}; |
| 2626 | std.debug.warn("variable: {}\n", @typeName(Foo)); | 2635 | std.debug.warn("variable: {}\n", .{@typeName(Foo)}); |
| 2627 | std.debug.warn("anonymous: {}\n", @typeName(struct {})); | 2636 | std.debug.warn("anonymous: {}\n", .{@typeName(struct {})}); |
| 2628 | std.debug.warn("function: {}\n", @typeName(List(i32))); | 2637 | std.debug.warn("function: {}\n", .{@typeName(List(i32))}); |
| 2629 | } | 2638 | } |
| 2630 | | 2639 | |
| 2631 | fn List(comptime T: type) type { | 2640 | fn List(comptime T: type) type { |
| ... | @@ -3806,18 +3815,18 @@ test "defer basics" { | ... | @@ -3806,18 +3815,18 @@ test "defer basics" { |
| 3806 | // If multiple defer statements are specified, they will be executed in | 3815 | // If multiple defer statements are specified, they will be executed in |
| 3807 | // the reverse order they were run. | 3816 | // the reverse order they were run. |
| 3808 | fn deferUnwindExample() void { | 3817 | fn deferUnwindExample() void { |
| 3809 | warn("\n"); | 3818 | warn("\n", .{}); |
| 3810 | | 3819 | |
| 3811 | defer { | 3820 | defer { |
| 3812 | warn("1 "); | 3821 | warn("1 ", .{}); |
| 3813 | } | 3822 | } |
| 3814 | defer { | 3823 | defer { |
| 3815 | warn("2 "); | 3824 | warn("2 ", .{}); |
| 3816 | } | 3825 | } |
| 3817 | if (false) { | 3826 | if (false) { |
| 3818 | // defers are not run if they are never executed. | 3827 | // defers are not run if they are never executed. |
| 3819 | defer { | 3828 | defer { |
| 3820 | warn("3 "); | 3829 | warn("3 ", .{}); |
| 3821 | } | 3830 | } |
| 3822 | } | 3831 | } |
| 3823 | } | 3832 | } |
| ... | @@ -3832,15 +3841,15 @@ test "defer unwinding" { | ... | @@ -3832,15 +3841,15 @@ test "defer unwinding" { |
| 3832 | // This is especially useful in allowing a function to clean up properly | 3841 | // This is especially useful in allowing a function to clean up properly |
| 3833 | // on error, and replaces goto error handling tactics as seen in c. | 3842 | // on error, and replaces goto error handling tactics as seen in c. |
| 3834 | fn deferErrorExample(is_error: bool) !void { | 3843 | fn deferErrorExample(is_error: bool) !void { |
| 3835 | warn("\nstart of function\n"); | 3844 | warn("\nstart of function\n", .{}); |
| 3836 | | 3845 | |
| 3837 | // This will always be executed on exit | 3846 | // This will always be executed on exit |
| 3838 | defer { | 3847 | defer { |
| 3839 | warn("end of function\n"); | 3848 | warn("end of function\n", .{}); |
| 3840 | } | 3849 | } |
| 3841 | | 3850 | |
| 3842 | errdefer { | 3851 | errdefer { |
| 3843 | warn("encountered an error!\n"); | 3852 | warn("encountered an error!\n", .{}); |
| 3844 | } | 3853 | } |
| 3845 | | 3854 | |
| 3846 | if (is_error) { | 3855 | if (is_error) { |
| ... | @@ -5843,7 +5852,7 @@ const a_number: i32 = 1234; | ... | @@ -5843,7 +5852,7 @@ const a_number: i32 = 1234; |
| 5843 | const a_string = "foobar"; | 5852 | const a_string = "foobar"; |
| 5844 | | 5853 | |
| 5845 | pub fn main() void { | 5854 | pub fn main() void { |
| 5846 | warn("here is a string: '{}' here is a number: {}\n", a_string, a_number); | 5855 | warn("here is a string: '{}' here is a number: {}\n", .{a_string, a_number}); |
| 5847 | } | 5856 | } |
| 5848 | {#code_end#} | 5857 | {#code_end#} |
| 5849 | | 5858 | |
| ... | @@ -5960,8 +5969,11 @@ const a_number: i32 = 1234; | ... | @@ -5960,8 +5969,11 @@ const a_number: i32 = 1234; |
| 5960 | const a_string = "foobar"; | 5969 | const a_string = "foobar"; |
| 5961 | | 5970 | |
| 5962 | test "printf too many arguments" { | 5971 | test "printf too many arguments" { |
| 5963 | warn("here is a string: '{}' here is a number: {}\n", | 5972 | warn("here is a string: '{}' here is a number: {}\n", .{ |
| 5964 | a_string, a_number, a_number); | 5973 | a_string, |
| | 5974 | a_number, |
| | 5975 | a_number, |
| | 5976 | }); |
| 5965 | } | 5977 | } |
| 5966 | {#code_end#} | 5978 | {#code_end#} |
| 5967 | <p> | 5979 | <p> |
| ... | @@ -5979,7 +5991,7 @@ const a_string = "foobar"; | ... | @@ -5979,7 +5991,7 @@ const a_string = "foobar"; |
| 5979 | const fmt = "here is a string: '{}' here is a number: {}\n"; | 5991 | const fmt = "here is a string: '{}' here is a number: {}\n"; |
| 5980 | | 5992 | |
| 5981 | pub fn main() void { | 5993 | pub fn main() void { |
| 5982 | warn(fmt, a_string, a_number); | 5994 | warn(fmt, .{a_string, a_number}); |
| 5983 | } | 5995 | } |
| 5984 | {#code_end#} | 5996 | {#code_end#} |
| 5985 | <p> | 5997 | <p> |
| ... | @@ -6417,7 +6429,7 @@ pub fn main() void { | ... | @@ -6417,7 +6429,7 @@ pub fn main() void { |
| 6417 | | 6429 | |
| 6418 | fn amainWrap() void { | 6430 | fn amainWrap() void { |
| 6419 | amain() catch |e| { | 6431 | amain() catch |e| { |
| 6420 | std.debug.warn("{}\n", e); | 6432 | std.debug.warn("{}\n", .{e}); |
| 6421 | if (@errorReturnTrace()) |trace| { | 6433 | if (@errorReturnTrace()) |trace| { |
| 6422 | std.debug.dumpStackTrace(trace.*); | 6434 | std.debug.dumpStackTrace(trace.*); |
| 6423 | } | 6435 | } |
| ... | @@ -6447,8 +6459,8 @@ fn amain() !void { | ... | @@ -6447,8 +6459,8 @@ fn amain() !void { |
| 6447 | const download_text = try await download_frame; | 6459 | const download_text = try await download_frame; |
| 6448 | defer allocator.free(download_text); | 6460 | defer allocator.free(download_text); |
| 6449 | | 6461 | |
| 6450 | std.debug.warn("download_text: {}\n", download_text); | 6462 | std.debug.warn("download_text: {}\n", .{download_text}); |
| 6451 | std.debug.warn("file_text: {}\n", file_text); | 6463 | std.debug.warn("file_text: {}\n", .{file_text}); |
| 6452 | } | 6464 | } |
| 6453 | | 6465 | |
| 6454 | var global_download_frame: anyframe = undefined; | 6466 | var global_download_frame: anyframe = undefined; |
| ... | @@ -6458,7 +6470,7 @@ fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 { | ... | @@ -6458,7 +6470,7 @@ fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 { |
| 6458 | suspend { | 6470 | suspend { |
| 6459 | global_download_frame = @frame(); | 6471 | global_download_frame = @frame(); |
| 6460 | } | 6472 | } |
| 6461 | std.debug.warn("fetchUrl returning\n"); | 6473 | std.debug.warn("fetchUrl returning\n", .{}); |
| 6462 | return result; | 6474 | return result; |
| 6463 | } | 6475 | } |
| 6464 | | 6476 | |
| ... | @@ -6469,7 +6481,7 @@ fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 { | ... | @@ -6469,7 +6481,7 @@ fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 { |
| 6469 | suspend { | 6481 | suspend { |
| 6470 | global_file_frame = @frame(); | 6482 | global_file_frame = @frame(); |
| 6471 | } | 6483 | } |
| 6472 | std.debug.warn("readFile returning\n"); | 6484 | std.debug.warn("readFile returning\n", .{}); |
| 6473 | return result; | 6485 | return result; |
| 6474 | } | 6486 | } |
| 6475 | {#code_end#} | 6487 | {#code_end#} |
| ... | @@ -6487,7 +6499,7 @@ pub fn main() void { | ... | @@ -6487,7 +6499,7 @@ pub fn main() void { |
| 6487 | | 6499 | |
| 6488 | fn amainWrap() void { | 6500 | fn amainWrap() void { |
| 6489 | amain() catch |e| { | 6501 | amain() catch |e| { |
| 6490 | std.debug.warn("{}\n", e); | 6502 | std.debug.warn("{}\n", .{e}); |
| 6491 | if (@errorReturnTrace()) |trace| { | 6503 | if (@errorReturnTrace()) |trace| { |
| 6492 | std.debug.dumpStackTrace(trace.*); | 6504 | std.debug.dumpStackTrace(trace.*); |
| 6493 | } | 6505 | } |
| ... | @@ -6517,21 +6529,21 @@ fn amain() !void { | ... | @@ -6517,21 +6529,21 @@ fn amain() !void { |
| 6517 | const download_text = try await download_frame; | 6529 | const download_text = try await download_frame; |
| 6518 | defer allocator.free(download_text); | 6530 | defer allocator.free(download_text); |
| 6519 | | 6531 | |
| 6520 | std.debug.warn("download_text: {}\n", download_text); | 6532 | std.debug.warn("download_text: {}\n", .{download_text}); |
| 6521 | std.debug.warn("file_text: {}\n", file_text); | 6533 | std.debug.warn("file_text: {}\n", .{file_text}); |
| 6522 | } | 6534 | } |
| 6523 | | 6535 | |
| 6524 | fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 { | 6536 | fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 { |
| 6525 | const result = try std.mem.dupe(allocator, u8, "this is the downloaded url contents"); | 6537 | const result = try std.mem.dupe(allocator, u8, "this is the downloaded url contents"); |
| 6526 | errdefer allocator.free(result); | 6538 | errdefer allocator.free(result); |
| 6527 | std.debug.warn("fetchUrl returning\n"); | 6539 | std.debug.warn("fetchUrl returning\n", .{}); |
| 6528 | return result; | 6540 | return result; |
| 6529 | } | 6541 | } |
| 6530 | | 6542 | |
| 6531 | fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 { | 6543 | fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 { |
| 6532 | const result = try std.mem.dupe(allocator, u8, "this is the file contents"); | 6544 | const result = try std.mem.dupe(allocator, u8, "this is the file contents"); |
| 6533 | errdefer allocator.free(result); | 6545 | errdefer allocator.free(result); |
| 6534 | std.debug.warn("readFile returning\n"); | 6546 | std.debug.warn("readFile returning\n", .{}); |
| 6535 | return result; | 6547 | return result; |
| 6536 | } | 6548 | } |
| 6537 | {#code_end#} | 6549 | {#code_end#} |
| ... | @@ -7103,7 +7115,7 @@ const num1 = blk: { | ... | @@ -7103,7 +7115,7 @@ const num1 = blk: { |
| 7103 | test "main" { | 7115 | test "main" { |
| 7104 | @compileLog("comptime in main"); | 7116 | @compileLog("comptime in main"); |
| 7105 | | 7117 | |
| 7106 | warn("Runtime in main, num1 = {}.\n", num1); | 7118 | warn("Runtime in main, num1 = {}.\n", .{num1}); |
| 7107 | } | 7119 | } |
| 7108 | {#code_end#} | 7120 | {#code_end#} |
| 7109 | <p> | 7121 | <p> |
| ... | @@ -7124,7 +7136,7 @@ const num1 = blk: { | ... | @@ -7124,7 +7136,7 @@ const num1 = blk: { |
| 7124 | }; | 7136 | }; |
| 7125 | | 7137 | |
| 7126 | test "main" { | 7138 | test "main" { |
| 7127 | warn("Runtime in main, num1 = {}.\n", num1); | 7139 | warn("Runtime in main, num1 = {}.\n", .{num1}); |
| 7128 | } | 7140 | } |
| 7129 | {#code_end#} | 7141 | {#code_end#} |
| 7130 | {#header_close#} | 7142 | {#header_close#} |
| ... | @@ -8706,7 +8718,7 @@ const std = @import("std"); | ... | @@ -8706,7 +8718,7 @@ const std = @import("std"); |
| 8706 | pub fn main() void { | 8718 | pub fn main() void { |
| 8707 | var value: i32 = -1; | 8719 | var value: i32 = -1; |
| 8708 | var unsigned = @intCast(u32, value); | 8720 | var unsigned = @intCast(u32, value); |
| 8709 | std.debug.warn("value: {}\n", unsigned); | 8721 | std.debug.warn("value: {}\n", .{unsigned}); |
| 8710 | } | 8722 | } |
| 8711 | {#code_end#} | 8723 | {#code_end#} |
| 8712 | <p> | 8724 | <p> |
| ... | @@ -8728,7 +8740,7 @@ const std = @import("std"); | ... | @@ -8728,7 +8740,7 @@ const std = @import("std"); |
| 8728 | pub fn main() void { | 8740 | pub fn main() void { |
| 8729 | var spartan_count: u16 = 300; | 8741 | var spartan_count: u16 = 300; |
| 8730 | const byte = @intCast(u8, spartan_count); | 8742 | const byte = @intCast(u8, spartan_count); |
| 8731 | std.debug.warn("value: {}\n", byte); | 8743 | std.debug.warn("value: {}\n", .{byte}); |
| 8732 | } | 8744 | } |
| 8733 | {#code_end#} | 8745 | {#code_end#} |
| 8734 | <p> | 8746 | <p> |
| ... | @@ -8762,7 +8774,7 @@ const std = @import("std"); | ... | @@ -8762,7 +8774,7 @@ const std = @import("std"); |
| 8762 | pub fn main() void { | 8774 | pub fn main() void { |
| 8763 | var byte: u8 = 255; | 8775 | var byte: u8 = 255; |
| 8764 | byte += 1; | 8776 | byte += 1; |
| 8765 | std.debug.warn("value: {}\n", byte); | 8777 | std.debug.warn("value: {}\n", .{byte}); |
| 8766 | } | 8778 | } |
| 8767 | {#code_end#} | 8779 | {#code_end#} |
| 8768 | {#header_close#} | 8780 | {#header_close#} |
| ... | @@ -8785,11 +8797,11 @@ pub fn main() !void { | ... | @@ -8785,11 +8797,11 @@ pub fn main() !void { |
| 8785 | var byte: u8 = 255; | 8797 | var byte: u8 = 255; |
| 8786 | | 8798 | |
| 8787 | byte = if (math.add(u8, byte, 1)) |result| result else |err| { | 8799 | byte = if (math.add(u8, byte, 1)) |result| result else |err| { |
| 8788 | warn("unable to add one: {}\n", @errorName(err)); | 8800 | warn("unable to add one: {}\n", .{@errorName(err)}); |
| 8789 | return err; | 8801 | return err; |
| 8790 | }; | 8802 | }; |
| 8791 | | 8803 | |
| 8792 | warn("result: {}\n", byte); | 8804 | warn("result: {}\n", .{byte}); |
| 8793 | } | 8805 | } |
| 8794 | {#code_end#} | 8806 | {#code_end#} |
| 8795 | {#header_close#} | 8807 | {#header_close#} |
| ... | @@ -8814,9 +8826,9 @@ pub fn main() void { | ... | @@ -8814,9 +8826,9 @@ pub fn main() void { |
| 8814 | | 8826 | |
| 8815 | var result: u8 = undefined; | 8827 | var result: u8 = undefined; |
| 8816 | if (@addWithOverflow(u8, byte, 10, &result)) { | 8828 | if (@addWithOverflow(u8, byte, 10, &result)) { |
| 8817 | warn("overflowed result: {}\n", result); | 8829 | warn("overflowed result: {}\n", .{result}); |
| 8818 | } else { | 8830 | } else { |
| 8819 | warn("result: {}\n", result); | 8831 | warn("result: {}\n", .{result}); |
| 8820 | } | 8832 | } |
| 8821 | } | 8833 | } |
| 8822 | {#code_end#} | 8834 | {#code_end#} |
| ... | @@ -8861,7 +8873,7 @@ const std = @import("std"); | ... | @@ -8861,7 +8873,7 @@ const std = @import("std"); |
| 8861 | pub fn main() void { | 8873 | pub fn main() void { |
| 8862 | var x: u8 = 0b01010101; | 8874 | var x: u8 = 0b01010101; |
| 8863 | var y = @shlExact(x, 2); | 8875 | var y = @shlExact(x, 2); |
| 8864 | std.debug.warn("value: {}\n", y); | 8876 | std.debug.warn("value: {}\n", .{y}); |
| 8865 | } | 8877 | } |
| 8866 | {#code_end#} | 8878 | {#code_end#} |
| 8867 | {#header_close#} | 8879 | {#header_close#} |
| ... | @@ -8879,7 +8891,7 @@ const std = @import("std"); | ... | @@ -8879,7 +8891,7 @@ const std = @import("std"); |
| 8879 | pub fn main() void { | 8891 | pub fn main() void { |
| 8880 | var x: u8 = 0b10101010; | 8892 | var x: u8 = 0b10101010; |
| 8881 | var y = @shrExact(x, 2); | 8893 | var y = @shrExact(x, 2); |
| 8882 | std.debug.warn("value: {}\n", y); | 8894 | std.debug.warn("value: {}\n", .{y}); |
| 8883 | } | 8895 | } |
| 8884 | {#code_end#} | 8896 | {#code_end#} |
| 8885 | {#header_close#} | 8897 | {#header_close#} |
| ... | @@ -8900,7 +8912,7 @@ pub fn main() void { | ... | @@ -8900,7 +8912,7 @@ pub fn main() void { |
| 8900 | var a: u32 = 1; | 8912 | var a: u32 = 1; |
| 8901 | var b: u32 = 0; | 8913 | var b: u32 = 0; |
| 8902 | var c = a / b; | 8914 | var c = a / b; |
| 8903 | std.debug.warn("value: {}\n", c); | 8915 | std.debug.warn("value: {}\n", .{c}); |
| 8904 | } | 8916 | } |
| 8905 | {#code_end#} | 8917 | {#code_end#} |
| 8906 | {#header_close#} | 8918 | {#header_close#} |
| ... | @@ -8921,7 +8933,7 @@ pub fn main() void { | ... | @@ -8921,7 +8933,7 @@ pub fn main() void { |
| 8921 | var a: u32 = 10; | 8933 | var a: u32 = 10; |
| 8922 | var b: u32 = 0; | 8934 | var b: u32 = 0; |
| 8923 | var c = a % b; | 8935 | var c = a % b; |
| 8924 | std.debug.warn("value: {}\n", c); | 8936 | std.debug.warn("value: {}\n", .{c}); |
| 8925 | } | 8937 | } |
| 8926 | {#code_end#} | 8938 | {#code_end#} |
| 8927 | {#header_close#} | 8939 | {#header_close#} |
| ... | @@ -8942,7 +8954,7 @@ pub fn main() void { | ... | @@ -8942,7 +8954,7 @@ pub fn main() void { |
| 8942 | var a: u32 = 10; | 8954 | var a: u32 = 10; |
| 8943 | var b: u32 = 3; | 8955 | var b: u32 = 3; |
| 8944 | var c = @divExact(a, b); | 8956 | var c = @divExact(a, b); |
| 8945 | std.debug.warn("value: {}\n", c); | 8957 | std.debug.warn("value: {}\n", .{c}); |
| 8946 | } | 8958 | } |
| 8947 | {#code_end#} | 8959 | {#code_end#} |
| 8948 | {#header_close#} | 8960 | {#header_close#} |
| ... | @@ -8961,7 +8973,7 @@ const std = @import("std"); | ... | @@ -8961,7 +8973,7 @@ const std = @import("std"); |
| 8961 | pub fn main() void { | 8973 | pub fn main() void { |
| 8962 | var bytes = [5]u8{ 1, 2, 3, 4, 5 }; | 8974 | var bytes = [5]u8{ 1, 2, 3, 4, 5 }; |
| 8963 | var slice = @bytesToSlice(u32, bytes[0..]); | 8975 | var slice = @bytesToSlice(u32, bytes[0..]); |
| 8964 | std.debug.warn("value: {}\n", slice[0]); | 8976 | std.debug.warn("value: {}\n", .{slice[0]}); |
| 8965 | } | 8977 | } |
| 8966 | {#code_end#} | 8978 | {#code_end#} |
| 8967 | {#header_close#} | 8979 | {#header_close#} |
| ... | @@ -8980,7 +8992,7 @@ const std = @import("std"); | ... | @@ -8980,7 +8992,7 @@ const std = @import("std"); |
| 8980 | pub fn main() void { | 8992 | pub fn main() void { |
| 8981 | var optional_number: ?i32 = null; | 8993 | var optional_number: ?i32 = null; |
| 8982 | var number = optional_number.?; | 8994 | var number = optional_number.?; |
| 8983 | std.debug.warn("value: {}\n", number); | 8995 | std.debug.warn("value: {}\n", .{number}); |
| 8984 | } | 8996 | } |
| 8985 | {#code_end#} | 8997 | {#code_end#} |
| 8986 | <p>One way to avoid this crash is to test for null instead of assuming non-null, with | 8998 | <p>One way to avoid this crash is to test for null instead of assuming non-null, with |
| ... | @@ -8991,9 +9003,9 @@ pub fn main() void { | ... | @@ -8991,9 +9003,9 @@ pub fn main() void { |
| 8991 | const optional_number: ?i32 = null; | 9003 | const optional_number: ?i32 = null; |
| 8992 | | 9004 | |
| 8993 | if (optional_number) |number| { | 9005 | if (optional_number) |number| { |
| 8994 | warn("got number: {}\n", number); | 9006 | warn("got number: {}\n", .{number}); |
| 8995 | } else { | 9007 | } else { |
| 8996 | warn("it's null\n"); | 9008 | warn("it's null\n", .{}); |
| 8997 | } | 9009 | } |
| 8998 | } | 9010 | } |
| 8999 | {#code_end#} | 9011 | {#code_end#} |
| ... | @@ -9016,7 +9028,7 @@ const std = @import("std"); | ... | @@ -9016,7 +9028,7 @@ const std = @import("std"); |
| 9016 | | 9028 | |
| 9017 | pub fn main() void { | 9029 | pub fn main() void { |
| 9018 | const number = getNumberOrFail() catch unreachable; | 9030 | const number = getNumberOrFail() catch unreachable; |
| 9019 | std.debug.warn("value: {}\n", number); | 9031 | std.debug.warn("value: {}\n", .{number}); |
| 9020 | } | 9032 | } |
| 9021 | | 9033 | |
| 9022 | fn getNumberOrFail() !i32 { | 9034 | fn getNumberOrFail() !i32 { |
| ... | @@ -9032,9 +9044,9 @@ pub fn main() void { | ... | @@ -9032,9 +9044,9 @@ pub fn main() void { |
| 9032 | const result = getNumberOrFail(); | 9044 | const result = getNumberOrFail(); |
| 9033 | | 9045 | |
| 9034 | if (result) |number| { | 9046 | if (result) |number| { |
| 9035 | warn("got number: {}\n", number); | 9047 | warn("got number: {}\n", .{number}); |
| 9036 | } else |err| { | 9048 | } else |err| { |
| 9037 | warn("got error: {}\n", @errorName(err)); | 9049 | warn("got error: {}\n", .{@errorName(err)}); |
| 9038 | } | 9050 | } |
| 9039 | } | 9051 | } |
| 9040 | | 9052 | |
| ... | @@ -9061,7 +9073,7 @@ pub fn main() void { | ... | @@ -9061,7 +9073,7 @@ pub fn main() void { |
| 9061 | var err = error.AnError; | 9073 | var err = error.AnError; |
| 9062 | var number = @errorToInt(err) + 500; | 9074 | var number = @errorToInt(err) + 500; |
| 9063 | var invalid_err = @intToError(number); | 9075 | var invalid_err = @intToError(number); |
| 9064 | std.debug.warn("value: {}\n", number); | 9076 | std.debug.warn("value: {}\n", .{number}); |
| 9065 | } | 9077 | } |
| 9066 | {#code_end#} | 9078 | {#code_end#} |
| 9067 | {#header_close#} | 9079 | {#header_close#} |
| ... | @@ -9091,7 +9103,7 @@ const Foo = enum { | ... | @@ -9091,7 +9103,7 @@ const Foo = enum { |
| 9091 | pub fn main() void { | 9103 | pub fn main() void { |
| 9092 | var a: u2 = 3; | 9104 | var a: u2 = 3; |
| 9093 | var b = @intToEnum(Foo, a); | 9105 | var b = @intToEnum(Foo, a); |
| 9094 | std.debug.warn("value: {}\n", @tagName(b)); | 9106 | std.debug.warn("value: {}\n", .{@tagName(b)}); |
| 9095 | } | 9107 | } |
| 9096 | {#code_end#} | 9108 | {#code_end#} |
| 9097 | {#header_close#} | 9109 | {#header_close#} |
| ... | @@ -9128,7 +9140,7 @@ pub fn main() void { | ... | @@ -9128,7 +9140,7 @@ pub fn main() void { |
| 9128 | } | 9140 | } |
| 9129 | fn foo(set1: Set1) void { | 9141 | fn foo(set1: Set1) void { |
| 9130 | const x = @errSetCast(Set2, set1); | 9142 | const x = @errSetCast(Set2, set1); |
| 9131 | std.debug.warn("value: {}\n", x); | 9143 | std.debug.warn("value: {}\n", .{x}); |
| 9132 | } | 9144 | } |
| 9133 | {#code_end#} | 9145 | {#code_end#} |
| 9134 | {#header_close#} | 9146 | {#header_close#} |
| ... | @@ -9184,7 +9196,7 @@ pub fn main() void { | ... | @@ -9184,7 +9196,7 @@ pub fn main() void { |
| 9184 | | 9196 | |
| 9185 | fn bar(f: *Foo) void { | 9197 | fn bar(f: *Foo) void { |
| 9186 | f.float = 12.34; | 9198 | f.float = 12.34; |
| 9187 | std.debug.warn("value: {}\n", f.float); | 9199 | std.debug.warn("value: {}\n", .{f.float}); |
| 9188 | } | 9200 | } |
| 9189 | {#code_end#} | 9201 | {#code_end#} |
| 9190 | <p> | 9202 | <p> |
| ... | @@ -9208,7 +9220,7 @@ pub fn main() void { | ... | @@ -9208,7 +9220,7 @@ pub fn main() void { |
| 9208 | | 9220 | |
| 9209 | fn bar(f: *Foo) void { | 9221 | fn bar(f: *Foo) void { |
| 9210 | f.* = Foo{ .float = 12.34 }; | 9222 | f.* = Foo{ .float = 12.34 }; |
| 9211 | std.debug.warn("value: {}\n", f.float); | 9223 | std.debug.warn("value: {}\n", .{f.float}); |
| 9212 | } | 9224 | } |
| 9213 | {#code_end#} | 9225 | {#code_end#} |
| 9214 | <p> | 9226 | <p> |
| ... | @@ -9227,7 +9239,7 @@ pub fn main() void { | ... | @@ -9227,7 +9239,7 @@ pub fn main() void { |
| 9227 | var f = Foo{ .int = 42 }; | 9239 | var f = Foo{ .int = 42 }; |
| 9228 | f = Foo{ .float = undefined }; | 9240 | f = Foo{ .float = undefined }; |
| 9229 | bar(&f); | 9241 | bar(&f); |
| 9230 | std.debug.warn("value: {}\n", f.float); | 9242 | std.debug.warn("value: {}\n", .{f.float}); |
| 9231 | } | 9243 | } |
| 9232 | | 9244 | |
| 9233 | fn bar(f: *Foo) void { | 9245 | fn bar(f: *Foo) void { |
| ... | @@ -9348,7 +9360,7 @@ pub fn main() !void { | ... | @@ -9348,7 +9360,7 @@ pub fn main() !void { |
| 9348 | const allocator = &arena.allocator; | 9360 | const allocator = &arena.allocator; |
| 9349 | | 9361 | |
| 9350 | const ptr = try allocator.create(i32); | 9362 | const ptr = try allocator.create(i32); |
| 9351 | std.debug.warn("ptr={*}\n", ptr); | 9363 | std.debug.warn("ptr={*}\n", .{ptr}); |
| 9352 | } | 9364 | } |
| 9353 | {#code_end#} | 9365 | {#code_end#} |
| 9354 | When using this kind of allocator, there is no need to free anything manually. Everything | 9366 | When using this kind of allocator, there is no need to free anything manually. Everything |
| ... | @@ -9881,7 +9893,7 @@ pub fn main() !void { | ... | @@ -9881,7 +9893,7 @@ pub fn main() !void { |
| 9881 | defer std.process.argsFree(std.heap.page_allocator, args); | 9893 | defer std.process.argsFree(std.heap.page_allocator, args); |
| 9882 | | 9894 | |
| 9883 | for (args) |arg, i| { | 9895 | for (args) |arg, i| { |
| 9884 | std.debug.warn("{}: {}\n", i, arg); | 9896 | std.debug.warn("{}: {}\n", .{i, arg}); |
| 9885 | } | 9897 | } |
| 9886 | } | 9898 | } |
| 9887 | {#code_end#} | 9899 | {#code_end#} |