on master help sign in
adds docs for new gates ++find and ++fand
commit96d6fea24765bad1fea2b1eadcccc66002591149 authorJoseph Bryan <joemfb@gmail.com> dateThu 7 Jul 2016, 12:50 (10 years ago) parent377b81b
1 file changed+107
docs/hoon/library/2b.md+107
docs/hoon/library/2b.md+107
@@ -128,6 +128,113 @@ Examples
128128
129129
130130
131+***
132+### `++find`
133+
134+First index in list
135+
136+Produces the index of the first occurrence of `++list` `nedl` in
137+`++list` `hstk` as the `++unit` of an atom.
138+
139+Accepts
140+-------
141+
142+`nedl` is a list.
143+
144+`hstk` is a list.
145+
146+Produces
147+--------
148+
149+The `++unit` of an atom.
150+
151+Source
152+------
153+
154+ ++ find :: first index
155+ ~/ %find
156+ |= {nedl/(list) hstk/(list)}
157+ =| i/@ud
158+ |- ^- (unit @ud)
159+ =+ [n=nedl h=hstk]
160+ |-
161+ ?: |(?=($~ n) ?=($~ h))
162+ ~
163+ ?: =(i.n i.h)
164+ ?~ t.n
165+ `i
166+ $(n t.n, h t.h)
167+ ^$(i +(i), hstk +.hstk)
168+
169+
170+Examples
171+--------
172+
173+ > (find [3]~ ~[1 2 3])
174+ [~ 2]
175+ > (find [4]~ ~[1 2 3])
176+ ~
177+ > (find ['a']~ "cbabab")
178+ [~ 2]
179+ > (find "ab" "cbabab")
180+ [~ 2]
181+
182+
183+
184+***
185+### `++fand`
186+
187+All indices in list
188+
189+Produces the indices of all occurrences of `++list` `nedl` in
190+`++list` `hstk` as a `++list` of atoms.
191+
192+Accepts
193+-------
194+
195+`nedl` is a list.
196+
197+`hstk` is a list.
198+
199+Produces
200+--------
201+
202+A `++list` of atoms.
203+
204+Source
205+------
206+
207+ ++ fand :: all indices
208+ ~/ %fand
209+ |= {nedl/(list) hstk/(list)}
210+ =| i/@ud
211+ =| fnd/(list @ud)
212+ |- ^+ fnd
213+ =+ [n=nedl h=hstk]
214+ |-
215+ ?: |(?=($~ n) ?=($~ h))
216+ (flop fnd)
217+ ?: =(i.n i.h)
218+ ?~ t.n
219+ ^$(i +(i), hstk +.hstk, fnd [i fnd])
220+ $(n t.n, h t.h)
221+ ^$(i +(i), hstk +.hstk)
222+
223+
224+Examples
225+--------
226+
227+ > (fand [3]~ ~[1 2 3])
228+ ~[2]
229+ > (fand [4]~ ~[1 2 3])
230+ ~
231+ > (fand ['a']~ "cbabab")
232+ ~[2 4]
233+ > (fand "ab" "cbabab")
234+ ~[2 4]
235+
236+
237+
131238***
132239### `++levy`
133240