From dc1dcf13287f174554d645421d783ee574295c82 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Mon, 6 Sep 2021 12:06:07 -0700 Subject: [PATCH] Fix some typos, reword enum bit again --- chapter-1.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chapter-1.md b/chapter-1.md index 06d97d4..5524a36 100644 --- a/chapter-1.md +++ b/chapter-1.md @@ -590,7 +590,7 @@ test "set enum ordinal value" { } ``` -Functions can be given to enums. These are sometimes called "methods", and act as namespaced functions that can be called with dot syntax. As a convenience, when called from an instance of the enum these methods are automatically passed that instance as their first argument. Notice below that `Suit.spades.isClubs()` is equivalent to `Suit.isClubs(Suit.spades)`. Additionally, since we're calling the method from the enum, we don't have to specify the enum again, and can shorten the argument to just `.spades`. +Functions can be given to enums. These are sometimes called "methods", and act as namespaced functions that can be called with dot syntax. As a convenience, when called from an instance of the enum these methods are automatically passed that instance as their first argument. Thus, `Suit.spades.isClubs()` is equivalent to `Suit.isClubs(Suit.spades)`. Additionally, when calling a method from the enum, we can shorten the argument to omit the enum name and pass it with just a leading dot, as in the example below. ```zig const Suit = enum { @@ -674,7 +674,7 @@ test "struct defaults" { Like enums, structs may also contain functions and declarations. -Similar to enums, methods called from a struct instance will be passed a _pointer to_ that instance. In addition, structs an additional unique property: when accessing fields from a pointer to a struct, one level of dereferencing is done automatically. Notice how these work together in the example below: the swap() function is automatically passed a pointer to `thing`, and then accesses self.x and self.y using that pointer without needing to dereference it. +Similar to enums, methods called from a struct instance will be passed a *pointer to* that instance. Structs also have an additional unique property: when accessing fields from a pointer to a struct, one level of dereferencing is done automatically. Notice how these work together in the example below: the swap() function is automatically passed a pointer to `thing`, and then accesses self.x and self.y using that pointer without needing to dereference it. ```zig const Stuff = struct {