diff options
| author | Chris Boesch <chrboesch@noreply.codeberg.org> | 2026-06-21 16:48:15 +0200 |
|---|---|---|
| committer | Chris Boesch <chrboesch@noreply.codeberg.org> | 2026-06-21 16:48:15 +0200 |
| commit | 151450cc7ddc188ec69d066bdc5f4a85c4210fbe (patch) | |
| tree | eb0e8ab53bfd9b8d65d24337c4193a48b88823c3 /exercises | |
| parent | 894ebf1a37044cce86a229f48de87133d0859cab (diff) | |
| parent | cbcb570248a5297a0644fc22357bf81aac54545a (diff) | |
Merge pull request 'minor fixes' (#470) from minor-fixes into main
Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/470
Diffstat (limited to 'exercises')
| -rw-r--r-- | exercises/047_methods.zig | 18 | ||||
| -rw-r--r-- | exercises/108_threading2.zig | 2 | ||||
| -rw-r--r-- | exercises/115_packed2.zig | 2 |
3 files changed, 20 insertions, 2 deletions
diff --git a/exercises/047_methods.zig b/exercises/047_methods.zig index 3221ca2..3e88719 100644 --- a/exercises/047_methods.zig +++ b/exercises/047_methods.zig @@ -37,6 +37,24 @@ // self, others use a lowercase version of the type name, but feel // free to use whatever is most appropriate. // +// "But hold on," you say, eyeing a() and b() suspiciously, "why +// does one take 'self' and another take '*self'?" Sharp eye! +// +// It all comes down to a single question: does the function need +// to CHANGE the struct? +// +// * Needs to change it? Take a pointer (*Bar). Without it you'd +// be scribbling on a COPY, and your changes would evaporate the +// instant the function returns. Poof. +// * Only reads it? Plain Bar is just fine. +// (For a big, bulky struct you might still write *const Bar to +// avoid copying it around, but for small ones a copy is cheap.) +// +// You'll see this below: zap() takes 'self: HeatRay' by value +// because it only reads the ray's damage, but it takes the alien +// as '*Alien' because zapping is supposed to HURT - and that means +// changing the alien's health for real, not on a throwaway copy. +// // Okay, you're armed. // // Now, please zap the alien structs until they're all gone or diff --git a/exercises/108_threading2.zig b/exercises/108_threading2.zig index bbf8d78..e1b35ac 100644 --- a/exercises/108_threading2.zig +++ b/exercises/108_threading2.zig @@ -46,7 +46,7 @@ // 1,000,000,000 partial values. And for each additional digit we have to // add a zero. // Even fast computers - and I mean really fast computers - get a bit warmer -// on the CPU when it comes to really many digits. But the 8 digits are +// on the CPU when it comes to a large number of digits. But 8 digits are // enough for us for now, because we want to understand the principle and // nothing more, right? // diff --git a/exercises/115_packed2.zig b/exercises/115_packed2.zig index db5190a..2a772d7 100644 --- a/exercises/115_packed2.zig +++ b/exercises/115_packed2.zig @@ -51,7 +51,7 @@ comptime { // // Try to make the float below negative: -/// IEEE 754 half precision float +// IEEE 754 binary16 floating-point format const Float = packed union(u16) { value: f16, bits: packed struct(u16) { |
