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