]> git.eshelyaron.com Git - emacs.git/commitdiff
; Make 'value<' consider cons cell greater than all other objects
authorEshel Yaron <me@eshelyaron.com>
Fri, 29 Mar 2024 20:37:27 +0000 (21:37 +0100)
committerEshel Yaron <me@eshelyaron.com>
Fri, 29 Mar 2024 20:38:17 +0000 (21:38 +0100)
doc/lispref/sequences.texi
src/fns.c

index c9e4762487815a4deae451a972ea9a074994f84c..d22303b6f5d20ffd84b2c2946f1042b64af00e2d 100644 (file)
@@ -461,21 +461,27 @@ This function returns non-@code{nil} if @var{a} comes before @var{b} in
 the standard sorting order; this means that it returns @code{nil} when
 @var{b} comes before @var{a}, or if they are equal or unordered.
 
-The arguments @var{a} and @var{b} must have the same type.
-Specifically:
+@code{value<} compares @var{a} and @var{b} according to the following rules:
 
 @itemize @bullet
 @item
+Conses come after all other objects.
+@item
+Two conses are compared by their @code{car}s, and if the @code{car}s are
+equal or unordered then the conses are compared by their @code{cdr}s.
+@item
 Numbers are compared using @code{<} (@pxref{definition of <}).
 @item
 Strings are compared using @code{string<} (@pxref{definition of
-string<}) and symbols are compared by comparing their names as strings.
+string<}).
 @item
-Conses, lists, vectors and records are compared lexicographically.  This
-means that the two sequences are compared element-wise from left to
-right until they differ, and the result is then that of @code{value<} on
-the first pair of differing elements.  If one sequence runs out of
-elements before the other, the shorter sequence comes before the longer.
+Symbols are compared by comparing their names as strings.
+@item
+Lists, vectors and records are compared lexicographically.  This means
+that the two sequences are compared element-wise from first to last
+until they differ, and the result is then that of @code{value<} on the
+first pair of differing elements.  If one sequence runs out of elements
+before the other, the shorter sequence comes before the longer.
 @item
 Markers are compared first by buffer, then by position.
 @item
@@ -496,15 +502,6 @@ Examples:
 (value< [3 2 "a"] [3 2 "b"]) @result{} t
 @end example
 
-@noindent
-Note that @code{nil} is treated as either a symbol or an empty list,
-depending on what it is compared against:
-
-@example
-(value< nil '(0)) @result{} t
-(value< 'nib nil) @result{} t
-@end example
-
 @noindent
 There is no limit to the length of sequences (lists, vectors and so on)
 that can be compared, but @code{value<} may fail with an error if used
index db5e856d5bda0ca92b3d8cc378cf58a541438c8b..6fe75f203edfd5d2e4fd054be66aa4dccdbd049c 100644 (file)
--- a/src/fns.c
+++ b/src/fns.c
@@ -3044,8 +3044,6 @@ value_cmp (Lisp_Object a, Lisp_Object b, int maxdepth)
       if (BARE_SYMBOL_P (b))
        return string_cmp (XBARE_SYMBOL (a)->u.s.name,
                           XBARE_SYMBOL (b)->u.s.name);
-      if (CONSP (b) && NILP (a))
-       return -1;
       if (SYMBOLP (b))
        /* Slow-path branch when B is a symbol-with-pos.  */
        return string_cmp (XBARE_SYMBOL (a)->u.s.name, XSYMBOL (b)->u.s.name);
@@ -3070,11 +3068,7 @@ value_cmp (Lisp_Object a, Lisp_Object b, int maxdepth)
              goto tail_recurse;
            }
        }
-      if (NILP (b))
-       return 1;
-      else
-       goto type_mismatch;
-      goto tail_recurse;
+      goto type_mismatch;
 
     case Lisp_Vectorlike:
       if (VECTORLIKEP (b))
@@ -3187,6 +3181,10 @@ value_cmp (Lisp_Object a, Lisp_Object b, int maxdepth)
       eassume (0);
     }
  type_mismatch:
+  if (CONSP (a))
+    return 1;
+  if (CONSP (b))
+    return -1;
   xsignal2 (Qtype_mismatch, a, b);
 }