3Now we're going to cover the boiler plate that we skimmed over
10This program is a cell of two elements: the first, `%say`, tells
11the interpreter what to produce--in this case a value.
13The second element is `|=`, which we know produces a function.
14`|=`'s first child is its argument(s), which in this case is any
15noun (`*`). Its second child is the remainder of the program.
17Similarly, the rest of the program is a cell of the literal
18`%noun`, which tells the shell that we're producing a value of
19type `noun`, and the second child contains the code that we run
20to actually produce our value of the type `noun`.
22`=<` is a rune that takes two children. The second child is the
23context against which we run the first child. So in this case, we
24are running the expression `(sum 1.000)` against everything
25contained within the `|%`. In Hoon, we call the code executed the
26"formula" and its context the "subject".
29::::::::::::::::::::::::::::::
30=< (sum 1.000) :: formula
31::::::::::::::::::::::::::::::
39 (add b $(b (add 3 b))) ::
49 (add b $(b (add b 5))) ::
53 (add (five a) (three a)) ::
55::::::::::::::::::::::::::::::
58In nearly every language there is a similar concept of a
59"context" in which expressions are executed. For example, in C
60this includes things like the call stack, stack variables, and so
63Hoon is unique in that this context is a first-class value.
64Scheme allows a sort of reification of the context through
65continutations, and some may see a parallel to Forth's stack, but
66Hoon takes takes the concept one step further.
68Our starting subject is the standard library, which is defined in
69`/arvo/hoon.hoon` and `/arvo/zuse.hoon`. This is where functions
70like `add` are defined. When we define a core with `|%`, we
71don't throw away the subject (i.e. the standard library); rather,
72we stack the new core on top of the old subject so that both are
77- Pass `++sum` its arguments (`2000` and `3000`) from the
80- Comment out all of the arms of the `|%`. Now add another arm
81 and call it `++add`, have it accept two arguments and procduce
82 42 (regardless of input). Change the `=<` line to `[(add 5 7)
83 (^add 5 7)]`. Can you recognize what's happening?
87- To pass arguments from the command line to a program, you
88 replace the `*` in the first line of the boiler plate to
89 `[^ [[arg=TYPE ~] ~]]` where `TYPE` is replaced with the
90 type of argument you're expecting. Then `+euler1 a` from
91 the dojo sets `arg` to `a`.
92- The empty list is `~`
93- Lisp-style cons (construct a cell/prepend an element) is
95- For example, the first three positive integers are `[1 2 3
97- `gte` tests whether `a` is greater than or equal to `b`.
98- `mod` runs the modulo operation on two atoms.
99- See the [basic math section]() for more info.
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