Skip to content

Commit

Permalink
Fix some typos, reword enum bit again
Browse files Browse the repository at this point in the history
  • Loading branch information
cincodenada authored Sep 6, 2021
1 parent 62c670d commit dc1dcf1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions chapter-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit dc1dcf1

Please sign in to comment.