Skip to content

Commit 5da9373

Browse files
authored
Merge pull request #170 from pedropark99/dev-epub
Add epub format configs
2 parents cf25243 + 54826dd commit 5da9373

File tree

29 files changed

+87
-89
lines changed

29 files changed

+87
-89
lines changed

Chapters/03-structs.qmd

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,22 @@ xsw: switch (@as(u8, 1)) {
301301

302302
### The `defer` keyword {#sec-defer}
303303

304-
With the `defer` keyword you can register an expression to be executed when you exit the current scope.
305-
Therefore, this keyword has a similar functionality as the `on.exit()` function from R.
306-
Take the `foo()` function below as an example. When we execute this `foo()` function, the expression
304+
Zig has a `defer` keyword, which plays a very important role in control flow, and also, in releasing resources.
305+
In summary, the `defer` keyword allows you to register an expression to be executed when you exit the current scope.
306+
307+
At this point, you might attempt to compare the Zig `defer` keyword to it's sibling in the Go language
308+
(i.e. [Go also has a `defer` keyword](https://go.dev/tour/flowcontrol/12)).
309+
However, the Go `defer` keyword behaves slightly different
310+
than it's sibling in Zig. More specifically, the `defer` keyword in Go always move an expression to be
311+
executed at the **exit of the current function**.
312+
313+
If you think deeply about this statement, you will notice that the "exit of the current function" is something
314+
slightly different than the "exit of the current scope". So, just be careful when comparing the two
315+
keywords together. A single function in Zig might contain many different scopes inside of it, and, therefore,
316+
the `defer` input expression might be executed at different places of the function, depending on which scope you
317+
are currently in.
318+
319+
As a first example, consider the `foo()` function exposed below. When we execute this `foo()` function, the expression
307320
that prints the message "Exiting function ..." is getting executed only when the function exits
308321
its scope.
309322

Chapters/05-pointers.qmd

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ might point to a null value. This is a common source of undefined behaviour in C
307307
When programmers work with pointers in C, they have to constantly check if
308308
their pointers are pointing to null values or not.
309309

310-
If for some reason, your Zig code produces a null value somewhere, and, this null
310+
In contrast, when working in Zig, if for some reason, your Zig code produces a null value somewhere, and, this null
311311
value ends up in an object that is non-nullable, a runtime error is always
312312
raised by your Zig program. Take the program below as an example.
313313
The `zig` compiler can see the `null` value at compile time, and, as result,
@@ -347,8 +347,9 @@ Ok, we know now that all objects are non-nullable by default in Zig.
347347
But what if we actually need to use an object that might receive a null value?
348348
Here is where optionals come in.
349349

350-
An optional object in Zig is an object that can be null.
351-
To mark an object as optional, we use the `?` operator. When you put
350+
An optional object in Zig is rather similar to a [`std::optional` object in C++](https://en.cppreference.com/w/cpp/utility/optional.html).
351+
It is an object that can either contain a value, or nothing at all (a.k.a. the object can be null).
352+
To mark an object in our Zig code as "optional", we use the `?` operator. When you put
352353
this `?` operator right before the data type of an object, you transform
353354
this data type into an optional data type, and the object becomes an optional object.
354355

_freeze/Chapters/01-base64/execute-results/html.json

Lines changed: 2 additions & 4 deletions
Large diffs are not rendered by default.

_freeze/Chapters/01-memory/execute-results/html.json

Lines changed: 2 additions & 4 deletions
Large diffs are not rendered by default.

_freeze/Chapters/01-zig-weird/execute-results/html.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

_freeze/Chapters/02-debugging/execute-results/html.json

Lines changed: 2 additions & 4 deletions
Large diffs are not rendered by default.

_freeze/Chapters/03-structs/execute-results/html.json

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

_freeze/Chapters/03-unittests/execute-results/html.json

Lines changed: 2 additions & 4 deletions
Large diffs are not rendered by default.

_freeze/Chapters/04-http-server/execute-results/html.json

Lines changed: 2 additions & 4 deletions
Large diffs are not rendered by default.

_freeze/Chapters/05-pointers/execute-results/html.json

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)