Merge branch 'main' into test-expect

This commit is contained in:
Chris Boesch
2025-08-24 14:59:26 +02:00
18 changed files with 54 additions and 171 deletions

View File

@@ -3,7 +3,7 @@
// example that takes two parameters. As you can see, parameters
// are declared just like any other types ("name": "type"):
//
// fn myFunction(number: u8, is_lucky: bool) {
// fn myFunction(number: u8, is_lucky: bool) void {
// ...
// }
//

View File

@@ -16,12 +16,12 @@ const std = @import("std");
//
pub fn main() !void {
// We get a Writer for Standard Out so we can print() to it.
const stdout = std.io.getStdOut().writer();
var stdout = std.fs.File.stdout().writer(&.{});
// 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.print("Hello world!\n", .{});
stdout.interface.print("Hello world!\n", .{});
}

View File

@@ -10,11 +10,11 @@ const std = @import("std");
const NumError = error{IllegalNumber};
pub fn main() void {
const stdout = std.io.getStdOut().writer();
var stdout = std.fs.File.stdout().writer(&.{});
const my_num: u32 = getNumber();
try stdout.print("my_num={}\n", .{my_num});
try stdout.interface.print("my_num={}\n", .{my_num});
}
// This function is obviously weird and non-functional. But you will not be changing it for this quiz.

View File

@@ -32,7 +32,7 @@ const print = std.debug.print;
pub fn main() !void {
// let's check the pangram
print("Is this a pangram? {?}!\n", .{isPangram("The quick brown fox jumps over the lazy dog.")});
print("Is this a pangram? {}!\n", .{isPangram("The quick brown fox jumps over the lazy dog.")});
}
fn isPangram(str: []const u8) bool {
@@ -45,7 +45,7 @@ fn isPangram(str: []const u8) bool {
// loop about all characters in the string
for (str) |c| {
// if the character is an alphabetical character
if (ascii.isASCII(c) and ascii.isAlphabetic(c)) {
if (ascii.isAscii(c) and ascii.isAlphabetic(c)) {
// then we set the bit at the position
//
// to do this, we use a little trick:

View File

@@ -106,7 +106,7 @@ pub fn main() !void {
// After the threads have been started,
// they run in parallel and we can still do some work in between.
std.time.sleep(1500 * std.time.ns_per_ms);
std.Thread.sleep(1500 * std.time.ns_per_ms);
std.debug.print("Some weird stuff, after starting the threads.\n", .{});
}
// After we have left the closed area, we wait until
@@ -117,12 +117,12 @@ pub fn main() !void {
// This function is started with every thread that we set up.
// In our example, we pass the number of the thread as a parameter.
fn thread_function(num: usize) !void {
std.time.sleep(200 * num * std.time.ns_per_ms);
std.Thread.sleep(200 * num * std.time.ns_per_ms);
std.debug.print("thread {d}: {s}\n", .{ num, "started." });
// This timer simulates the work of the thread.
const work_time = 3 * ((5 - num % 3) - 2);
std.time.sleep(work_time * std.time.ns_per_s);
std.Thread.sleep(work_time * std.time.ns_per_s);
std.debug.print("thread {d}: {s}\n", .{ num, "finished." });
}