diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2019-09-20 07:46:52 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2019-09-20 07:46:52 -0700 |
commit | 7a9ab728565c650e0631744e79e7e8a77f57e347 (patch) | |
tree | ace13a75f84dd65698821027fc081fd66c474222 | |
parent | dfc6ac6ad22e1d4c86ce7c201c5d42085ae29137 (diff) | |
download | txr-7a9ab728565c650e0631744e79e7e8a77f57e347.tar.gz txr-7a9ab728565c650e0631744e79e7e8a77f57e347.tar.bz2 txr-7a9ab728565c650e0631744e79e7e8a77f57e347.zip |
buffers: allow inequality comparison with less.
* lib.c (less_tab_init): Assign category 6 to BUF type, so
buffers are sorted after other types.
(less): Add BUF case.
* txr.1: Documented.
-rw-r--r-- | lib.c | 14 | ||||
-rw-r--r-- | txr.1 | 10 |
2 files changed, 21 insertions, 3 deletions
@@ -4563,6 +4563,7 @@ static void less_tab_init(void) type_prec[BGNUM] = 1; type_prec[FLNUM] = 1; type_prec[RNG] = 2; + type_prec[BUF] = 6; for (l = 0; l <= MAXTYPE; l++) for (r = 0; r <= MAXTYPE; r++) { @@ -4689,6 +4690,19 @@ tail: return nil; } + case BUF: + { + cnum ll = c_num(left->b.len); + cnum rl = c_num(right->b.len); + cnum len = min(ll, rl); + int cmp = memcmp(left->b.data, right->b.data, len); + + if (cmp < 0 || (cmp == 0 && ll < rl)) + return t; + + return nil; + } + break; default: internal_error("unhandled case in less function"); } @@ -17971,7 +17971,7 @@ and The .code less function is capable of comparing numbers, characters, symbols, strings, -as well as lists and vectors of these. +as well as lists and vectors of these. It can also compare buffers. If both arguments are the same object so that .mono @@ -18047,7 +18047,6 @@ Note that the empty list nil compared to a cons is handled by type-based precedence, described below. - Two vectors are compared by .code less lexicographically, similarly @@ -18063,6 +18062,10 @@ is the outcome of comparing those differing elements themselves with .codn less . +Two buffers are also compared by +.code less +lexicographically, as if they were vectors of integer byte values. + Two ranges are compared by .code less using lexicographic logic similar to conses and vectors. @@ -18088,7 +18091,8 @@ then .code less resolves the situation based on the following precedence: numbers and characters are less than ranges, which are less than strings, which are less -than symbols, which are less than conses, which are less than vectors. +than symbols, which are less than conses, which are less than vectors, +which are less than buffers. Note that since .code nil |