on 7fa97bd help sign in
422 lines 6.6 kB history raw
1---
2navhome: /docs/
3---
6# 2f: noun ordering
7### `++aor`
9Alphabetical order
11Computes whether `a` and `b` are in alphabetical order, producing a flag.
13#### Accepts
15`a` is a noun.
17`b` is a noun.
19#### Produces
21A flag.
23#### Source
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)
42#### Examples
44 > (aor 'a' 'b')
45 %.y
47 > (aor 'b' 'a')
48 %.n
50 > (aor 'a' 'a')
51 %.y
53 > (aor "foo" "bar")
54 %.n
56 > (aor "bar" "foo")
57 %.y
59 > (aor "abcdefz" "abcdefa")
60 %.n
62 > (aor "abcdefa" "abcdefz")
63 %.y
65 > (aor 10.000 17.000)
66 %.y
68 > (aor 10 9)
69 %.n
73***
74### `++dor`
76Numeric order
78Computes whether `a` and `b` are in ascending numeric order, producing a flag.
80#### Accepts
82`a` is a noun.
84`b` is a noun.
86#### Produces
88A flag.
90#### Source
92 ++ dor
93 ~/ %dor
94 |= [a=* b=*]
95 ^- ?
96 ?: =(a b) &
97 ?. ?=(@ a)
98 ?: ?=(@ b) |
99 ?: =(-.a -.b)
100 $(a +.a, b +.b)
101 $(a -.a, b -.b)
102 ?. ?=(@ b) &
103 (lth a b)
106#### Examples
108 > (dor 1 2)
109 %.y
111 > (dor 2 1)
112 %.n
114 > (dor ~[1 2 3] ~[1 2 4])
115 %.y
117 > (dor ~[1 2 4] ~[1 2 3])
118 %.n
120 > (dor `(list @)`~[99 100 10.000] ~[99 101 10.000])
121 %.y
123 > (dor ~[99 101 10.999] `(list @)`~[99 100 10.000])
124 %.n
126#### Discussion
128If `a` and `b` are both atoms, `dor` is equivalent to [`lte`](../1a). If they're
129cells, `dor` recurses on the heads, and then if the heads are the same it checks
130the tails.
132If one sample is a cell and the other is an atom, the cell sample is treated as
133"greater."
136***
137### `++gor`
139Hash order
141Computes whether of `(mug a)` and `(mug b)` are in ascending numeric order,
142producing a flag. If the `mug` hashes are equal, `a` and `b` are compared by
143`dor` instead.
145[`mug`](../2e) is the the 31-bit nonzero FNV-1a hash algorithm.
147#### Accepts
149`a` is a noun.
151`b` is a noun.
153#### Produces
155A flag.
157#### Source
159 ++ gor
160 ~/ %gor
161 |= [a=* b=*]
162 ^- ?
163 =+ [c=(mug a) d=(mug b)]
164 ?: =(c d)
165 (dor a b)
166 (lth c d)
169#### Examples
171 > (gor 'd' 'c')
172 %.y
174 > 'd'
175 'd'
177 > 'c'
178 'c'
180 > `@ud`'d'
181 100
183 > `@ud`'c'
184 99
186 > (mug 'd')
187 1.628.185.714
189 > (mug 'c')
190 1.712.073.811
192 > (gor 'd' 'c')
193 %.y
195 > (gor 'c' 'd')
196 %.n
198 > (gor "foo" "bar")
199 %.n
201 > (gor (some 10) `(list @)`[1 2 3 ~])
202 %.n
204#### Discussion
206`map`s use `gor` on the key for horizontal ordering and `vor` for
207vertical order. `map`s only look at the keys (the head of the key-value pair
208elements) for ordering.
210***
211### `++hor`
213Horizontal hash order
215If `a` and `b` are atoms, they are computed as samples of `gor`, producing a
216flag.
218If `a` and `b` are cells, `hor` checks to see if their heads are equal. If their
219heads are equal, `gor` is computed on their tails, producing a flag. If their
220heads are not equal, `gor` is computed on their heads, producing a flag.
222If `a` is an atom and `b` is not, then `%.y` is produced. If `b` is an atom and
223`a` is not, `%.n` is produced.
225#### Accepts
227`a` is a noun.
229`b` is a noun.
231#### Produces
233A flag.
235#### Source
237 ++ hor
238 ~/ %hor
239 |= [a=* b=*]
240 ^- ?
241 ?: ?=(@ a)
242 ?. ?=(@ b) &
243 (gor a b)
244 ?: ?=(@ b) |
245 ?: =(-.a -.b)
246 (gor +.a +.b)
247 (gor -.a -.b)
250#### Examples
252 > (hor . 1)
253 %.n
255 > (hor 1 2)
256 %.y
258 > (hor "abc" "cba")
259 %.y
261 > (hor 'c' 'd')
262 %.n
264 > (hor 100 [1 1])
265 %.y
267 > (hor [1 1] 100)
268 %.n
270 > (hor 500.000.000 "foo")
271 %.y
273 > (hor "foo" 500.000.000)
274 %.n
276 > (hor 0 "foo")
277 %.y
279 > (gor `(list @)`[0 ~] 1)
280 %.n
282 > (hor `(list @)`[50 500 5.000 ~] 1)
283 %.n
286#### Discussion
288Sets (+set, +in) use `hor` for their horizontal order and `vor` for their
289vertical order. See [`apt:in`](../2h) to see how a set verifies its correctness.
290`vor` is used to verify.
292***
293### `++lor`
295Leg order
297Computes whether the corresponding legs of `a` and `b` are in ascending
298numeric order, producing a flag.
300#### Accepts
302`a` is a noun.
304`b` is a noun.
306#### Accepts
308A flag.
310#### Source
312 ++ lor
313 ~/ %lor
314 |= [a=* b=*]
315 ^- ?
316 ?: =(a b) &
317 ?@ a
318 ?^ b &
319 (lth a b)
320 ?: =(-.a -.b)
321 $(a +.a, b +.b)
322 $(a -.a, b -.b)
325#### Examples
327 > (lor 1 2)
328 %.y
330 > (lor 2 1)
331 %.n
333 > (lor 9 [1 2])
334 %.y
336 > (lor `(list @)`[1 2 3 ~] `(list @)`[1 2 3 4 ~])
337 %.y
339 > (lor `(list @)`[1 2 3 ~] `(list @)`[1 2 2 ~])
340 %.n
342 > (lor `(list @)`[1 2 3 ~] `(list @)`[2 2 ~])
343 %.y
345 > (lor [2 2 5] [1 5 9 8])
346 %.n
348 > (lor [1 5 8] [1 5 9 8])
349 %.y
351 > (lor [1 2 3] [1 2])
352 !! exit
355#### Discussion
357`lor` is no longer used internally.
359***
360### `++vor`
362Vertical order
364Computes whether the double-hashes `(mug (mug a))` and `(mug (mug b))` are in
365ascending numeric order, producing a flag. If the double-`mug` hashes are
366equal, `a` and `b` are compared by `dor` instead.
368[`mug`](../2e) is the the 31-bit nonzero FNV-1a hash algorithm.
371#### Accepts
373`a` is a noun
375`b` is a noun
377#### Produces
379A flag.
381#### Source
383 ++ vor
384 ~/ %vor
385 |= [a=* b=*]
386 ^- ?
387 =+ [c=(mug (mug a)) d=(mug (mug b))]
388 ?: =(c d)
389 (dor a b)
390 (lth c d)
393#### Examples
395 > (vor 'f' 'g')
396 %.y
398 > [(mug 'f') (mug 'g')]
399 [1.661.740.952 1.644.963.335]
401 > [(mug (mug 'f')) (mug (mug 'g'))]
402 [261.421.509 1.861.258.547]
404 > (vor 'a' 'z')
405 %.n
407 > (vor 43.326 41.106)
408 %.n
411#### Discussion
413Maps, sets, and queues all use `vor` to check for vertical ordering. Maps and
414sets also use `gor` and `hor` for horizontal order, respectively, but queues use
415vertical ordering alone.
417Since hashing removes correlation, double-`mug`ging with `vor` removes
418correlation with single-`mug`ged `hor`. Vertical order becomes uncorrelated
419with horizontal order.
422***