11Now we're going to cover the boiler plate that we skimmed over earlier.
15 =< (sum [1.000 2.000])
17The first rune, `:-` (colhep, aka
18[:cons](../../hoon/twig/col-cell/hep-cons/)), constructs the 2-element cell
19that will be our program. The first element, `%say`, tells the
20interpreter what to produce--in this case a value.
22The second element is `|=`, which we know produces a function. `|=`'s
23first child is its argument(s), which in this case is any noun (`*`).
24Its second child is the remainder of the program.
26Similarly, the rest of the program (which we construct with another
27`:-`) is a cell of the literal `%noun`, which tells the shell that we're
28producing a value of type `noun`, and the code that we run to actually
29produce our value of the type `noun`.
31`=<` ([tisgal](../../hoon/twig/tis-flow/gal-rap/)) is a rune that takes two
32children. The second child is the context against which we run the first
33child. So in this case, we are running the expression
34`(sum [1.000 2.000])` against everything contained within the `|%`. In
35Hoon, we call the code executed the "formula" and its context the
38 ::::::::::::::::::::::::::::::
39 =< (sum [1.000 2.000]) :: formula
40 ::::::::::::::::::::::::::::::
48 (add b $(b (add 3 b))) ::
58 (add b $(b (add b 5))) ::
62 (add (five a) (three b)) ::
64 ::::::::::::::::::::::::::::::
66In nearly every language there is a similar concept of a "context" in
67which expressions are executed. For example, in C this includes things
68like the call stack, stack variables, and so on.
70Hoon is unique in that this context is a first-class value. Scheme
71allows a sort of reification of the context through continuations, and
72some may see a parallel to Forth's stack, but Hoon takes the
73concept one step further.
75Our starting subject is the [standard library](../../hoon/library), which is
76defined in `/arvo/hoon.hoon` and `/arvo/zuse.hoon`. This is where
77functions like `add` are defined. When we define a core with `|%`, we
78don't throw away the subject (i.e. the standard library); rather, we
79stack the new core on top of the old subject so that both are
84- Pass `++sum` its arguments (`2.000` and `3.000`) from the
87- Comment out all of the arms of the `|%`. Now add another arm and
88 call it `++add`, have it accept two arguments and procduce 42
89 (regardless of input). Change the `=<` line to
90 `[(add 5 7) (^add 5 7)]`. Can you recognize what's happening?
94- To pass arguments from the command line to a program, you replace
95 the `*` in the first line of the boiler plate to
96 `{^ {{arg/TYPE $~} $~}}` where `TYPE` is replaced with the type of
97 argument you're expecting. Then `+euler1 a` from the dojo sets `arg`
99- The empty list is `~`
100- Lisp-style cons (construct a cell/prepend an element) is
102- For example, the first three positive integers are `[1 2 3 ~]`
103- `(gte a b)` tests whether `a` is greater than or equal to `b`.
104- `(mod a b)` runs the modulo operation on two atoms.
105- See the basic math section in `/arvo/hoon.hoon` 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