on master help sign in
Update 2p
90521d0rmariani
docs/hoon/library/2p.md+54−55
@@ -8,29 +8,26 @@ navhome: /docs/
8
8
9Unpack atom to noun
9Unpack atom to noun
10
10
11−Produces a noun unpacked from atom `a`. The inverse of jam.
11+Produces a noun unpacked from atom `a`. The inverse of `jam`.
12
12
13−Accepts
13+#### Accepts
14−-------
15
14
16`a` is an atom.
15`a` is an atom.
17
16
18−Produces
17+#### Produces
19−--------
20
18
21−A `++noun`.
19+A noun.
22
20
23−Source
21+#### Source
24−------
25
22
26− ++ cue :: unpack
23+ ++ cue
27 ~/ %cue
24 ~/ %cue
28− |= a/@
25+ |= a=@
29 ^- *
26 ^- *
30 =+ b=0
27 =+ b=0
31 =+ m=`(map @ *)`~
28 =+ m=`(map @ *)`~
32 =< q
29 =< q
33− |- ^- {p/@ q/* r/(map @ *)}
30+ |- ^- [p=@ q=* r=(map @ *)]
34 ?: =(0 (cut 0 [b 1] a))
31 ?: =(0 (cut 0 [b 1] a))
35 =+ c=(rub +(b) a)
32 =+ c=(rub +(b) a)
36 [+(p.c) q.c (~(put by m) b q.c)]
33 [+(p.c) q.c (~(put by m) b q.c)]
@@ -42,18 +39,18 @@ Source
42 [(add 2 (add p.u p.v)) w (~(put by r.v) b w)]
39 [(add 2 (add p.u p.v)) w (~(put by r.v) b w)]
43 =+ d=(rub c a)
40 =+ d=(rub c a)
44 [(add 2 p.d) (need (~(get by m) q.d)) m]
41 [(add 2 p.d) (need (~(get by m) q.d)) m]
45− ::
46
42
47−
48−Examples
43+#### Examples
49−--------
50
44
51 > (cue 12)
45 > (cue 12)
52 1
46 1
47+
53 > (cue 817)
48 > (cue 817)
54 [1 1]
49 [1 1]
50+
55 > (cue 4.657)
51 > (cue 4.657)
56 [1 2]
52 [1 2]
53+
57 > (cue 39.689)
54 > (cue 39.689)
58 [0 19]
55 [0 19]
59
56
@@ -63,29 +60,26 @@ Examples
63
60
64Pack noun to atom
61Pack noun to atom
65
62
66−Produces an atom packed from noun `a`. The inverse of cue.
63+Produces an atom packed from noun `a`. The inverse of `cue`.
67
64
68−Accepts
65+#### Accepts
69−-------
70
66
71`a` is a noun.
67`a` is a noun.
72
68
73−Produces
69+#### Produces
74−--------
75
70
76An atom.
71An atom.
77
72
78−Source
73+#### Source
79−------
80
74
81− ++ jam :: pack
75+ ++ jam
82 ~/ %jam
76 ~/ %jam
83− |= a/*
77+ |= a=*
84 ^- @
78 ^- @
85 =+ b=0
79 =+ b=0
86 =+ m=`(map * @)`~
80 =+ m=`(map * @)`~
87 =< q
81 =< q
88− |- ^- {p/@ q/@ r/(map * @)}
82+ |- ^- [p=@ q=@ r=(map * @)]
89 =+ c=(~(get by m) a)
83 =+ c=(~(get by m) a)
90 ?~ c
84 ?~ c
91 => .(m (~(put by m) a b))
85 => .(m (~(put by m) a b))
@@ -101,18 +95,19 @@ Source
101 [(add 1 p.d) (lsh 0 1 q.d) m]
95 [(add 1 p.d) (lsh 0 1 q.d) m]
102 =+ d=(mat u.c)
96 =+ d=(mat u.c)
103 [(add 2 p.d) (mix 3 (lsh 0 2 q.d)) m]
97 [(add 2 p.d) (mix 3 (lsh 0 2 q.d)) m]
104− ::
105
98
106
99
107−Examples
100+#### Examples
108−--------
109
101
110 > (jam 1)
102 > (jam 1)
111 12
103 12
104+
112 > (jam [1 1])
105 > (jam [1 1])
113 817
106 817
107+
114 > (jam [1 2])
108 > (jam [1 2])
115 4.657
109 4.657
110+
116 > (jam [~ u=19])
111 > (jam [~ u=19])
117 39.689
112 39.689
118
113
@@ -127,49 +122,50 @@ Produces a cell whose tail `q` is atom `a` with a bit representation of
127its length prepended to it (as the least significant bits). The head `p`
122its length prepended to it (as the least significant bits). The head `p`
128is the length of `q` in bits.
123is the length of `q` in bits.
129
124
130−Accepts
125+#### Accepts
131−-------
132
126
133`a` is an atom.
127`a` is an atom.
134
128
135−Produces
129+#### Produces
136−--------
137
130
138−A cell of two atoms, `p` and `q`.
131+A cell of two atom.
139
132
140−Source
133+#### Source
141−------
142
134
143− ++ mat :: length-encode
135+ ++ mat
144 ~/ %mat
136 ~/ %mat
145− |= a/@
137+ |= a=@
146− ^- {p/@ q/@}
138+ ^- [p=@ q=@]
147 ?: =(0 a)
139 ?: =(0 a)
148 [1 1]
140 [1 1]
149 =+ b=(met 0 a)
141 =+ b=(met 0 a)
150 =+ c=(met 0 b)
142 =+ c=(met 0 b)
151 :- (add (add c c) b)
143 :- (add (add c c) b)
152 (cat 0 (bex c) (mix (end 0 (dec c) b) (lsh 0 (dec c) a)))
144 (cat 0 (bex c) (mix (end 0 (dec c) b) (lsh 0 (dec c) a)))
153− ::
154−
155
145
156−Examples
146+#### Examples
157−--------
158
147
159 > (mat 0xaaa)
148 > (mat 0xaaa)
160 [p=20 q=699.024]
149 [p=20 q=699.024]
150+
161 > (met 0 q:(mat 0xaaa))
151 > (met 0 q:(mat 0xaaa))
162 20
152 20
153+
163 > `@ub`q:(mat 0xaaa)
154 > `@ub`q:(mat 0xaaa)
164 0b1010.1010.1010.1001.0000
155 0b1010.1010.1010.1001.0000
156+
165 > =a =-(~&(- -) `@ub`0xaaa)
157 > =a =-(~&(- -) `@ub`0xaaa)
166 0b1010.1010.1010
158 0b1010.1010.1010
159+
167 > =b =-(~&(- -) `@ub`(xeb a))
160 > =b =-(~&(- -) `@ub`(xeb a))
168 0b1100
161 0b1100
162+
169 > =b =-(~&(- -) `@ub`(met 0 a))
163 > =b =-(~&(- -) `@ub`(met 0 a))
170 0b1100
164 0b1100
165+
171 > =c =-(~&(- -) (xeb b))
166 > =c =-(~&(- -) (xeb b))
172 4
167 4
168+
173 > [`@ub`a `@ub`(end 0 (dec c) b) `@ub`(bex c)]
169 > [`@ub`a `@ub`(end 0 (dec c) b) `@ub`(bex c)]
174 [0b1010.1010.1010 0b100 0b1.0000]
170 [0b1010.1010.1010 0b100 0b1.0000]
175
171
@@ -183,27 +179,24 @@ Length-decode
183The inverse of `++mat`. Accepts a cell of index `a` and a bitstring `b`
179The inverse of `++mat`. Accepts a cell of index `a` and a bitstring `b`
184and produces the cell whose tail `q` is the decoded atom at index `a`
180and produces the cell whose tail `q` is the decoded atom at index `a`
185and whose head is the length of the encoded atom `q`, by which the
181and whose head is the length of the encoded atom `q`, by which the
186−offset `a` is advanced. Only used internally as a helper cue.
182+offset `a` is advanced.
187
183
188−Accepts
184+#### Accepts
189−-------
190
185
191`a` is an atom.
186`a` is an atom.
192
187
193`b` is a bitstring as an atom.
188`b` is a bitstring as an atom.
194
189
195−Produces
190+#### Produces
196−--------
197
191
198−A cell of two atoms, `p` and `q`.
192+A cell of two atoms.
199
193
200−Source
194+#### Source
201−------
202
195
203− ++ rub :: length-decode
196+ ++ rub
204 ~/ %rub
197 ~/ %rub
205− |= {a/@ b/@}
198+ |= [a=@ b=@]
206− ^- {p/@ q/@}
199+ ^- [p=@ q=@]
207 =+ ^= c
200 =+ ^= c
208 =+ [c=0 m=(met 0 b)]
201 =+ [c=0 m=(met 0 b)]
209 |- ?< (gth c m)
202 |- ?< (gth c m)
@@ -217,14 +210,20 @@ Source
217 [(add (add c c) e) (cut 0 [(add d (dec c)) e] b)]
210 [(add (add c c) e) (cut 0 [(add d (dec c)) e] b)]
218
211
219
212
220−Examples
213+#### Examples
221−--------
222
214
223 > `@ub`(jam 0xaaa)
215 > `@ub`(jam 0xaaa)
224 0b1.0101.0101.0101.0010.0000
216 0b1.0101.0101.0101.0010.0000
217+
225 > (rub 1 0b1.0101.0101.0101.0010.0000)
218 > (rub 1 0b1.0101.0101.0101.0010.0000)
226 [p=20 q=2.730]
219 [p=20 q=2.730]
220+
227 > `@ux`q:(rub 1 0b1.0101.0101.0101.0010.0000)
221 > `@ux`q:(rub 1 0b1.0101.0101.0101.0010.0000)
228 0xaaa
222 0xaaa
229
223
224+
225+#### Discussion
226+
227+Only used internally as a helper cue.
228+
230***
229***