authorgravatar for eleanor@eleanor-nb.comEleanor NB <eleanor@eleanor-nb.com> 2020-06-19 19:38:22+10:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-06-19 19:03:37-04:00
log605769ec25923a50fc01d29d5837fbc48abffcf1
treec438abe24a3000da109455a081a99c30184b440d
parent237c5429b0e8a089c89d13031ae6004ebac55ba9

Replaced all occurrences of std.debug.warn in the docs with std.debug.print


1 files changed, 78 insertions(+), 79 deletions(-)

doc/langref.html.in+78-79
...@@ -236,19 +236,18 @@ pub fn main() !void {...@@ -236,19 +236,18 @@ pub fn main() !void {
236}236}
237 {#code_end#}237 {#code_end#}
238 <p>238 <p>
239 Usually you don't want to write to stdout. You want to write to stderr. And you239 Usually you don't want to write to stdout. You want to write to stderr, and you
240 don't care if it fails. It's more like a <em>warning message</em> that you want240 don't care if it fails. For that you can use a simpler API:
241 to emit. For that you can use a simpler API:
242 </p>241 </p>
243 {#code_begin|exe|hello#}242 {#code_begin|exe|hello#}
244const warn = @import("std").debug.warn;243const print = @import("std").debug.print;
245244
246pub fn main() void {245pub fn main() void {
247 warn("Hello, world!\n", .{});246 print("Hello, world!\n", .{});
248}247}
249 {#code_end#}248 {#code_end#}
250 <p>249 <p>
251 Note that you can leave off the {#syntax#}!{#endsyntax#} from the return type because {#syntax#}warn{#endsyntax#} cannot fail.250 Note that you can leave off the {#syntax#}!{#endsyntax#} from the return type because {#syntax#}print{#endsyntax#} cannot fail.
252 </p>251 </p>
253 {#see_also|Values|@import|Errors|Root Source File#}252 {#see_also|Values|@import|Errors|Root Source File#}
254 {#header_close#}253 {#header_close#}
...@@ -307,7 +306,7 @@ const Timestamp = struct {...@@ -307,7 +306,7 @@ const Timestamp = struct {
307 {#header_open|Values#}306 {#header_open|Values#}
308 {#code_begin|exe|values#}307 {#code_begin|exe|values#}
309// Top-level declarations are order-independent:308// Top-level declarations are order-independent:
310const warn = std.debug.warn;309const print = std.debug.print;
311const std = @import("std");310const std = @import("std");
312const os = std.os;311const os = std.os;
313const assert = std.debug.assert;312const assert = std.debug.assert;
...@@ -315,14 +314,14 @@ const assert = std.debug.assert;...@@ -315,14 +314,14 @@ const assert = std.debug.assert;
315pub fn main() void {314pub fn main() void {
316 // integers315 // integers
317 const one_plus_one: i32 = 1 + 1;316 const one_plus_one: i32 = 1 + 1;
318 warn("1 + 1 = {}\n", .{one_plus_one});317 print("1 + 1 = {}\n", .{one_plus_one});
319318
320 // floats319 // floats
321 const seven_div_three: f32 = 7.0 / 3.0;320 const seven_div_three: f32 = 7.0 / 3.0;
322 warn("7.0 / 3.0 = {}\n", .{seven_div_three});321 print("7.0 / 3.0 = {}\n", .{seven_div_three});
323322
324 // boolean323 // boolean
325 warn("{}\n{}\n{}\n", .{324 print("{}\n{}\n{}\n", .{
326 true and false,325 true and false,
327 true or false,326 true or false,
328 !true,327 !true,
...@@ -332,7 +331,7 @@ pub fn main() void {...@@ -332,7 +331,7 @@ pub fn main() void {
332 var optional_value: ?[]const u8 = null;331 var optional_value: ?[]const u8 = null;
333 assert(optional_value == null);332 assert(optional_value == null);
334333
335 warn("\noptional 1\ntype: {}\nvalue: {}\n", .{334 print("\noptional 1\ntype: {}\nvalue: {}\n", .{
336 @typeName(@TypeOf(optional_value)),335 @typeName(@TypeOf(optional_value)),
337 optional_value,336 optional_value,
338 });337 });
...@@ -340,7 +339,7 @@ pub fn main() void {...@@ -340,7 +339,7 @@ pub fn main() void {
340 optional_value = "hi";339 optional_value = "hi";
341 assert(optional_value != null);340 assert(optional_value != null);
342341
343 warn("\noptional 2\ntype: {}\nvalue: {}\n", .{342 print("\noptional 2\ntype: {}\nvalue: {}\n", .{
344 @typeName(@TypeOf(optional_value)),343 @typeName(@TypeOf(optional_value)),
345 optional_value,344 optional_value,
346 });345 });
...@@ -348,14 +347,14 @@ pub fn main() void {...@@ -348,14 +347,14 @@ pub fn main() void {
348 // error union347 // error union
349 var number_or_error: anyerror!i32 = error.ArgNotFound;348 var number_or_error: anyerror!i32 = error.ArgNotFound;
350349
351 warn("\nerror union 1\ntype: {}\nvalue: {}\n", .{350 print("\nerror union 1\ntype: {}\nvalue: {}\n", .{
352 @typeName(@TypeOf(number_or_error)),351 @typeName(@TypeOf(number_or_error)),
353 number_or_error,352 number_or_error,
354 });353 });
355354
356 number_or_error = 1234;355 number_or_error = 1234;
357356
358 warn("\nerror union 2\ntype: {}\nvalue: {}\n", .{357 print("\nerror union 2\ntype: {}\nvalue: {}\n", .{
359 @typeName(@TypeOf(number_or_error)),358 @typeName(@TypeOf(number_or_error)),
360 number_or_error,359 number_or_error,
361 });360 });
...@@ -994,15 +993,15 @@ export fn foo_optimized(x: f64) f64 {...@@ -994,15 +993,15 @@ export fn foo_optimized(x: f64) f64 {
994 which operates in strict mode.</p>993 which operates in strict mode.</p>
995 {#code_begin|exe|float_mode#}994 {#code_begin|exe|float_mode#}
996 {#code_link_object|foo#}995 {#code_link_object|foo#}
997const warn = @import("std").debug.warn;996const print = @import("std").debug.print;
998997
999extern fn foo_strict(x: f64) f64;998extern fn foo_strict(x: f64) f64;
1000extern fn foo_optimized(x: f64) f64;999extern fn foo_optimized(x: f64) f64;
10011000
1002pub fn main() void {1001pub fn main() void {
1003 const x = 0.001;1002 const x = 0.001;
1004 warn("optimized = {}\n", .{foo_optimized(x)});1003 print("optimized = {}\n", .{foo_optimized(x)});
1005 warn("strict = {}\n", .{foo_strict(x)});1004 print("strict = {}\n", .{foo_strict(x)});
1006}1005}
1007 {#code_end#}1006 {#code_end#}
1008 {#see_also|@setFloatMode|Division by Zero#}1007 {#see_also|@setFloatMode|Division by Zero#}
...@@ -2668,9 +2667,9 @@ const std = @import("std");...@@ -2668,9 +2667,9 @@ const std = @import("std");
26682667
2669pub fn main() void {2668pub fn main() void {
2670 const Foo = struct {};2669 const Foo = struct {};
2671 std.debug.warn("variable: {}\n", .{@typeName(Foo)});2670 std.debug.print("variable: {}\n", .{@typeName(Foo)});
2672 std.debug.warn("anonymous: {}\n", .{@typeName(struct {})});2671 std.debug.print("anonymous: {}\n", .{@typeName(struct {})});
2673 std.debug.warn("function: {}\n", .{@typeName(List(i32))});2672 std.debug.print("function: {}\n", .{@typeName(List(i32))});
2674}2673}
26752674
2676fn List(comptime T: type) type {2675fn List(comptime T: type) type {
...@@ -3869,7 +3868,7 @@ test "if error union" {...@@ -3869,7 +3868,7 @@ test "if error union" {
3869 {#code_begin|test|defer#}3868 {#code_begin|test|defer#}
3870const std = @import("std");3869const std = @import("std");
3871const assert = std.debug.assert;3870const assert = std.debug.assert;
3872const warn = std.debug.warn;3871const print = std.debug.print;
38733872
3874// defer will execute an expression at the end of the current scope.3873// defer will execute an expression at the end of the current scope.
3875fn deferExample() usize {3874fn deferExample() usize {
...@@ -3892,18 +3891,18 @@ test "defer basics" {...@@ -3892,18 +3891,18 @@ test "defer basics" {
3892// If multiple defer statements are specified, they will be executed in3891// If multiple defer statements are specified, they will be executed in
3893// the reverse order they were run.3892// the reverse order they were run.
3894fn deferUnwindExample() void {3893fn deferUnwindExample() void {
3895 warn("\n", .{});3894 print("\n", .{});
38963895
3897 defer {3896 defer {
3898 warn("1 ", .{});3897 print("1 ", .{});
3899 }3898 }
3900 defer {3899 defer {
3901 warn("2 ", .{});3900 print("2 ", .{});
3902 }3901 }
3903 if (false) {3902 if (false) {
3904 // defers are not run if they are never executed.3903 // defers are not run if they are never executed.
3905 defer {3904 defer {
3906 warn("3 ", .{});3905 print("3 ", .{});
3907 }3906 }
3908 }3907 }
3909}3908}
...@@ -3918,15 +3917,15 @@ test "defer unwinding" {...@@ -3918,15 +3917,15 @@ test "defer unwinding" {
3918// This is especially useful in allowing a function to clean up properly3917// This is especially useful in allowing a function to clean up properly
3919// on error, and replaces goto error handling tactics as seen in c.3918// on error, and replaces goto error handling tactics as seen in c.
3920fn deferErrorExample(is_error: bool) !void {3919fn deferErrorExample(is_error: bool) !void {
3921 warn("\nstart of function\n", .{});3920 print("\nstart of function\n", .{});
39223921
3923 // This will always be executed on exit3922 // This will always be executed on exit
3924 defer {3923 defer {
3925 warn("end of function\n", .{});3924 print("end of function\n", .{});
3926 }3925 }
39273926
3928 errdefer {3927 errdefer {
3929 warn("encountered an error!\n", .{});3928 print("encountered an error!\n", .{});
3930 }3929 }
39313930
3932 if (is_error) {3931 if (is_error) {
...@@ -5925,13 +5924,13 @@ const Node = struct {...@@ -5925,13 +5924,13 @@ const Node = struct {
5925 Putting all of this together, let's see how {#syntax#}printf{#endsyntax#} works in Zig.5924 Putting all of this together, let's see how {#syntax#}printf{#endsyntax#} works in Zig.
5926 </p>5925 </p>
5927 {#code_begin|exe|printf#}5926 {#code_begin|exe|printf#}
5928const warn = @import("std").debug.warn;5927const print = @import("std").debug.print;
59295928
5930const a_number: i32 = 1234;5929const a_number: i32 = 1234;
5931const a_string = "foobar";5930const a_string = "foobar";
59325931
5933pub fn main() void {5932pub fn main() void {
5934 warn("here is a string: '{}' here is a number: {}\n", .{a_string, a_number});5933 print("here is a string: '{}' here is a number: {}\n", .{a_string, a_number});
5935}5934}
5936 {#code_end#}5935 {#code_end#}
59375936
...@@ -6045,13 +6044,13 @@ pub fn printValue(self: *OutStream, value: var) !void {...@@ -6045,13 +6044,13 @@ pub fn printValue(self: *OutStream, value: var) !void {
6045 And now, what happens if we give too many arguments to {#syntax#}printf{#endsyntax#}?6044 And now, what happens if we give too many arguments to {#syntax#}printf{#endsyntax#}?
6046 </p>6045 </p>
6047 {#code_begin|test_err|Unused arguments#}6046 {#code_begin|test_err|Unused arguments#}
6048const warn = @import("std").debug.warn;6047const print = @import("std").debug.print;
60496048
6050const a_number: i32 = 1234;6049const a_number: i32 = 1234;
6051const a_string = "foobar";6050const a_string = "foobar";
60526051
6053test "printf too many arguments" {6052test "printf too many arguments" {
6054 warn("here is a string: '{}' here is a number: {}\n", .{6053 print("here is a string: '{}' here is a number: {}\n", .{
6055 a_string,6054 a_string,
6056 a_number,6055 a_number,
6057 a_number,6056 a_number,
...@@ -6066,14 +6065,14 @@ test "printf too many arguments" {...@@ -6066,14 +6065,14 @@ test "printf too many arguments" {
6066 only that it is a compile-time known value that can be coerced to a {#syntax#}[]const u8{#endsyntax#}:6065 only that it is a compile-time known value that can be coerced to a {#syntax#}[]const u8{#endsyntax#}:
6067 </p>6066 </p>
6068 {#code_begin|exe|printf#}6067 {#code_begin|exe|printf#}
6069const warn = @import("std").debug.warn;6068const print = @import("std").debug.print;
60706069
6071const a_number: i32 = 1234;6070const a_number: i32 = 1234;
6072const a_string = "foobar";6071const a_string = "foobar";
6073const fmt = "here is a string: '{}' here is a number: {}\n";6072const fmt = "here is a string: '{}' here is a number: {}\n";
60746073
6075pub fn main() void {6074pub fn main() void {
6076 warn(fmt, .{a_string, a_number});6075 print(fmt, .{a_string, a_number});
6077}6076}
6078 {#code_end#}6077 {#code_end#}
6079 <p>6078 <p>
...@@ -6511,7 +6510,7 @@ pub fn main() void {...@@ -6511,7 +6510,7 @@ pub fn main() void {
65116510
6512fn amainWrap() void {6511fn amainWrap() void {
6513 amain() catch |e| {6512 amain() catch |e| {
6514 std.debug.warn("{}\n", .{e});6513 std.debug.print("{}\n", .{e});
6515 if (@errorReturnTrace()) |trace| {6514 if (@errorReturnTrace()) |trace| {
6516 std.debug.dumpStackTrace(trace.*);6515 std.debug.dumpStackTrace(trace.*);
6517 }6516 }
...@@ -6541,8 +6540,8 @@ fn amain() !void {...@@ -6541,8 +6540,8 @@ fn amain() !void {
6541 const download_text = try await download_frame;6540 const download_text = try await download_frame;
6542 defer allocator.free(download_text);6541 defer allocator.free(download_text);
65436542
6544 std.debug.warn("download_text: {}\n", .{download_text});6543 std.debug.print("download_text: {}\n", .{download_text});
6545 std.debug.warn("file_text: {}\n", .{file_text});6544 std.debug.print("file_text: {}\n", .{file_text});
6546}6545}
65476546
6548var global_download_frame: anyframe = undefined;6547var global_download_frame: anyframe = undefined;
...@@ -6552,7 +6551,7 @@ fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 {...@@ -6552,7 +6551,7 @@ fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 {
6552 suspend {6551 suspend {
6553 global_download_frame = @frame();6552 global_download_frame = @frame();
6554 }6553 }
6555 std.debug.warn("fetchUrl returning\n", .{});6554 std.debug.print("fetchUrl returning\n", .{});
6556 return result;6555 return result;
6557}6556}
65586557
...@@ -6563,7 +6562,7 @@ fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 {...@@ -6563,7 +6562,7 @@ fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 {
6563 suspend {6562 suspend {
6564 global_file_frame = @frame();6563 global_file_frame = @frame();
6565 }6564 }
6566 std.debug.warn("readFile returning\n", .{});6565 std.debug.print("readFile returning\n", .{});
6567 return result;6566 return result;
6568}6567}
6569 {#code_end#}6568 {#code_end#}
...@@ -6581,7 +6580,7 @@ pub fn main() void {...@@ -6581,7 +6580,7 @@ pub fn main() void {
65816580
6582fn amainWrap() void {6581fn amainWrap() void {
6583 amain() catch |e| {6582 amain() catch |e| {
6584 std.debug.warn("{}\n", .{e});6583 std.debug.print("{}\n", .{e});
6585 if (@errorReturnTrace()) |trace| {6584 if (@errorReturnTrace()) |trace| {
6586 std.debug.dumpStackTrace(trace.*);6585 std.debug.dumpStackTrace(trace.*);
6587 }6586 }
...@@ -6611,21 +6610,21 @@ fn amain() !void {...@@ -6611,21 +6610,21 @@ fn amain() !void {
6611 const download_text = try await download_frame;6610 const download_text = try await download_frame;
6612 defer allocator.free(download_text);6611 defer allocator.free(download_text);
66136612
6614 std.debug.warn("download_text: {}\n", .{download_text});6613 std.debug.print("download_text: {}\n", .{download_text});
6615 std.debug.warn("file_text: {}\n", .{file_text});6614 std.debug.print("file_text: {}\n", .{file_text});
6616}6615}
66176616
6618fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 {6617fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 {
6619 const result = try std.mem.dupe(allocator, u8, "this is the downloaded url contents");6618 const result = try std.mem.dupe(allocator, u8, "this is the downloaded url contents");
6620 errdefer allocator.free(result);6619 errdefer allocator.free(result);
6621 std.debug.warn("fetchUrl returning\n", .{});6620 std.debug.print("fetchUrl returning\n", .{});
6622 return result;6621 return result;
6623}6622}
66246623
6625fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 {6624fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 {
6626 const result = try std.mem.dupe(allocator, u8, "this is the file contents");6625 const result = try std.mem.dupe(allocator, u8, "this is the file contents");
6627 errdefer allocator.free(result);6626 errdefer allocator.free(result);
6628 std.debug.warn("readFile returning\n", .{});6627 std.debug.print("readFile returning\n", .{});
6629 return result;6628 return result;
6630}6629}
6631 {#code_end#}6630 {#code_end#}
...@@ -7121,7 +7120,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val...@@ -7121,7 +7120,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
7121 compile-time executing code.7120 compile-time executing code.
7122 </p>7121 </p>
7123 {#code_begin|test_err|found compile log statement#}7122 {#code_begin|test_err|found compile log statement#}
7124const warn = @import("std").debug.warn;7123const print = @import("std").debug.print;
71257124
7126const num1 = blk: {7125const num1 = blk: {
7127 var val1: i32 = 99;7126 var val1: i32 = 99;
...@@ -7133,7 +7132,7 @@ const num1 = blk: {...@@ -7133,7 +7132,7 @@ const num1 = blk: {
7133test "main" {7132test "main" {
7134 @compileLog("comptime in main");7133 @compileLog("comptime in main");
71357134
7136 warn("Runtime in main, num1 = {}.\n", .{num1});7135 print("Runtime in main, num1 = {}.\n", .{num1});
7137}7136}
7138 {#code_end#}7137 {#code_end#}
7139 <p>7138 <p>
...@@ -7145,7 +7144,7 @@ test "main" {...@@ -7145,7 +7144,7 @@ test "main" {
7145 program compiles successfully and the generated executable prints:7144 program compiles successfully and the generated executable prints:
7146 </p>7145 </p>
7147 {#code_begin|test#}7146 {#code_begin|test#}
7148const warn = @import("std").debug.warn;7147const print = @import("std").debug.print;
71497148
7150const num1 = blk: {7149const num1 = blk: {
7151 var val1: i32 = 99;7150 var val1: i32 = 99;
...@@ -7154,7 +7153,7 @@ const num1 = blk: {...@@ -7154,7 +7153,7 @@ const num1 = blk: {
7154};7153};
71557154
7156test "main" {7155test "main" {
7157 warn("Runtime in main, num1 = {}.\n", .{num1});7156 print("Runtime in main, num1 = {}.\n", .{num1});
7158}7157}
7159 {#code_end#}7158 {#code_end#}
7160 {#header_close#}7159 {#header_close#}
...@@ -8555,7 +8554,7 @@ const std = @import("std");...@@ -8555,7 +8554,7 @@ const std = @import("std");
8555pub fn main() void {8554pub fn main() void {
8556 var value: i32 = -1;8555 var value: i32 = -1;
8557 var unsigned = @intCast(u32, value);8556 var unsigned = @intCast(u32, value);
8558 std.debug.warn("value: {}\n", .{unsigned});8557 std.debug.print("value: {}\n", .{unsigned});
8559}8558}
8560 {#code_end#}8559 {#code_end#}
8561 <p>8560 <p>
...@@ -8577,7 +8576,7 @@ const std = @import("std");...@@ -8577,7 +8576,7 @@ const std = @import("std");
8577pub fn main() void {8576pub fn main() void {
8578 var spartan_count: u16 = 300;8577 var spartan_count: u16 = 300;
8579 const byte = @intCast(u8, spartan_count);8578 const byte = @intCast(u8, spartan_count);
8580 std.debug.warn("value: {}\n", .{byte});8579 std.debug.print("value: {}\n", .{byte});
8581}8580}
8582 {#code_end#}8581 {#code_end#}
8583 <p>8582 <p>
...@@ -8611,7 +8610,7 @@ const std = @import("std");...@@ -8611,7 +8610,7 @@ const std = @import("std");
8611pub fn main() void {8610pub fn main() void {
8612 var byte: u8 = 255;8611 var byte: u8 = 255;
8613 byte += 1;8612 byte += 1;
8614 std.debug.warn("value: {}\n", .{byte});8613 std.debug.print("value: {}\n", .{byte});
8615}8614}
8616 {#code_end#}8615 {#code_end#}
8617 {#header_close#}8616 {#header_close#}
...@@ -8629,16 +8628,16 @@ pub fn main() void {...@@ -8629,16 +8628,16 @@ pub fn main() void {
8629 <p>Example of catching an overflow for addition:</p>8628 <p>Example of catching an overflow for addition:</p>
8630 {#code_begin|exe_err#}8629 {#code_begin|exe_err#}
8631const math = @import("std").math;8630const math = @import("std").math;
8632const warn = @import("std").debug.warn;8631const print = @import("std").debug.print;
8633pub fn main() !void {8632pub fn main() !void {
8634 var byte: u8 = 255;8633 var byte: u8 = 255;
86358634
8636 byte = if (math.add(u8, byte, 1)) |result| result else |err| {8635 byte = if (math.add(u8, byte, 1)) |result| result else |err| {
8637 warn("unable to add one: {}\n", .{@errorName(err)});8636 print("unable to add one: {}\n", .{@errorName(err)});
8638 return err;8637 return err;
8639 };8638 };
86408639
8641 warn("result: {}\n", .{byte});8640 print("result: {}\n", .{byte});
8642}8641}
8643 {#code_end#}8642 {#code_end#}
8644 {#header_close#}8643 {#header_close#}
...@@ -8657,15 +8656,15 @@ pub fn main() !void {...@@ -8657,15 +8656,15 @@ pub fn main() !void {
8657 Example of {#link|@addWithOverflow#}:8656 Example of {#link|@addWithOverflow#}:
8658 </p>8657 </p>
8659 {#code_begin|exe#}8658 {#code_begin|exe#}
8660const warn = @import("std").debug.warn;8659const print = @import("std").debug.print;
8661pub fn main() void {8660pub fn main() void {
8662 var byte: u8 = 255;8661 var byte: u8 = 255;
86638662
8664 var result: u8 = undefined;8663 var result: u8 = undefined;
8665 if (@addWithOverflow(u8, byte, 10, &result)) {8664 if (@addWithOverflow(u8, byte, 10, &result)) {
8666 warn("overflowed result: {}\n", .{result});8665 print("overflowed result: {}\n", .{result});
8667 } else {8666 } else {
8668 warn("result: {}\n", .{result});8667 print("result: {}\n", .{result});
8669 }8668 }
8670}8669}
8671 {#code_end#}8670 {#code_end#}
...@@ -8710,7 +8709,7 @@ const std = @import("std");...@@ -8710,7 +8709,7 @@ const std = @import("std");
8710pub fn main() void {8709pub fn main() void {
8711 var x: u8 = 0b01010101;8710 var x: u8 = 0b01010101;
8712 var y = @shlExact(x, 2);8711 var y = @shlExact(x, 2);
8713 std.debug.warn("value: {}\n", .{y});8712 std.debug.print("value: {}\n", .{y});
8714}8713}
8715 {#code_end#}8714 {#code_end#}
8716 {#header_close#}8715 {#header_close#}
...@@ -8728,7 +8727,7 @@ const std = @import("std");...@@ -8728,7 +8727,7 @@ const std = @import("std");
8728pub fn main() void {8727pub fn main() void {
8729 var x: u8 = 0b10101010;8728 var x: u8 = 0b10101010;
8730 var y = @shrExact(x, 2);8729 var y = @shrExact(x, 2);
8731 std.debug.warn("value: {}\n", .{y});8730 std.debug.print("value: {}\n", .{y});
8732}8731}
8733 {#code_end#}8732 {#code_end#}
8734 {#header_close#}8733 {#header_close#}
...@@ -8749,7 +8748,7 @@ pub fn main() void {...@@ -8749,7 +8748,7 @@ pub fn main() void {
8749 var a: u32 = 1;8748 var a: u32 = 1;
8750 var b: u32 = 0;8749 var b: u32 = 0;
8751 var c = a / b;8750 var c = a / b;
8752 std.debug.warn("value: {}\n", .{c});8751 std.debug.print("value: {}\n", .{c});
8753}8752}
8754 {#code_end#}8753 {#code_end#}
8755 {#header_close#}8754 {#header_close#}
...@@ -8770,7 +8769,7 @@ pub fn main() void {...@@ -8770,7 +8769,7 @@ pub fn main() void {
8770 var a: u32 = 10;8769 var a: u32 = 10;
8771 var b: u32 = 0;8770 var b: u32 = 0;
8772 var c = a % b;8771 var c = a % b;
8773 std.debug.warn("value: {}\n", .{c});8772 std.debug.print("value: {}\n", .{c});
8774}8773}
8775 {#code_end#}8774 {#code_end#}
8776 {#header_close#}8775 {#header_close#}
...@@ -8791,7 +8790,7 @@ pub fn main() void {...@@ -8791,7 +8790,7 @@ pub fn main() void {
8791 var a: u32 = 10;8790 var a: u32 = 10;
8792 var b: u32 = 3;8791 var b: u32 = 3;
8793 var c = @divExact(a, b);8792 var c = @divExact(a, b);
8794 std.debug.warn("value: {}\n", .{c});8793 std.debug.print("value: {}\n", .{c});
8795}8794}
8796 {#code_end#}8795 {#code_end#}
8797 {#header_close#}8796 {#header_close#}
...@@ -8810,20 +8809,20 @@ const std = @import("std");...@@ -8810,20 +8809,20 @@ const std = @import("std");
8810pub fn main() void {8809pub fn main() void {
8811 var optional_number: ?i32 = null;8810 var optional_number: ?i32 = null;
8812 var number = optional_number.?;8811 var number = optional_number.?;
8813 std.debug.warn("value: {}\n", .{number});8812 std.debug.print("value: {}\n", .{number});
8814}8813}
8815 {#code_end#}8814 {#code_end#}
8816 <p>One way to avoid this crash is to test for null instead of assuming non-null, with8815 <p>One way to avoid this crash is to test for null instead of assuming non-null, with
8817 the {#syntax#}if{#endsyntax#} expression:</p>8816 the {#syntax#}if{#endsyntax#} expression:</p>
8818 {#code_begin|exe|test#}8817 {#code_begin|exe|test#}
8819const warn = @import("std").debug.warn;8818const print = @import("std").debug.print;
8820pub fn main() void {8819pub fn main() void {
8821 const optional_number: ?i32 = null;8820 const optional_number: ?i32 = null;
88228821
8823 if (optional_number) |number| {8822 if (optional_number) |number| {
8824 warn("got number: {}\n", .{number});8823 print("got number: {}\n", .{number});
8825 } else {8824 } else {
8826 warn("it's null\n", .{});8825 print("it's null\n", .{});
8827 }8826 }
8828}8827}
8829 {#code_end#}8828 {#code_end#}
...@@ -8846,7 +8845,7 @@ const std = @import("std");...@@ -8846,7 +8845,7 @@ const std = @import("std");
88468845
8847pub fn main() void {8846pub fn main() void {
8848 const number = getNumberOrFail() catch unreachable;8847 const number = getNumberOrFail() catch unreachable;
8849 std.debug.warn("value: {}\n", .{number});8848 std.debug.print("value: {}\n", .{number});
8850}8849}
88518850
8852fn getNumberOrFail() !i32 {8851fn getNumberOrFail() !i32 {
...@@ -8856,15 +8855,15 @@ fn getNumberOrFail() !i32 {...@@ -8856,15 +8855,15 @@ fn getNumberOrFail() !i32 {
8856 <p>One way to avoid this crash is to test for an error instead of assuming a successful result, with8855 <p>One way to avoid this crash is to test for an error instead of assuming a successful result, with
8857 the {#syntax#}if{#endsyntax#} expression:</p>8856 the {#syntax#}if{#endsyntax#} expression:</p>
8858 {#code_begin|exe#}8857 {#code_begin|exe#}
8859const warn = @import("std").debug.warn;8858const print = @import("std").debug.print;
88608859
8861pub fn main() void {8860pub fn main() void {
8862 const result = getNumberOrFail();8861 const result = getNumberOrFail();
88638862
8864 if (result) |number| {8863 if (result) |number| {
8865 warn("got number: {}\n", .{number});8864 print("got number: {}\n", .{number});
8866 } else |err| {8865 } else |err| {
8867 warn("got error: {}\n", .{@errorName(err)});8866 print("got error: {}\n", .{@errorName(err)});
8868 }8867 }
8869}8868}
88708869
...@@ -8891,7 +8890,7 @@ pub fn main() void {...@@ -8891,7 +8890,7 @@ pub fn main() void {
8891 var err = error.AnError;8890 var err = error.AnError;
8892 var number = @errorToInt(err) + 500;8891 var number = @errorToInt(err) + 500;
8893 var invalid_err = @intToError(number);8892 var invalid_err = @intToError(number);
8894 std.debug.warn("value: {}\n", .{number});8893 std.debug.print("value: {}\n", .{number});
8895}8894}
8896 {#code_end#}8895 {#code_end#}
8897 {#header_close#}8896 {#header_close#}
...@@ -8921,7 +8920,7 @@ const Foo = enum {...@@ -8921,7 +8920,7 @@ const Foo = enum {
8921pub fn main() void {8920pub fn main() void {
8922 var a: u2 = 3;8921 var a: u2 = 3;
8923 var b = @intToEnum(Foo, a);8922 var b = @intToEnum(Foo, a);
8924 std.debug.warn("value: {}\n", .{@tagName(b)});8923 std.debug.print("value: {}\n", .{@tagName(b)});
8925}8924}
8926 {#code_end#}8925 {#code_end#}
8927 {#header_close#}8926 {#header_close#}
...@@ -8958,7 +8957,7 @@ pub fn main() void {...@@ -8958,7 +8957,7 @@ pub fn main() void {
8958}8957}
8959fn foo(set1: Set1) void {8958fn foo(set1: Set1) void {
8960 const x = @errSetCast(Set2, set1);8959 const x = @errSetCast(Set2, set1);
8961 std.debug.warn("value: {}\n", .{x});8960 std.debug.print("value: {}\n", .{x});
8962}8961}
8963 {#code_end#}8962 {#code_end#}
8964 {#header_close#}8963 {#header_close#}
...@@ -9015,7 +9014,7 @@ pub fn main() void {...@@ -9015,7 +9014,7 @@ pub fn main() void {
90159014
9016fn bar(f: *Foo) void {9015fn bar(f: *Foo) void {
9017 f.float = 12.34;9016 f.float = 12.34;
9018 std.debug.warn("value: {}\n", .{f.float});9017 std.debug.print("value: {}\n", .{f.float});
9019}9018}
9020 {#code_end#}9019 {#code_end#}
9021 <p>9020 <p>
...@@ -9039,7 +9038,7 @@ pub fn main() void {...@@ -9039,7 +9038,7 @@ pub fn main() void {
90399038
9040fn bar(f: *Foo) void {9039fn bar(f: *Foo) void {
9041 f.* = Foo{ .float = 12.34 };9040 f.* = Foo{ .float = 12.34 };
9042 std.debug.warn("value: {}\n", .{f.float});9041 std.debug.print("value: {}\n", .{f.float});
9043}9042}
9044 {#code_end#}9043 {#code_end#}
9045 <p>9044 <p>
...@@ -9058,7 +9057,7 @@ pub fn main() void {...@@ -9058,7 +9057,7 @@ pub fn main() void {
9058 var f = Foo{ .int = 42 };9057 var f = Foo{ .int = 42 };
9059 f = Foo{ .float = undefined };9058 f = Foo{ .float = undefined };
9060 bar(&f);9059 bar(&f);
9061 std.debug.warn("value: {}\n", .{f.float});9060 std.debug.print("value: {}\n", .{f.float});
9062}9061}
90639062
9064fn bar(f: *Foo) void {9063fn bar(f: *Foo) void {
...@@ -9178,7 +9177,7 @@ pub fn main() !void {...@@ -9178,7 +9177,7 @@ pub fn main() !void {
9178 const allocator = &arena.allocator;9177 const allocator = &arena.allocator;
91799178
9180 const ptr = try allocator.create(i32);9179 const ptr = try allocator.create(i32);
9181 std.debug.warn("ptr={*}\n", .{ptr});9180 std.debug.print("ptr={*}\n", .{ptr});
9182}9181}
9183 {#code_end#}9182 {#code_end#}
9184 When using this kind of allocator, there is no need to free anything manually. Everything9183 When using this kind of allocator, there is no need to free anything manually. Everything
...@@ -9712,7 +9711,7 @@ pub fn main() !void {...@@ -9712,7 +9711,7 @@ pub fn main() !void {
9712 defer std.process.argsFree(std.heap.page_allocator, args);9711 defer std.process.argsFree(std.heap.page_allocator, args);
97139712
9714 for (args) |arg, i| {9713 for (args) |arg, i| {
9715 std.debug.warn("{}: {}\n", .{i, arg});9714 std.debug.print("{}: {}\n", .{i, arg});
9716 }9715 }
9717}9716}
9718 {#code_end#}9717 {#code_end#}
...@@ -9734,7 +9733,7 @@ pub fn main() !void {...@@ -9734,7 +9733,7 @@ pub fn main() !void {
9734 try preopens.populate();9733 try preopens.populate();
97359734
9736 for (preopens.asSlice()) |preopen, i| {9735 for (preopens.asSlice()) |preopen, i| {
9737 std.debug.warn("{}: {}\n", .{ i, preopen });9736 std.debug.print("{}: {}\n", .{ i, preopen });
9738 }9737 }
9739}9738}
9740 {#code_end#}9739 {#code_end#}