on 140ac0e help sign in
338 lines 5.9 kB history raw
1# 2k: queue logic
2### `++to`
4Queue operations
6Container arm for queue operation arms. The contained arms inherit its
7sample `++qeu` `a`.
9Accepts
10-------
12`a` is a queue, ++qeu.
14Source
15------
17 ++ to :: queue engine
18 |/ a/(qeu)
20### `+-bal:to`
22Balance
24Vertically rebalances queue `a`.
26Accepts
27-------
29`a` is a queue.
31Produces
32--------
34A queue.
36Source
37------
39 +- bal
40 |- ^+ a
41 ?~ a ~
42 ?. |(?=($~ l.a) (vor n.a n.l.a))
43 $(a [n.l.a l.l.a $(a [n.a r.l.a r.a])])
44 ?. |(?=($~ r.a) (vor n.a n.r.a))
45 $(a [n.r.a $(a [n.a l.a l.r.a]) r.r.a])
46 a
47 ::
50Examples
51--------
53 > `(qeu tape)`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~]
54 {"a" "b" "c" "d" "e" "f" "g"}
55 > `*`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~]
56 [[97 0] 0 [98 0] 0 [99 0] 0 [100 0] 0 [101 0] 0 [102 0] 0 [103 0] 0 0]
57 > ~(bal to `(qeu tape)`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~])
58 {"a" "b" "c" "d" "e" "f" "g"}
59 > `*`~(bal to `(qeu tape)`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~])
60 [[100 0] [[99 0] [[98 0] [[97 0] 0 0] 0] 0] [101 0] 0 [102 0] 0 [103 0] 0 0]
62------------------------------------------------------------------------
64### `+-dep:to`
66Maximum Depth
68Produces the maximum depth of leaves (r.a and l.a) in queue `a`.
70Accepts
71-------
73`a` is a queue.
75Produces
76--------
78An atom.
80Source
81------
83 +- dep :: max depth of queue
84 |- ^- @
85 ?~ a 0
86 +((max $(a l.a) $(a r.a)))
87 ::
90Examples
91--------
93 > =a (~(gas to `(qeu @)`~) `(list @)`[1 2 3 4 5 6 7 ~])
94 > ~(dep to a)
95 4
96 > =a (~(gas to `(qeu @)`~) `(list @)`[1 2 3 4 ~])
97 > ~(dep to a)
98 3
99 > =a (~(gas to `(qeu @)`~) `(list @)`[1 2 ~])
100 > ~(dep to a)
101 2
102 > ~(dep to `(qeu tape)`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~])
103 7
104 > ~(dep to ~(bal to `(qeu tape)`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~]))
105 4
107------------------------------------------------------------------------
109### `+-gas`
111Push list
113Push all elements of `++list` `b` into the `++queue`.
115Accepts
116-------
118`a` is a queue.
120`b` is a list.
122Produces
123--------
125A queue.
127Source
128------
130 +- gas :: insert list to queue
131 |= b=(list ,_?>(?=(^ a) n.a))
132 |- ^+ a
133 ?~(b a $(b t.b, a (put(+< a) i.b)))
134 ::
136Examples
137--------
139 > (~(gas to `(qeu ,@)`~) `(list ,@)`[1 2 3 ~])
140 {3 2 1}
141 > =a (~(gas to `(qeu ,@)`~) `(list ,@)`[1 2 3 ~])
142 > =b `(list ,@)`[4 5 6 ~]
143 > (~(gas to a) b)
144 {6 5 4 3 2 1}
146------------------------------------------------------------------------
148### `+-get:to`
150Pop
152Produces the head and tail `++queue` of `a`.
154Accepts
155-------
157`a` is a queue.
159Produces
160--------
162The last element in `a` along with the rest of queue `a`.
164Source
165------
167 +- get :: head-tail pair
168 |- ^+ ?>(?=(^ a) [p=n.a q=*(qeu _n.a)])
169 ?~ a
170 !!
171 ?~ r.a
172 [n.a l.a]
173 =+ b=$(a r.a)
174 :- p.b
175 ?: |(?=($~ q.b) (vor n.a n.q.b))
176 [n.a l.a q.b]
177 [n.q.b [n.a l.a l.q.b] r.q.b]
178 ::
180Examples
181--------
183 > =s (~(gas to *(qeu @)) `(list @)`~[1 2 3])
184 > ~(get to s)
185 [p=1 q={3 2}]
186 > ~(get to ~)
187 ! exit
189------------------------------------------------------------------------
191### `+-nap:to`
193Remove last element
195Removes the head of `++queue` `a`, producing the resulting queue.
197Accepts
198-------
200`a` is a queue.
202Produces
203--------
205A queue.
207Source
208------
210 +- nap :: removes head
211 ?> ?=(^ a)
212 ?: =(~ l.a) r.a
213 =+ b=get(a l.a)
214 bal(a ^+(a [p.b q.b r.a]))
215 ::
217Examples
218--------
220 > =a (~(gas to `(qeu @)`~) `(list @)`[1 2 3 4 5 6 ~])
221 > -.a
222 n=6
223 > =b ~(nap to a)
224 > -.b
225 n=2
226 > b
227 {5 4 3 2 1}
228 > a
229 {6 5 4 3 2 1}
231------------------------------------------------------------------------
233### `+-put:to`
235Insert
237Accept any noun `b` and adds to `++queue` `a` as the head, producing the
238resulting queue.
240Accepts
241-------
243`a` is a queue.
245`b` is any noun.
247Produces
248--------
250A queue.
252Source
253------
255 +- put :: insert new tail
256 |* b/*
257 |- ^+ a
258 ?~ a
259 [b ~ ~]
260 bal(a a(l $(a l.a)))
261 ::
264Examples
265--------
267 > (~(gas to `(qeu @)`~) `(list @)`[3 1 2 4 5 6 ~])
268 > (~(put to a) 7)
269 {7 6 5 4 2 1 3}
271------------------------------------------------------------------------
273### `+-tap:to`
275Queue to list
277Produces `++queue` `a` as a `++list` from front to back.
279Accepts
280-------
282`a` is a queue.
284Source
285------
287 +- tap :: adds list to end
288 |= b/(list _?>(?=(^ a) n.a))
289 =+ z=0 :: XX breaks jet match
290 ^+ b
291 ?~ a
292 b
293 $(a r.a, b [n.a $(a l.a)])
294 ::
296Examples
297--------
299 > =a (~(gas to `(qeu @)`~) `(list @)`[3 1 2 4 5 6 ~])
300 > `*`a
301 [6 0 2 [4 [5 0 0] 0] 1 0 3 0 0]
302 > (~(tap to a) `(list @)`[99 100 101 ~])
303 ~[3 1 2 4 5 6 99 100 101]
305------------------------------------------------------------------------
307### `+-top:to`
309Produces the head of `++queue` `a` as a `++unit` (an empty queue has no head).
311Accepts
312-------
314`a` is a queue.
316Produces
317--------
319A unit.
321Source
322------
324 +- top :: produces head
325 |- ^- (unit _?>(?=(^ a) n.a))
326 ?~ a ~
327 ?~(r.a [~ n.a] $(a r.a))
329Examples
330--------
332 > =a (~(gas to `(qeu @)`~) `(list @)`[1 2 3 4 5 6 ~])
333 > ~(top to a)
334 [~ 1]
338***