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