on master help sign in
Merge pull request #260 from joshuareagan/patch-7

corrected sieve example

commit5cfcc3d113d151e5c687ceb5f1b71417c8e96a62 authorKeaton Dunsford <keaton.dunsford@gmail.com> dateThu 10 May 2018, 10:44 (8 years ago) parenta0974e74016255
1 file changed+19−20
docs/hoon/examples.md+19−20
docs/hoon/examples.md+19−20
@@ -20,24 +20,24 @@ A function that produces the list of primes less than or equal to
2020its argument, an atom:
2121
2222```
23−|= thru/@ :: 1
23+|= thru=@ :: 1
2424^- (list @) :: 2
25−=/ field/(set @) (silt (gulf 2 thru)) :: 3
25+=/ field=(set @) (sy (gulf 2 thru)) :: 3
2626=< abet:main :: 4
2727|% :: 5
2828++ abet :: 6
29− (sort (~(tap in field) ~) lth) :: 7
29+ (sort ~(tap in field) lth) :: 7
3030:: :: 8
3131++ main :: 9
32− =/ factor/@ 2 :: 10
32+ =/ factor=@ 2 :: 10
3333 |- ^+ ..main :: 11
3434 ?: (gth (mul factor factor) thru) :: 12
3535 ..main :: 13
3636 $(factor +(factor), ..main (reap factor)) :: 14
3737:: :: 15
3838++ reap :: 16
39− |= factor/@ :: 17
40− =/ count/@ (mul 2 factor) :: 18
39+ |= factor=@ :: 17
40+ =/ count=@ (mul 2 factor) :: 18
4141 |- ^+ ..reap :: 19
4242 ?: (gth count thru) :: 20
4343 ..reap :: 21
@@ -51,9 +51,9 @@ its argument, an atom:
5151## `sieve`: explanation
5252
5353```
54−|= thru/@ :: 1
54+|= thru=@ :: 1
5555^- (list @) :: 2
56−=/ field/(set @) (silt (gulf 2 thru)) :: 3
56+=/ field=(set @) (sy (gulf 2 thru)) :: 3
5757```
5858
5959Line `1`: we are building a gate (function) whose sample
@@ -62,7 +62,7 @@ Line `1`: we are building a gate (function) whose sample
6262Line `2`: the product of this gate is a list of atoms.
6363
6464Line `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`
6666function creates the range `2` through `thru` inclusive, as a
6767list of atoms.
6868
@@ -76,7 +76,7 @@ with the computation completed. `abet` then extracts the result.
7676```
7777|% :: 5
7878++ abet :: 6
79− (sort (~(tap in field) ~) lth) :: 7
79+ (sort ~(tap in field) lth) :: 7
8080```
8181
8282Line `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
8484remain accessible.
8585
8686Lines `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
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).
87+sorted list. `in` is the set core; `tap` is an arm that exports
88+the set as a list. We sort this list in ascending order with
89+`lth` (less-than).
9190
9291```
9392++ main :: 9
94− =/ factor/@ 2 :: 10
93+ =/ factor=@ 2 :: 10
9594 |- ^+ ..main :: 11
9695```
9796
@@ -117,8 +116,8 @@ replacing the core with a version sieved by `reap`.
117116
118117```
119118++ reap :: 16
120− |= factor/@ :: 17
121− =/ count/@ (mul 2 factor) :: 18
119+ |= factor=@ :: 17
120+ =/ count=@ (mul 2 factor) :: 18
122121```
123122
124123Lines `16` and `17`: the `reap` arm, which produces a gate that
@@ -150,9 +149,9 @@ multiple of `factor`, and deleting it from `field`.
150149
151150Finally, the same code in a more concise "kernel" style.
152151```
153−|= top/@
152+|= top=@
154153^- (list @)
155−=+ fed=(silt (gulf 2 top))
154+=+ fed=(sy (gulf 2 top))
156155=< abet:main
157156|%
158157++ abet (sort (~(tap in fed)) lth)
@@ -164,7 +163,7 @@ Finally, the same code in a more concise "kernel" style.
164163 $(fac +(fac), ..main (reap fac))
165164::
166165++ reap
167− |= fac/@
166+ |= fac=@
168167 =+ cot=(mul 2 fac)
169168 |- ^+ ..reap
170169 ?: (gth cot top)