@@ -11,26 +11,23 @@ Here's everyone's favorite whiteboard example, FizzBuzz. Each
1111line is commented with its number:
1212
1313```
14−:gate end/atom :: 1
15−:var count 1 :: 2
16−:loop :: 3
17−:cast (list tape) :: 4
18−:if =(end count) :: 5
19− ~ :: 6
20−:cons :: 7
21− :if =(0 (mod count 15)) :: 8
22− "FizzBuzz" :: 9
23− :if =(0 (mod count 5)) :: 10
24− "Fizz" :: 11
25− :if =(0 (mod count 3)) :: 12
26− "Buzz" :: 13
27− (pave :wrap(count)) :: 14
28−:moar(count (add 1 count)) :: 15
14+|= end/atom :: 1
15+=/ count 1 :: 2
16+|- :: 3
17+^- (list tape) :: 4
18+?: =(end count) :: 5
19+ ~ :: 6
20+:- :: 7
21+ ?: =(0 (mod count 15)) :: 8
22+ "FizzBuzz" :: 9
23+ ?: =(0 (mod count 5)) :: 10
24+ "Fizz" :: 11
25+ ?: =(0 (mod count 3)) :: 12
26+ "Buzz" :: 13
27+ (pave !>(count)) :: 14
28+$(count (add 1 count)) :: 15
2929```
3030
31−Can you understand this code by just looking at it? Maybe.
32−But let's explain it anyway.
33−
3431Hoon is a functional language. FizzBuzz is usually defined as a
3532side effect, but officially Hoon has no side effects. This code
3633will *return* a list of strings, not *print* a list of strings.
@@ -41,8 +38,10 @@ The code produces a list in which each item is either a number
4138(as a string), "Fizz", "Buzz", or "Fizzbuzz". The value `~` is
4239"null" and indicates the end of the list.
4340
44−Line 1 defines a function of one argument, `end`, an unsigned
45−integer.
41+Line 1 uses the `|=`
42+*[rune](https://urbit.org/docs/about/glossary#rune)* to define a
43+function of one argument, `end`, which is of the type `atom` (i.e.
44+an unsigned integer).
4645
4746Line 2 declares a variable, `count`, with initial value `1`.
4847
@@ -50,24 +49,27 @@ Line 3 begins a loop.
5049
5150Line 4 defines the product of the loop as a list of `tape`s.
5251(A `tape` is a list of characters, one of Hoon's two string
53−types.)
52+types.) The `^-` rune is used for defining the product type the function
53+is to return.
5454
55−Line 5 checks if `count` equals `end`. If so, line 6 (and the
56−whole loop) returns the value `~`. If not, line 7 produces an
57−ordered pair. (This pair will be: (a) the next item in the list,
58−and (b) the rest of the list.)
55+Line 5 uses the `?:` rune, which is a conditional. This line
56+checks whether `count` equals `end`. If so, line 6 (and the
57+whole loop) returns the value `~`. The list is finished. If not,
58+line 7 produces an ordered pair. This pair will be: (a) the next
59+item in the list, determined by lines 8-14; and (b) the rest of
60+the list, determined by line 15.
5961
6062(a) The head of the pair is: (i) "FizzBuzz", or "Fizz", or
6163"Buzz", if the respective tests hit; otherwise, it's
6264(ii) the number in question, `count`. In case (ii), line 14
63−makes `count` into a `tape`, first by using `:wrap` to produce a
65+makes `count` into a `tape`, first by using `!>` to produce a
6466pair: runtime type of `count`, and `count` itself. `pave` is a
6567Hoon function that converts the type-value pair to a `tape`
6668(like C `sprintf()`).
6769
6870(b) The tail of the pair—the rest of the output list—is
69−produced at line 15, which repeats the loop (like Clojure
70−`recur`), with `count` incremented.
71+produced at line 15, which uses `$()` to repeat the loop (like
72+Clojure `recur`), with `count` incremented.
7173
7274You can test this code by mounting your home desk with
7375`|mount %` from the dojo; saving the above code as