on 69cd7eb help sign in
436 lines 6.5 kB history raw
1+++
2title = "2f: Noun Ordering"
3weight = 9
4template = "doc.html"
5+++
6### `++aor`
8Alphabetical order
10Computes whether `a` and `b` are in alphabetical order, producing a flag.
12#### Accepts
14`a` is a noun.
16`b` is a noun.
18#### Produces
20A flag.
22#### Source
24```
25 ++ aor
26 ~/ %aor
27 |= [a=* b=*]
28 ^- ?
29 ?: =(a b) &
30 ?. ?=(@ a)
31 ?: ?=(@ b) |
32 ?: =(-.a -.b)
33 $(a +.a, b +.b)
34 $(a -.a, b -.b)
35 ?. ?=(@ b) &
36 |-
37 =+ [c=(end 3 1 a) d=(end 3 1 b)]
38 ?: =(c d)
39 $(a (rsh 3 1 a), b (rsh 3 1 b))
40 (lth c d)
41```
43#### Examples
45```
46 > (aor 'a' 'b')
47 %.y
49 > (aor 'b' 'a')
50 %.n
52 > (aor 'a' 'a')
53 %.y
55 > (aor "foo" "bar")
56 %.n
58 > (aor "bar" "foo")
59 %.y
61 > (aor "abcdefz" "abcdefa")
62 %.n
64 > (aor "abcdefa" "abcdefz")
65 %.y
67 > (aor 10.000 17.000)
68 %.y
70 > (aor 10 9)
71 %.n
72```
75---
76### `++dor`
78Numeric order
80Computes whether `a` and `b` are in ascending numeric order, producing a flag.
82#### Accepts
84`a` is a noun.
86`b` is a noun.
88#### Produces
90A flag.
92#### Source
94```
95 ++ dor
96 ~/ %dor
97 |= [a=* b=*]
98 ^- ?
99 ?: =(a b) &
100 ?. ?=(@ a)
101 ?: ?=(@ b) |
102 ?: =(-.a -.b)
103 $(a +.a, b +.b)
104 $(a -.a, b -.b)
105 ?. ?=(@ b) &
106 (lth a b)
107```
109#### Examples
111```
112 > (dor 1 2)
113 %.y
115 > (dor 2 1)
116 %.n
118 > (dor ~[1 2 3] ~[1 2 4])
119 %.y
121 > (dor ~[1 2 4] ~[1 2 3])
122 %.n
124 > (dor `(list @)`~[99 100 10.000] ~[99 101 10.000])
125 %.y
127 > (dor ~[99 101 10.999] `(list @)`~[99 100 10.000])
128 %.n
129```
131#### Discussion
133If `a` and `b` are both atoms, `dor` is equivalent to [`lte`](@/docs/reference/library/1a.md). If they're
134cells, `dor` recurses on the heads, and then if the heads are the same it checks
135the tails.
137If one sample is a cell and the other is an atom, the cell sample is treated as
138"greater."
141---
142### `++gor`
144Hash order
146Computes whether of `(mug a)` and `(mug b)` are in ascending numeric order,
147producing a flag. If the `mug` hashes are equal, `a` and `b` are compared by
148`dor` instead.
150[`mug`](@/docs/reference/library/2e.md) is the the 31-bit nonzero FNV-1a hash algorithm.
152#### Accepts
154`a` is a noun.
156`b` is a noun.
158#### Produces
160A flag.
162#### Source
164```
165 ++ gor
166 ~/ %gor
167 |= [a=* b=*]
168 ^- ?
169 =+ [c=(mug a) d=(mug b)]
170 ?: =(c d)
171 (dor a b)
172 (lth c d)
173```
175#### Examples
177```
178 > (gor 'd' 'c')
179 %.y
181 > 'd'
182 'd'
184 > 'c'
185 'c'
187 > `@ud`'d'
188 100
190 > `@ud`'c'
191 99
193 > (mug 'd')
194 1.628.185.714
196 > (mug 'c')
197 1.712.073.811
199 > (gor 'd' 'c')
200 %.y
202 > (gor 'c' 'd')
203 %.n
205 > (gor "foo" "bar")
206 %.n
208 > (gor (some 10) `(list @)`[1 2 3 ~])
209 %.n
210```
212#### Discussion
214`map`s use `gor` on the key for horizontal ordering and `vor` for
215vertical order. `map`s only look at the keys (the head of the key-value pair
216elements) for ordering.
218---
219### `++hor`
221Horizontal hash order
223If `a` and `b` are atoms, they are computed as samples of `gor`, producing a
224flag.
226If `a` and `b` are cells, `hor` checks to see if their heads are equal. If their
227heads are equal, `gor` is computed on their tails, producing a flag. If their
228heads are not equal, `gor` is computed on their heads, producing a flag.
230If `a` is an atom and `b` is not, then `%.y` is produced. If `b` is an atom and
231`a` is not, `%.n` is produced.
233#### Accepts
235`a` is a noun.
237`b` is a noun.
239#### Produces
241A flag.
243#### Source
245```
246 ++ hor
247 ~/ %hor
248 |= [a=* b=*]
249 ^- ?
250 ?: ?=(@ a)
251 ?. ?=(@ b) &
252 (gor a b)
253 ?: ?=(@ b) |
254 ?: =(-.a -.b)
255 (gor +.a +.b)
256 (gor -.a -.b)
257```
259#### Examples
261```
262 > (hor . 1)
263 %.n
265 > (hor 1 2)
266 %.y
268 > (hor "abc" "cba")
269 %.y
271 > (hor 'c' 'd')
272 %.n
274 > (hor 100 [1 1])
275 %.y
277 > (hor [1 1] 100)
278 %.n
280 > (hor 500.000.000 "foo")
281 %.y
283 > (hor "foo" 500.000.000)
284 %.n
286 > (hor 0 "foo")
287 %.y
289 > (gor `(list @)`[0 ~] 1)
290 %.n
292 > (hor `(list @)`[50 500 5.000 ~] 1)
293 %.n
294```
296#### Discussion
298Sets (+set, +in) use `hor` for their horizontal order and `vor` for their
299vertical order. See [`apt:in`](@/docs/reference/library/2h.md) to see how a set verifies its correctness.
300`vor` is used to verify.
302---
303### `++lor`
305Leg order
307Computes whether the corresponding legs of `a` and `b` are in ascending
308numeric order, producing a flag.
310#### Accepts
312`a` is a noun.
314`b` is a noun.
316#### Accepts
318A flag.
320#### Source
322```
323 ++ lor
324 ~/ %lor
325 |= [a=* b=*]
326 ^- ?
327 ?: =(a b) &
328 ?@ a
329 ?^ b &
330 (lth a b)
331 ?: =(-.a -.b)
332 $(a +.a, b +.b)
333 $(a -.a, b -.b)
334```
336#### Examples
338```
339 > (lor 1 2)
340 %.y
342 > (lor 2 1)
343 %.n
345 > (lor 9 [1 2])
346 %.y
348 > (lor `(list @)`[1 2 3 ~] `(list @)`[1 2 3 4 ~])
349 %.y
351 > (lor `(list @)`[1 2 3 ~] `(list @)`[1 2 2 ~])
352 %.n
354 > (lor `(list @)`[1 2 3 ~] `(list @)`[2 2 ~])
355 %.y
357 > (lor [2 2 5] [1 5 9 8])
358 %.n
360 > (lor [1 5 8] [1 5 9 8])
361 %.y
363 > (lor [1 2 3] [1 2])
364 !! exit
365```
367#### Discussion
369`lor` is no longer used internally.
371---
372### `++vor`
374Vertical order
376Computes whether the double-hashes `(mug (mug a))` and `(mug (mug b))` are in
377ascending numeric order, producing a flag. If the double-`mug` hashes are
378equal, `a` and `b` are compared by `dor` instead.
380[`mug`](@/docs/reference/library/2e.md) is the the 31-bit nonzero FNV-1a hash algorithm.
383#### Accepts
385`a` is a noun
387`b` is a noun
389#### Produces
391A flag.
393#### Source
395```
396 ++ vor
397 ~/ %vor
398 |= [a=* b=*]
399 ^- ?
400 =+ [c=(mug (mug a)) d=(mug (mug b))]
401 ?: =(c d)
402 (dor a b)
403 (lth c d)
404```
406#### Examples
408```
409 > (vor 'f' 'g')
410 %.y
412 > [(mug 'f') (mug 'g')]
413 [1.661.740.952 1.644.963.335]
415 > [(mug (mug 'f')) (mug (mug 'g'))]
416 [261.421.509 1.861.258.547]
418 > (vor 'a' 'z')
419 %.n
421 > (vor 43.326 41.106)
422 %.n
423```
425#### Discussion
427Maps, sets, and queues all use `vor` to check for vertical ordering. Maps and
428sets also use `gor` and `hor` for horizontal order, respectively, but queues use
429vertical ordering alone.
431Since hashing removes correlation, double-`mug`ging with `vor` removes
432correlation with single-`mug`ged `hor`. Vertical order becomes uncorrelated
433with horizontal order.
436---