on master help sign in
Merge pull request #260 from joshuareagan/patch-7
5cfcc3dKeaton Dunsford
docs/hoon/examples.md+19−20
@@ -20,24 +20,24 @@ A function that produces the list of primes less than or equal to
20its argument, an atom:
20its argument, an atom:
21
21
22```
22```
23−|= thru/@ :: 1
23+|= thru=@ :: 1
24^- (list @) :: 2
24^- (list @) :: 2
25−=/ field/(set @) (silt (gulf 2 thru)) :: 3
25+=/ field=(set @) (sy (gulf 2 thru)) :: 3
26=< abet:main :: 4
26=< abet:main :: 4
27|% :: 5
27|% :: 5
28++ abet :: 6
28++ abet :: 6
29− (sort (~(tap in field) ~) lth) :: 7
29+ (sort ~(tap in field) lth) :: 7
30:: :: 8
30:: :: 8
31++ main :: 9
31++ main :: 9
32− =/ factor/@ 2 :: 10
32+ =/ factor=@ 2 :: 10
33 |- ^+ ..main :: 11
33 |- ^+ ..main :: 11
34 ?: (gth (mul factor factor) thru) :: 12
34 ?: (gth (mul factor factor) thru) :: 12
35 ..main :: 13
35 ..main :: 13
36 $(factor +(factor), ..main (reap factor)) :: 14
36 $(factor +(factor), ..main (reap factor)) :: 14
37:: :: 15
37:: :: 15
38++ reap :: 16
38++ reap :: 16
39− |= factor/@ :: 17
39+ |= factor=@ :: 17
40− =/ count/@ (mul 2 factor) :: 18
40+ =/ count=@ (mul 2 factor) :: 18
41 |- ^+ ..reap :: 19
41 |- ^+ ..reap :: 19
42 ?: (gth count thru) :: 20
42 ?: (gth count thru) :: 20
43 ..reap :: 21
43 ..reap :: 21
@@ -51,9 +51,9 @@ its argument, an atom:
51## `sieve`: explanation
51## `sieve`: explanation
52
52
53```
53```
54−|= thru/@ :: 1
54+|= thru=@ :: 1
55^- (list @) :: 2
55^- (list @) :: 2
56−=/ field/(set @) (silt (gulf 2 thru)) :: 3
56+=/ field=(set @) (sy (gulf 2 thru)) :: 3
57```
57```
58
58
59Line `1`: we are building a gate (function) whose sample
59Line `1`: we are building a gate (function) whose sample
@@ -62,7 +62,7 @@ Line `1`: we are building a gate (function) whose sample
62Line `2`: the product of this gate is a list of atoms.
62Line `2`: the product of this gate is a list of atoms.
63
63
64Line `3`: we introduce a variable `field`, whose type is a set of
64Line `3`: we introduce a variable `field`, whose type is a set of
65−atoms. The `silt` function converts a list to a set. The `gulf`
65+atoms. The `sy` function converts a list to a set. The `gulf`
66function creates the range `2` through `thru` inclusive, as a
66function creates the range `2` through `thru` inclusive, as a
67list of atoms.
67list of atoms.
68
68
@@ -76,7 +76,7 @@ with the computation completed. `abet` then extracts the result.
76```
76```
77|% :: 5
77|% :: 5
78++ abet :: 6
78++ abet :: 6
79− (sort (~(tap in field) ~) lth) :: 7
79+ (sort ~(tap in field) lth) :: 7
80```
80```
81
81
82Line `5`: we wrap a core around our existing subject. The
82Line `5`: we wrap a core around our existing subject. The
@@ -84,14 +84,13 @@ Line `5`: we wrap a core around our existing subject. The
84remain accessible.
84remain accessible.
85
85
86Lines `6` and `7`: the `abet` arm, which produces the field as a
86Lines `6` and `7`: the `abet` arm, which produces the field as a
87−sorted list. `in` is the set core; `tap` is an arm which
87+sorted list. `in` is the set core; `tap` is an arm that exports
88−produces a gate that exports the set as a list, prepending it to
89−a tail which is nil in this case (and most cases). We sort this
90−list in ascending order with `lth` (less-than).
88+the set as a list. We sort this list in ascending order with
89+`lth` (less-than).
91
90
92```
91```
93++ main :: 9
92++ main :: 9
94− =/ factor/@ 2 :: 10
93+ =/ factor=@ 2 :: 10
95 |- ^+ ..main :: 11
94 |- ^+ ..main :: 11
96```
95```
97
96
@@ -117,8 +116,8 @@ replacing the core with a version sieved by `reap`.
117
116
118```
117```
119++ reap :: 16
118++ reap :: 16
120− |= factor/@ :: 17
119+ |= factor=@ :: 17
121− =/ count/@ (mul 2 factor) :: 18
120+ =/ count=@ (mul 2 factor) :: 18
122```
121```
123
122
124Lines `16` and `17`: the `reap` arm, which produces a gate that
123Lines `16` and `17`: the `reap` arm, which produces a gate that
@@ -150,9 +149,9 @@ multiple of `factor`, and deleting it from `field`.
150
149
151Finally, the same code in a more concise "kernel" style.
150Finally, the same code in a more concise "kernel" style.
152```
151```
153−|= top/@
152+|= top=@
154^- (list @)
153^- (list @)
155−=+ fed=(silt (gulf 2 top))
154+=+ fed=(sy (gulf 2 top))
156=< abet:main
155=< abet:main
157|%
156|%
158++ abet (sort (~(tap in fed)) lth)
157++ abet (sort (~(tap in fed)) lth)
@@ -164,7 +163,7 @@ Finally, the same code in a more concise "kernel" style.
164 $(fac +(fac), ..main (reap fac))
163 $(fac +(fac), ..main (reap fac))
165::
164::
166++ reap
165++ reap
167− |= fac/@
166+ |= fac=@
168 =+ cot=(mul 2 fac)
167 =+ cot=(mul 2 fac)
169 |- ^+ ..reap
168 |- ^+ ..reap
170 ?: (gth cot top)
169 ?: (gth cot top)