on 6d45ede help sign in
343 lines 5.9 kB history raw
1---
2navhome: /docs
3---
6# 2k: queue logic
7### `++to`
9Queue operations
11Container arm for queue operation arms. The contained arms inherit its
12sample `++qeu` `a`.
14Accepts
15-------
17`a` is a queue, ++qeu.
19Source
20------
22 ++ to :: queue engine
23 |/ a/(qeu)
25### `+-bal:to`
27Balance
29Vertically rebalances queue `a`.
31Accepts
32-------
34`a` is a queue.
36Produces
37--------
39A queue.
41Source
42------
44 +- bal
45 |- ^+ a
46 ?~ a ~
47 ?. |(?=($~ l.a) (vor n.a n.l.a))
48 $(a [n.l.a l.l.a $(a [n.a r.l.a r.a])])
49 ?. |(?=($~ r.a) (vor n.a n.r.a))
50 $(a [n.r.a $(a [n.a l.a l.r.a]) r.r.a])
51 a
52 ::
55Examples
56--------
58 > `(qeu tape)`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~]
59 {"a" "b" "c" "d" "e" "f" "g"}
60 > `*`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~]
61 [[97 0] 0 [98 0] 0 [99 0] 0 [100 0] 0 [101 0] 0 [102 0] 0 [103 0] 0 0]
62 > ~(bal to `(qeu tape)`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~])
63 {"a" "b" "c" "d" "e" "f" "g"}
64 > `*`~(bal to `(qeu tape)`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~])
65 [[100 0] [[99 0] [[98 0] [[97 0] 0 0] 0] 0] [101 0] 0 [102 0] 0 [103 0] 0 0]
67------------------------------------------------------------------------
69### `+-dep:to`
71Maximum Depth
73Produces the maximum depth of leaves (r.a and l.a) in queue `a`.
75Accepts
76-------
78`a` is a queue.
80Produces
81--------
83An atom.
85Source
86------
88 +- dep :: max depth of queue
89 |- ^- @
90 ?~ a 0
91 +((max $(a l.a) $(a r.a)))
92 ::
95Examples
96--------
98 > =a (~(gas to `(qeu @)`~) `(list @)`[1 2 3 4 5 6 7 ~])
99 > ~(dep to a)
100 4
101 > =a (~(gas to `(qeu @)`~) `(list @)`[1 2 3 4 ~])
102 > ~(dep to a)
103 3
104 > =a (~(gas to `(qeu @)`~) `(list @)`[1 2 ~])
105 > ~(dep to a)
106 2
107 > ~(dep to `(qeu tape)`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~])
108 7
109 > ~(dep to ~(bal to `(qeu tape)`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~]))
110 4
112------------------------------------------------------------------------
114### `+-gas`
116Push list
118Push all elements of `++list` `b` into the `++queue`.
120Accepts
121-------
123`a` is a queue.
125`b` is a list.
127Produces
128--------
130A queue.
132Source
133------
135 +- gas :: insert list to queue
136 |= b=(list ,_?>(?=(^ a) n.a))
137 |- ^+ a
138 ?~(b a $(b t.b, a (put(+< a) i.b)))
139 ::
141Examples
142--------
144 > (~(gas to `(qeu ,@)`~) `(list ,@)`[1 2 3 ~])
145 {3 2 1}
146 > =a (~(gas to `(qeu ,@)`~) `(list ,@)`[1 2 3 ~])
147 > =b `(list ,@)`[4 5 6 ~]
148 > (~(gas to a) b)
149 {6 5 4 3 2 1}
151------------------------------------------------------------------------
153### `+-get:to`
155Pop
157Produces the head and tail `++queue` of `a`.
159Accepts
160-------
162`a` is a queue.
164Produces
165--------
167The last element in `a` along with the rest of queue `a`.
169Source
170------
172 +- get :: head-tail pair
173 |- ^+ ?>(?=(^ a) [p=n.a q=*(qeu _n.a)])
174 ?~ a
175 !!
176 ?~ r.a
177 [n.a l.a]
178 =+ b=$(a r.a)
179 :- p.b
180 ?: |(?=($~ q.b) (vor n.a n.q.b))
181 [n.a l.a q.b]
182 [n.q.b [n.a l.a l.q.b] r.q.b]
183 ::
185Examples
186--------
188 > =s (~(gas to *(qeu @)) `(list @)`~[1 2 3])
189 > ~(get to s)
190 [p=1 q={3 2}]
191 > ~(get to ~)
192 ! exit
194------------------------------------------------------------------------
196### `+-nap:to`
198Remove last element
200Removes the head of `++queue` `a`, producing the resulting queue.
202Accepts
203-------
205`a` is a queue.
207Produces
208--------
210A queue.
212Source
213------
215 +- nap :: removes head
216 ?> ?=(^ a)
217 ?: =(~ l.a) r.a
218 =+ b=get(a l.a)
219 bal(a ^+(a [p.b q.b r.a]))
220 ::
222Examples
223--------
225 > =a (~(gas to `(qeu @)`~) `(list @)`[1 2 3 4 5 6 ~])
226 > -.a
227 n=6
228 > =b ~(nap to a)
229 > -.b
230 n=2
231 > b
232 {5 4 3 2 1}
233 > a
234 {6 5 4 3 2 1}
236------------------------------------------------------------------------
238### `+-put:to`
240Insert
242Accept any noun `b` and adds to `++queue` `a` as the head, producing the
243resulting queue.
245Accepts
246-------
248`a` is a queue.
250`b` is any noun.
252Produces
253--------
255A queue.
257Source
258------
260 +- put :: insert new tail
261 |* b/*
262 |- ^+ a
263 ?~ a
264 [b ~ ~]
265 bal(a a(l $(a l.a)))
266 ::
269Examples
270--------
272 > (~(gas to `(qeu @)`~) `(list @)`[3 1 2 4 5 6 ~])
273 > (~(put to a) 7)
274 {7 6 5 4 2 1 3}
276------------------------------------------------------------------------
278### `+-tap:to`
280Queue to list
282Produces `++queue` `a` as a `++list` from front to back.
284Accepts
285-------
287`a` is a queue.
289Source
290------
292 +- tap :: adds list to end
293 |= b/(list _?>(?=(^ a) n.a))
294 =+ z=0 :: XX breaks jet match
295 ^+ b
296 ?~ a
297 b
298 $(a r.a, b [n.a $(a l.a)])
299 ::
301Examples
302--------
304 > =a (~(gas to `(qeu @)`~) `(list @)`[3 1 2 4 5 6 ~])
305 > `*`a
306 [6 0 2 [4 [5 0 0] 0] 1 0 3 0 0]
307 > (~(tap to a) `(list @)`[99 100 101 ~])
308 ~[3 1 2 4 5 6 99 100 101]
310------------------------------------------------------------------------
312### `+-top:to`
314Produces the head of `++queue` `a` as a `++unit` (an empty queue has no head).
316Accepts
317-------
319`a` is a queue.
321Produces
322--------
324A unit.
326Source
327------
329 +- top :: produces head
330 |- ^- (unit _?>(?=(^ a) n.a))
331 ?~ a ~
332 ?~(r.a [~ n.a] $(a r.a))
334Examples
335--------
337 > =a (~(gas to `(qeu @)`~) `(list @)`[1 2 3 4 5 6 ~])
338 > ~(top to a)
339 [~ 1]
343***