8Here's everyone's favorite whiteboard example, FizzBuzz. Each
9line is commented with its number:
18 :if =(0 (mod count 15)) :: 7
20 :if =(0 (mod count 5)) :: 9
22 :if =(0 (mod count 3)) :: 11
24 (text :wrap(count)) :: 13
25:moar(count (add 1 count)) :: 14
28Can you understand this code by just looking at it? Hopefully,
29but let's explain it anyway.
31Hoon is a functional language. FizzBuzz is usually defined as a
32side effect, but Hoon has no side effects. This code will
33*make* a list of strings, not *print* a list of strings.
35Line 1 defines a function of one argument, `end`, an unsigned
38Line 2 declares a variable, `count`, with initial value `1`.
42Line 4 checks if `count` equals `end`. If so, line 5 (and the
43whole loop) produces the value `~`, null. If not, line 6 begins
46The head of the pair is "FizzBuzz", or "Fizz", or "Buzz", if the
47respective tests hit. If not, line 13 wraps a runtime type
48around `count`, then prints the type-value pair to a string (like
49C `sprintf()`). This string is the first item in the output list.
51The tail of the pair is line 14, which repeats the loop (like
52Clojure `recur`), with `count` incremented. This list of strings
53is the rest of the output list.
55You can test this code by mounting your home desk with `|mount %home`;
56copying it into `home/gen/fizzbuzz.hoon` in your Urbit pier; then
57typing `+fizzbuzz 100` in the Urbit dojo (shell).
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list