on master help sign in
update col runes
f5dd3baTinnus Napbus
content/docs/hoon/reference/rune/col.md+282−121
@@ -4,242 +4,403 @@ weight = 9
4template = "doc.html"
4template = "doc.html"
5aliases = ["docs/reference/hoon-expressions/rune/col/"]
5aliases = ["docs/reference/hoon-expressions/rune/col/"]
6+++
6+++
7−The `:` ("col") expressions are used to produce cells, which are pairs of values. E.g., `:-(p q)` produces the cell `[p q]`. All `:` runes reduce to `:-`.
8
7
9−## Runes
8+The `:` ("col") expressions are used to produce cells, which are pairs of
9+values. E.g., `:-(p q)` produces the cell `[p q]`. All `:` runes reduce to `:-`.
10
10
11−### `:_` "colcab"
11+## `:-` "colhep"
12
12
13−`[%clcb p=hoon q=hoon]`; construct a cell, inverted.
13+Construct a cell (2-tuple).
14
14
15−##### Expands to
15+#### Syntax
16+
17+Two arguments, fixed.
18+
19+Tall form:
16
20
17```hoon
21```hoon
18−:-(q p)
22+:- p
23+q
19```
24```
20
25
21−##### Syntax
26+Wide form:
22
27
23−Regular: **2-fixed**.
28+```hoon
29+:-(p q)
30+```
24
31
25−##### Examples
32+Irregular form:
26
33
34+```hoon
35+[p q]
27```
36```
28−~zod:dojo> :_(1 2)
37+
29−[2 1]
38+or
39+
40+```hoon
41+p^q
30```
42```
31
43
32−### `::` "colcol"
44+#### AST
33
45
34−Code comment
46+```hoon
47+[%clhp p=hoon q=hoon]
48+```
35
49
36−##### Syntax
50+#### Produces
37
51
38−:: any text you like!
52+The cell of `p` and `q`.
53+
54+#### Discussion
55+
56+Hoon expressions actually use the same "autocons" pattern as Nock
57+formulas. If you're assembling expressions (which usually only the
58+compiler does), `[a b]` is the same as `:-(a b)`.
59+
60+#### Examples
39
61
40−##### Examples
62+```
63+> :-(1 2)
64+[1 2]
65+
66+~zod:dojo> 1^2
67+[1 2]
68+```
69+
70+---
71+
72+## `:_` "colcab"
73+
74+Construct a cell, inverted.
75+
76+#### Syntax
77+
78+Two arguments, fixed.
79+
80+Tall form:
41
81
42```hoon
82```hoon
43−::
83+:_ p
44−:: this is commented code
84+q
45−::
46−|= a=@ :: a gate
47−(add 2 a) :: that adds 2
48− :: to the input
49```
85```
50
86
51−### `:-` "colhep"
87+Wide form:
52
88
53−`[%clhp p=hoon q=hoon]`: construct a cell (2-tuple).
89+```hoon
90+:_(p q)
91+```
54
92
55−##### Produces
93+Irregular form:
56
94
57−The cell of `p` and `q`.
95+None.
58
96
59−##### Syntax
97+#### AST
60
98
61−Regular: **2-fixed**.
99+```hoon
100+[%clcb p=hoon q=hoon]
101+```
62
102
63−Irregular: `[a b]` is `:-(a b)`.
103+#### Expands to
64
104
65−Irregular: `[a b c]` is `[a [b c]]`.
105+```hoon
106+:-(q p)
107+```
66
108
67−Irregular: `a^b^c` is `[a b c]`.
109+#### Examples
68
110
69−Irregular: `a/b` is `[%a b]`.
111+```
112+> :_(1 2)
113+[2 1]
114+```
70
115
71−Irregular: `` `a `` is `[~ a]`.
116+---
72
117
73−Irregular: `~[a b]` is `[a b ~]`.
118+## `:+` "collus"
74
119
75−Irregular: `[a b c]~` is `[[a b c] ~]`.
120+Construct a triple (3-tuple).
76
121
77−## Discussion
122+#### Syntax
78
123
79−Hoon expressions actually use the same "autocons" pattern as Nock
124+Three arguments, fixed.
80−formulas. If you're assembling expressions (which usually only the
81−compiler does), `[a b]` is the same as `:-(a b)`.
82
125
83−##### Examples
126+Tall form:
84
127
128+```hoon
129+:+ p
130+ q
131+r
85```
132```
86−~zod:dojo> :-(1 2)
87−[1 2
88
133
89−~zod:dojo> 1^2
134+Wide form:
90−[1 2]
91
135
92−~zod:dojo> 1/2
136+```hoon
93−[%1 2]
137+:+(p q r)
138+```
94
139
95−~zod:dojo> `1
140+Irregular form:
96−[~ 1]
141+
142+```hoon
143+[p q r]
97```
144```
98
145
99−### `:^` "colket"
146+#### AST
100
147
148+```hoon
101−`[%clkt p=hoon q=hoon r=hoon s=hoon]`: construct a quadruple (4-tuple).
149+[%clls p=hoon q=hoon r=hoon]
150+```
102
151
103−##### Expands to
152+#### Expands to:
104
153
105```hoon
154```hoon
106−:-(p :-(q :-(r s)))
155+:-(p :-(q r))
107```
156```
108
157
109−##### Syntax
158+#### Examples
110
159
111−Regular: **4-fixed**.
160+```
161+> :+ 1
162+ 2
163+ 3
164+[1 2 3]
165+
166+> :+(%a ~ 'b')
167+[%a ~ 'b']
168+```
169+
170+---
112
171
113−##### Examples
172+## `:^` "colket"
114
173
174+Construct a quadruple (4-tuple).
175+
176+#### Syntax
177+
178+Four arguments, fixed.
179+
180+Tall form:
181+
182+```hoon
183+:^ p
184+ q
185+ r
186+s
115```
187```
116−~zod:dojo> :^(1 2 3 4)
117−[1 2 3 4]
118
188
119−~zod:dojo> :^ 5
189+Wide form:
120− 6
190+
121− 7
191+```hoon
122− 8
192+:^(p q r s)
123−[5 6 7 8]
124```
193```
125
194
126−### `:+` "collus"
195+Irregular form:
196+
197+```hoon
198+[p q r s]
199+```
127
200
201+#### AST
128
202
203+```hoon
129−`[%clls p=hoon q=hoon r=hoon]`: construct a triple (3-tuple).
204+[%clkt p=hoon q=hoon r=hoon s=hoon]
205+```
130
206
131−##### Expands to:
207+#### Expands to
132
208
133```hoon
209```hoon
134−:-(p :-(q r))
210+:-(p :-(q :-(r s)))
211+```
212+
213+#### Examples
214+
135```
215```
216+> :^(1 2 3 4)
217+[1 2 3 4]
218+
219+> :^ 5
220+ 6
221+ 7
222+ 8
223+[5 6 7 8]
224+```
225+
226+---
227+
228+## `:*` "coltar"
229+
230+Construct an n-tuple.
136
231
137−##### Syntax
232+#### Syntax
138
233
139−Regular: **3-fixed**.
234+Variable number of arguments.
140
235
141−##### Examples
236+Tall form:
142
237
238+```hoon
239+:* p1
240+ p2
241+ p3
242+ pn
243+==
143```
244```
144−/~zod:dojo> :+ 1
145− 2
146− 3
147−[1 2 3]
148
245
149−~zod:dojo> :+(%a ~ 'b')
246+Wide form:
150−[%a ~ 'b']
247+
248+```hoon
249+:*(p1 p2 p3 pn)
151```
250```
152
251
153−### `:~` "colsig"
252+Irregular form:
154
253
155−`[%clsg p=(list hoon)]`: construct a null-terminated list.
254+```hoon
255+[p1 p2 p3 pn]
256+```
257+
258+#### AST
156
259
260+```hoon
261+[%cltr p=(list hoon)]
262+```
263+
157−##### Expands to
264+#### Expands to
158
265
159**Pseudocode**: `a`, `b`, `c`, ... as elements of `p`:
266**Pseudocode**: `a`, `b`, `c`, ... as elements of `p`:
160
267
161```hoon
268```hoon
162−:-(a :-(b :-(c :-(... :-(z ~)))))
269+:-(a :-(b :-(c :-(... z)))))
163```
270```
164
271
165−##### Desugaring
272+#### Desugaring
166
273
167```hoon
274```hoon
168|-
275|-
169?~ p
276?~ p
170− ~
277+ !!
278+?~ t.p
279+ i.p
171:- i.p
280:- i.p
172$(p t.p)
281$(p t.p)
173```
282```
174
283
175−##### Syntax
284+#### Examples
176
285
177−Regular: **running**.
286+```
287+> :*(5 3 4 1 4 9 0 ~ 'a')
288+[5 3 4 1 4 9 0 ~ 'a']
178
289
179−##### Examples
290+> [5 3 4 1 4 9 0 ~ 'a']
291+[5 3 4 1 4 9 0 ~ 'a']
180
292
293+> :* 5
294+ 3
295+ 4
296+ 1
297+ 4
298+ 9
299+ 0
300+ ~
301+ 'a'
302+ ==
303+[5 3 4 1 4 9 0 ~ 'a']
181```
304```
182−~zod:dojo> :~(5 3 4 2 1)
183−[5 3 4 2 1 ~]
184
305
185−~zod:dojo> ~[5 3 4 2 1]
306+---
186−[5 3 4 2 1 ~]
187
307
188−~zod:dojo> :~ 5
308+## `:~` "colsig"
189− 3
309+
190− 4
310+Construct a null-terminated list.
191− 2
311+
192− 1
312+#### Syntax
313+
314+Variable number of arguments.
315+
316+Tall form:
317+
318+```hoon
319+:~ p1
320+ p2
321+ p3
322+ pn
193− ==
323+==
194−[5 3 4 2 1 ~]
195```
324```
196
325
197−### `:*` "coltar"
326+Wide form:
198
327
328+```hoon
329+:~(p1 p2 p3 pn)
330+```
331+
332+Irregular form:
333+
334+```hoon
335+~[p1 p2 p3 pn]
336+```
337+
338+#### AST
339+
340+```hoon
199−`[%cltr p=(list hoon)]`: construct an n-tuple.
341+[%clsg p=(list hoon)]
342+```
200
343
201−##### Expands to
344+#### Expands to
202
345
203**Pseudocode**: `a`, `b`, `c`, ... as elements of `p`:
346**Pseudocode**: `a`, `b`, `c`, ... as elements of `p`:
204
347
205```hoon
348```hoon
206−:-(a :-(b :-(c :-(... z)))))
349+:-(a :-(b :-(c :-(... :-(z ~)))))
207```
350```
208
351
209−##### Desugaring
352+#### Desugaring
210
353
211```hoon
354```hoon
212|-
355|-
213?~ p
356?~ p
214− !!
357+ ~
215−?~ t.p
216− i.p
217:- i.p
358:- i.p
218$(p t.p)
359$(p t.p)
219```
360```
220
361
221−##### Syntax
362+#### Discussion
222
363
223−Regular: **running**.
364+Note that this does not produce a `list` type, it just produces a
365+null-terminated n-tuple. To make it a proper `list` it must be cast or molded.
224
366
225−##### Examples
367+#### Examples
226
368
227```
369```
228−~zod:dojo> :*(5 3 4 1 4 9 0 ~ 'a')
370+> :~(5 3 4 2 1)
229−[5 3 4 1 4 9 0 ~ 'a']
371+[5 3 4 2 1 ~]
230
372
231−~zod:dojo> [5 3 4 1 4 9 0 ~ 'a']
373+> ~[5 3 4 2 1]
232−[5 3 4 1 4 9 0 ~ 'a']
374+[5 3 4 2 1 ~]
233
375
234−~zod:dojo> :* 5
376+> :~ 5
235− 3
377+ 3
236− 4
378+ 4
237− 1
379+ 2
238− 4
380+ 1
239− 9
240− 0
241− ~
242− 'a'
243− ==
381+ ==
244−[5 3 4 1 4 9 0 ~ 'a']
382+[5 3 4 2 1 ~]
383+```
384+
385+---
386+
387+## `::` "colcol"
388+
389+Code comment.
390+
391+#### Syntax
392+
393+```hoon
394+:: any text you like!
395+```
396+
397+#### Examples
398+
399+```hoon
400+::
401+:: this is commented code
402+::
403+|= a=@ :: a gate
404+(add 2 a) :: that adds 2
405+ :: to the input
245```
406```