on master help sign in
Merge pull request #277 from urbit/rmariani-patch-11
90b7b90rmariani
docs/hoon/library/2q.md+194−104
@@ -6,23 +6,22 @@ navhome: /docs/
6# 2q: molds and mold builders
6# 2q: molds and mold builders
7### `++char`
7### `++char`
8
8
9−Char
9+Character
10
10
11−A single character. odor `@tD` designates a single unicode byte. All
11+A single character. Aura `@tD` designates a single UTF-8 byte. All parsers
12−parsers consume `++tape`s, which are lists of `++char`.
12+consume `tape`s, which are lists of `char`.
13
13
14
14
15−Source
15+#### Source
16−------
17
16
18− ++ char @tD :: UTF-8 byte
17+ ++ char @tD
19
18
20−Examples
19+#### Examples
21−--------
22
20
23 > *char
21 > *char
24 ''
22 ''
25− ~zod/try> (char 97)
23+
24+ > `@tD`97
26 'a'
25 'a'
27
26
28
27
@@ -32,123 +31,201 @@ Examples
32
31
33UTF-8 text
32UTF-8 text
34
33
35−One of Hoon's two string types (the other being `++tape`). A cord is an
34+One of Hoon's two string types (the other being `tape`). A cord is an
36−atom of UTF-8 text. `++trip` and `++crip` convert between cord and
35+atom of UTF-8 text.
37−`++tape`.
38
36
39−Source
37+#### Source
40−------
41
38
42− ++ cord @t :: text atom (UTF-8)
39+ ++ cord @t
43
40
44−Examples
41+#### Examples
45−--------
46
42
47−Odor `@t` designates a Unicode atom, little-endian: the first character
48−in the text is the low byte.
49
43
44+ > *cord
45+ ''
46+
50 > `@ux`'foobar'
47 > `@ux`'foobar'
51 0x7261.626f.6f66
48 0x7261.626f.6f66
52
49
50+ > `@t`97
51+ 'a'
52+
53 > `@`'urbit'
53 > `@`'urbit'
54 499.984.265.845
54 499.984.265.845
55+
55− > (cord 499.984.265.845)
56+ > `@t`499.984.265.845
56 'urbit'
57 'urbit'
57
58
58
59
60+#### Discussion
61+
62+Aura `@t` designates a Unicode atom, little-endian: the first character
63+in the text is the least-significant byte.
64+
65+[`trip`](../4b) converts from `cord` to `tape`, and [`crip`](../4b) converts
66+from `tape` to `cord`.
67+
68+
59
69
60***
70***
61### `++date`
71### `++date`
62
72
63Point in time
73Point in time
64
74
65−A boolean designating AD or BC, a year atom, a month
75+A boolean designating AD or BC, a year atom, a month atom, and a `tarp`,
66−atom, and a `++tarp`, which is a day atom and a time.
76+which is a day atom and a time.
67
77
68−Source
78+#### Source
69−------
70
79
71− ++ date {{a/? y/@ud} m/@ud t/tarp} :: parsed date
80+ ++ date [[a=? y=@ud] m=@ud t=tarp]
72
81
73
82
74−Examples
83+#### Examples
75−--------
76
84
77−See also: `++year`, `++yore` `++stud`, `++dust`
85+ > *date
86+ [[a=%.y y=0] m=0 t=[d=0 h=0 m=0 s=0 f=~]]
78
87
79 > `date`(yore ~2014.6.6..21.09.15..0a16)
88 > `date`(yore ~2014.6.6..21.09.15..0a16)
80 [[a=%.y y=2.014] m=6 t=[d=6 h=21 m=9 s=15 f=~[0xa16]]]
89 [[a=%.y y=2.014] m=6 t=[d=6 h=21 m=9 s=15 f=~[0xa16]]]
81
90
91+ > now
92+ ~2018.5.25..17.55.15..9ad8
93+
94+
95+
96+#### Discussion
97+
98+See also: [`year`](../3c), [`yore`](../3c) [`stud`](../2q), [`dust`](../2q)
99+
100+***
101+### `++knot`
102+
103+ASCII
104+
105+An atom type that only permits ASCII characters.
106+
107+#### Source
108+
109+++ knot @ta
110+
111+#### Examples
112+
113+ > *knot
114+ ~.
115+
116+ > `@ta`105
117+ ~.i
118+
82
119
83***
120***
84### `++tang`
121### `++tang`
85
122
123+Generic print structure
124+
125+A list of `tank`s. It's for printing types and bottom-up printing of stack
126+traces.
127+
128+#### Source
129+
86− ++ tang (list tank) :: general error
130+++ tang (list tank)
87
131
88−Unused XX
132+#### Examples
89
133
134+ > *tang
135+ ~
136+
137+ > (~(win re [%palm ["1" "2" "3" "4"] [%leaf "foobar"] [%leaf "bazbud"] [%leaf "zzzzzzqaaa"] ~]) 0 50)
138+ <<"23foobar1bazbud1zzzzzzqaaa4">>
139+
140+ > (~(win re [%palm ["1" "2" "3" "4"] [%leaf "foobar"] [%leaf "bazbud"] [%leaf "zzzzzzqaaa"] ~]) 0 10)
141+ <<"2 foobar" " bazbud" "zzzzzzqaaa">>
142+
143+ > (~(win re [%rose ["1" "2" "3"] [%leaf "foobar"] [%leaf "bazbud"] ~]) 0 20)
144+ <<"2foobar1bazbud3">>
145+
146+ > (~(win re [%rose ["1" "2" "3"] [%leaf "foobar"] [%leaf "bazbud"] ~]) 0 10)
147+ <<"2 foobar" " bazbud" "3">>
90
148
91
149
92***
150***
93### `++tank`
151### `++tank`
94
152
95−Pretty-printing structure.
153+Pretty-printing structure
154+
155+A `tank` is one of three cases: a `%leaf` is simply a string (a printed line);
156+ a `%palm` is list of `tank` delimited by the strings in `p`, with back-steps at
157+new lines; and a `%rose` is a list of `tank` delimited by the strings in `p`
158+without back-steps at new lines.
96
159
97−A `++tank` is one of three cases: a `%leaf`
98−is simply a string; a `%palm` is XX need more information; and a `%rose` is a
99−list of `++tank` delimted by the strings in `p`.
100
160
161+#### Source
101
162
102−Source
163+ ++ tank $% [$leaf p=tape]
103−------
164+ $: $palm
165+ p=[p=tape q=tape r=tape s=tape]
166+ q=(list tank)
167+ ==
168+ $: $rose
169+ p=[p=tape q=tape r=tape]
170+ q=(list tank)
171+ ==
172+ ==
104
173
105− ++ tank $% {$leaf p/tape} :: printing formats
174+#### Examples
106− $: $palm :: backstep list
107− p/{p/tape q/tape r/tape s/tape} ::
108− q/(list tank) ::
109− == ::
110− $: $rose :: flat list
111− p/{p/tape q/tape r/tape} :: mid open close
112− q/(list tank) ::
113− == ::
114− == ::
115
175
116−Examples
176+ > *tank
117−--------
177+ [%rose p=[p="" q="" r=""] q=~]
118
178
119− > >(bex 20) (bex 19)<
120− [%rose p=[p=" " q="[" r="]"] q=~[[%leaf p="1.048.576"] [%leaf p="524.288"]]]
121− > (wash [0 80] >(bex 20) (bex 19)<) :: at 80 cols
179+ > (wash [0 80] >(bex 20) (bex 19)<) :: at 80 cols
122 <<"[1.048.576 524.288]">>
180 <<"[1.048.576 524.288]">>
181+
123− > (wash [0 15] >(bex 20) (bex 19)<) :: at 15 cols (two lines)
182+ > (wash [0 15] >(bex 20) (bex 19)<) :: at 15 cols
124 <<"[ 1.048.576" " 524.288" "]">>
183 <<"[ 1.048.576" " 524.288" "]">>
125
184
126− > [(bex 150) (bex 151)] :: at 80 cols
185+ > [(bex 150) (bex 151)] :: at 80 cols
127 [ 1.427.247.692.705.959.881.058.285.969.449.495.136.382.746.624
186 [ 1.427.247.692.705.959.881.058.285.969.449.495.136.382.746.624
128 2.854.495.385.411.919.762.116.571.938.898.990.272.765.493.248
187 2.854.495.385.411.919.762.116.571.938.898.990.272.765.493.248
129 ]
188 ]
130
189
190+ > (wash [0 40] >(bex 150) (bex 151)<)
191+ <<
192+ "[ \\/1.427.247.692.705.959.881.058.285.\\/"
193+ " 969.449.495.136.382.746.624"
194+ " \\/ \\/"
195+ " \\/2.854.495.385.411.919.762.116.571.\\/"
196+ " 938.898.990.272.765.493.248"
197+ " \\/ \\/"
198+ "]"
199+ >>
131
200
132
201
133−***
134
202
203+***
135### `++tape`
204### `++tape`
136
205
137−List of chars
206+List of characters
138
207
139−One of Hoon's two string types, the other being `++cord`. A tape is a
208+One of Hoon's two string types, the other being `++cord`. A tape is a list of
140−list of chars.
209+`char`.
141
210
142−Source
211+#### Source
143−------
144
212
145− ++ tape (list char) :: like a string
213+ ++ tape (list @tD)
214+
215+#### Examples
216+
217+ > *tape
218+ ""
219+
220+ > `tape`"foobar"
221+ "foobar"
146
222
147−Examples
223+ >`(list @t)`"foobar"
148−--------
224+ <|f o o b a r|>
149
225
150− > `(list char)`"foobar"
226+ >`(list @tD)`"foobar"
151 "foobar"
227 "foobar"
228+
152 > `(list @)`"foobar"
229 > `(list @)`"foobar"
153 ~[102 111 111 98 97 114]
230 ~[102 111 111 98 97 114]
154
231
@@ -156,26 +233,27 @@ Examples
156***
233***
157### `++tarp`
234### `++tarp`
158
235
159−Day through second
236+Parsed time
237+
238+The time component of a `date`: day, hour, minute, second and a list of `@ux`
239+ for precision.
240+
241+#### Source
160
242
161−The remaining part of a `++date`: day, hour, minute, second and a list
243+ ++ tarp [d=@ud h=@ud m=@ud s=@ud f=(list @ux)]
162−of `@ux` for precision.
163
244
164−Source
165−------
166
245
167− ++ tarp {d/@ud h/@ud m/@ud s/@ud f/(list @ux)} :: parsed time
246+#### Examples
168
247
169
248
170−Examples
249+ > *tarp
171−--------
250+ [d=0 h=0 m=0 s=0 f=~]
172
251
252+ > (yell now)
253+ [d=106.751.991.821.625 h=22 m=58 s=10 f=~[0x44ff]]
173
254
174− > -<-
255+ > `tarp`(yell ~2014.6.6..21.09.15..0a16)
175− ~2014.9.20..00.43.33..b52a
176− > :: the time is always in your context at -<-
177− > (yell -<-)
178− [d=106.751.991.820.278 h=0 m=43 s=39 f=~[0x54d1]]
256+ [d=106.751.991.820.172 h=21 m=9 s=15 f=~[0xa16]]
179
257
180 > (yell ~d20)
258 > (yell ~d20)
181 [d=20 h=0 m=0 s=0 f=~]
259 [d=20 h=0 m=0 s=0 f=~]
@@ -185,42 +263,51 @@ Examples
185***
263***
186### `++term`
264### `++term`
187
265
188−Hoon constants
266+Hoon constant
189
267
190A restricted text atom for Hoon constants. The only characters permitted are
268A restricted text atom for Hoon constants. The only characters permitted are
191−lowercase ASCII, `-`, and `0-9`, the latter two of which can neither be the first or last
269+lowercase ASCII letters, `-`, and `0-9`, the latter two of which cannot be the
192−character. The syntax for `@tas` is the text itself, always preceded by `%`.
270+first character. The syntax for `@tas` is the text itself, always preceded by
193−This means a term is always cubical. The empty `@tas` has a special syntax,
271+`%`. The empty `@tas` has a
194−`$`.
272+special syntax, `$`.
195
273
196
274
197−Source
275+#### Source
198−------
199
276
200− ++ term @tas :: Hoon ASCII subset
277+ ++ term @tas
201
278
202−Examples
279+#### Examples
203−--------
204
280
205 > *term
281 > *term
206 %$
282 %$
207
283
284+ > *%term
285+ %term
286+
208 > %dead-fish9
287 > %dead-fish9
209 %dead-fish9
288 %dead-fish9
289+
210 > -:!>(%dead-fish9)
290 > -:!>(%dead-fish9)
211− [%cube p=271.101.667.197.767.630.546.276 q=[%atom p=%tas]]
291+ #t/$dead-fish9
212
292
213
293
214
294
215***
295***
216### `++wain`
296### `++wain`
217
297
218− ++ wain (list cord) :: text lines (no \n)
298+List of strings
299+
300+A list of `cord`s. A `wain` is used instead of a single `cord` with `\n`.
219
301
220−A list of lines. A `++wain` is used instead of a single `++cord` with
221−`\n`.
222
302
223−See also: `++lore`, `++role`
303+#### Source
304+
305+ ++ wain (list cord)
306+
307+#### Examples
308+
309+ > *wain
310+ <||>
224
311
225 > `wain`/som/del/rok
312 > `wain`/som/del/rok
226 <|som del rok|>
313 <|som del rok|>
@@ -229,28 +316,31 @@ See also: `++lore`, `++role`
229***
316***
230### `++wall`
317### `++wall`
231
318
232−List of lines
319+List of list of characters
233
320
321+A list of `tape`s. `wall` is used instead of a single `tape` with `\n`.
234
322
235−A `++wall` is used instead of a single `++tape` with
323+#### Source
236−`\n`.
237
324
238−Source
325+ ++ wall (list tape)
239−------
240
326
241− ++ wall (list tape) :: text lines (no \n)
242−
243−Examples
327+#### Examples
244−--------
245−
246−See also: `++wash`
247
328
329+ > *wall
330+ <<>>
331+
248 > `wall`(wash [0 20] leaf+<(bex 256)>)
332 > `wall`(wash [0 20] leaf+<(bex 256)>)
249 <<
333 <<
250− "115.792.089.237.316.195.423.570.985.008.687.907.853.269.984.665.640.564.039.457.584.007.913.129.639.936"
334+ "\\/115.792.089.237.\\/"
335+ " 316.195.423.570."
336+ " 985.008.687.907."
337+ " 853.269.984.665."
338+ " 640.564.039.457."
339+ " 584.007.913.129."
340+ " 639.936"
341+ "\\/ \\/"
251 >>
342 >>
252
343
253
344
254
345
255−
256***
346***