@@ -11,13 +11,11 @@ In this lesson, we will write a generator that takes an integer and checks if it
1111:- %say
1212|= [* [n=@ud ~] ~]
1313:- %noun
14−?: ?& =(0 (mod n 2))
15− ?& (gte n 1)
16− ?! (gth n 100)
17− ==
18− ==
19− %.y
20−%.n
14+^- ?
15+?& =(0 (mod n 2))
16+ (gte n 1)
17+ (lte n 1000)
18+==
2119```
2220
2321On the very first line, with `:- %say` we are beginning to create a generator of the `%say` variety. The result of a `%say` generator is a cell with a head of `%say` and tail that is a gate, itself producing a `cask`, a pair of a `mark` and some data. It's not important for understanding conditionals; this is just template code. For more information about `%say` generators, see the [Generators](@/docs/tutorials/hoon/generators.md) documentation.
@@ -34,13 +32,18 @@ The code above builds a gate. The gate's first argument is a cell provided by Do
3432
3533This code is the third line of the `%say` "boilerplate," and it produces a `cask` with the head of `%noun`. We could use any `mark` here, but `%noun` is the most generic type, able to fit any data.
3634
37−But now let's get into the conditionals themselves. Below we'll examine the series of `?` runes used.
35+```hoon
36+^- ?
37+```
38+This line casts the output as a `flag`, which is a type whose values are `%.y` and `%.n` representing "yes" and "no".
39+
40+Let's get into the conditionals themselves. Below we'll examine the series of `?` runes used.
3841
3942```hoon
40−?: ?& =(0 (mod n 2))
43+?& =(0 (mod n 2))
4144```
4245
43−`?:` (pronounced "wut-col") is the simplest "wut" rune. It takes three children, also called sub-expressions. The first child is a boolean test, which means that it looks for a `%.y` ("yes") or a `%.n` ("no."). The second child is a yes-branch, which is what we arrive at if the aforementioned boolean test evaluates to `%.y`. The third child is a no-branch, so we arrive at it if instead the boolean test evaluates to `%.n`. These branches can contain any sort of Hoon expression, including further conditional expressions, as we will see.
46+`?:` (pronounced "wut-pam") is the simplest "wut" rune. It takes three children, also called sub-expressions. The first child is a boolean test, which means that it looks for a `%.y` ("yes") or a `%.n` ("no."). The second child is a yes-branch, which is what we arrive at if the aforementioned boolean test evaluates to `%.y`. The third child is a no-branch, so we arrive at it if instead the boolean test evaluates to `%.n`. These branches can contain any sort of Hoon expression, including further conditional expressions, as we will see.
4447
4548In our case, the first child of `?:` is `?& =(0 (mod n 2))`. It itself has another conditional rune, `?&` ("wut-pam"), which performs the logical "and" operation on its two children, making sure that both of them are true. The first child of our `?&` rune is `=(0 (mod n 2))`, which simply asks if `n` is even or not.
4649