From 21f86f07adf544850a7ef5f913c01117c04db147 Mon Sep 17 00:00:00 2001 From: Chris Boesch Date: Sat, 27 Dec 2025 23:44:12 +0100 Subject: migrated build and test --- exercises/026_hello2.zig | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'exercises/026_hello2.zig') diff --git a/exercises/026_hello2.zig b/exercises/026_hello2.zig index 582dba9..97ea918 100644 --- a/exercises/026_hello2.zig +++ b/exercises/026_hello2.zig @@ -15,8 +15,12 @@ const std = @import("std"); // https://ziglang.org/documentation/master/#Inferred-Error-Sets // pub fn main() !void { + // We need an io instance for I/O operations; + // we'll learn how to create them later. + const io = std.Options.debug_io; + // We get a Writer for Standard Out so we can print() to it. - var stdout = std.fs.File.stdout().writer(&.{}); + var stdout = std.Io.File.stdout().writer(io, &.{}); // Unlike std.debug.print(), the Standard Out writer can fail // with an error. We don't care _what_ the error is, we want -- cgit v1.2.3 From b33fd5a7448619ce37ff1fd78d0a4fba7661b6ff Mon Sep 17 00:00:00 2001 From: Chris Boesch Date: Sun, 28 Dec 2025 01:55:06 +0100 Subject: exc. 26 migrated --- exercises/026_hello2.zig | 14 +++++++------- patches/patches/026_hello2.patch | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'exercises/026_hello2.zig') diff --git a/exercises/026_hello2.zig b/exercises/026_hello2.zig index 97ea918..081c2b3 100644 --- a/exercises/026_hello2.zig +++ b/exercises/026_hello2.zig @@ -5,6 +5,9 @@ // const std = @import("std"); +// Instance for input/output, we'll learn how to create them later. +const io = std.Options.debug_io; + // Take note that this main() definition now returns "!void" rather // than just "void". Since there's no specific error type, this means // that Zig will infer the error type. This is appropriate in the case @@ -15,17 +18,14 @@ const std = @import("std"); // https://ziglang.org/documentation/master/#Inferred-Error-Sets // pub fn main() !void { - // We need an io instance for I/O operations; - // we'll learn how to create them later. - const io = std.Options.debug_io; - - // We get a Writer for Standard Out so we can print() to it. - var stdout = std.Io.File.stdout().writer(io, &.{}); + // We get a Writer interface for Standard Out so we can print() to it. + var stdout_writer = std.Io.File.stdout().writer(io, &.{}); + const stdout = &stdout_writer.interface; // Unlike std.debug.print(), the Standard Out writer can fail // with an error. We don't care _what_ the error is, we want // to be able to pass it up as a return value of main(). // // We just learned of a single statement which can accomplish this. - stdout.interface.print("Hello world!\n", .{}); + stdout.print("Hello world!\n", .{}); } diff --git a/patches/patches/026_hello2.patch b/patches/patches/026_hello2.patch index 7fde1d8..e35de35 100644 --- a/patches/patches/026_hello2.patch +++ b/patches/patches/026_hello2.patch @@ -1,9 +1,9 @@ ---- exercises/026_hello2.zig 2025-12-27 21:15:21.403899392 +0100 -+++ answers/026_hello2.zig 2025-12-27 20:28:53.267236800 +0100 +--- exercises/026_hello2.zig 2025-12-28 01:51:16.537444980 +0100 ++++ answers/026_hello2.zig 2025-12-28 01:51:10.280322328 +0100 @@ -27,5 +27,5 @@ // to be able to pass it up as a return value of main(). // // We just learned of a single statement which can accomplish this. -- stdout.interface.print("Hello world!\n", .{}); -+ try stdout.interface.print("Hello world!\n", .{}); +- stdout.print("Hello world!\n", .{}); ++ try stdout.print("Hello world!\n", .{}); } -- cgit v1.2.3 From 8e30debc6aa05a9313a085ba52b38d5c7224a7ea Mon Sep 17 00:00:00 2001 From: Chris Boesch Date: Sun, 28 Dec 2025 02:01:19 +0100 Subject: improved i/o explanation for exc. 26 --- exercises/026_hello2.zig | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'exercises/026_hello2.zig') diff --git a/exercises/026_hello2.zig b/exercises/026_hello2.zig index 081c2b3..7daa9e2 100644 --- a/exercises/026_hello2.zig +++ b/exercises/026_hello2.zig @@ -5,7 +5,7 @@ // const std = @import("std"); -// Instance for input/output, we'll learn how to create them later. +// Instance for input/output operations, we'll learn how to create them later. const io = std.Options.debug_io; // Take note that this main() definition now returns "!void" rather @@ -18,8 +18,9 @@ const io = std.Options.debug_io; // https://ziglang.org/documentation/master/#Inferred-Error-Sets // pub fn main() !void { - // We get a Writer interface for Standard Out so we can print() to it. + // We get a Writer for Standard Out... var stdout_writer = std.Io.File.stdout().writer(io, &.{}); + // ...and extract its interface so we can print() to it. const stdout = &stdout_writer.interface; // Unlike std.debug.print(), the Standard Out writer can fail -- cgit v1.2.3