emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Internationalize Emacs's messages (swahili)


From: Lars Ingebrigtsen
Subject: Re: Internationalize Emacs's messages (swahili)
Date: Sun, 27 Dec 2020 00:04:05 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

I whipped one up quickly.  The slightly interesting thing here is that
we have an opportunity here to make this slightly faster -- since we
have an upper length bound here, we can eschew the tortoise/hare
FOR_EACH_TAIL bit and just follow CDRs, which would be faster.  Of
course, if you give it a circular list, then it'll always return Qnil,
and if you give it (expt most-positive-fixnum most-positive-fixnum) on a
circular list, it'll take a while...

diff --git a/src/fns.c b/src/fns.c
index 646c3ed083..2234818e8e 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -145,6 +145,29 @@ DEFUN ("safe-length", Fsafe_length, Ssafe_length, 1, 1, 0,
   return make_fixnum (len);
 }
 
+DEFUN ("length<", Flength_less, Slength_less, 2, 2, 0,
+       doc: /* Return non-nil if SEQUENCE is shorter than LENGTH.
+See `length' for allowed values of SEQUENCE.  */)
+  (Lisp_Object sequence, Lisp_Object length)
+{
+  CHECK_INTEGER (length);
+  EMACS_INT len = XFIXNUM (length);
+
+  if (CONSP (sequence))
+    {
+      intptr_t i = 0;
+      FOR_EACH_TAIL (sequence)
+       {
+         i++;
+         if (i >= len)
+           return Qnil;
+       }
+      return Qt;
+    }
+  else
+    return XFIXNUM (Flength (sequence)) < len? Qt: Qnil;
+}
+
 DEFUN ("proper-list-p", Fproper_list_p, Sproper_list_p, 1, 1, 0,
        doc: /* Return OBJECT's length if it is a proper list, nil otherwise.
 A proper list is neither circular nor dotted (i.e., its last cdr is nil).  */
@@ -5721,6 +5744,7 @@ syms_of_fns (void)
   defsubr (&Srandom);
   defsubr (&Slength);
   defsubr (&Ssafe_length);
+  defsubr (&Slength_less);
   defsubr (&Sproper_list_p);
   defsubr (&Sstring_bytes);
   defsubr (&Sstring_distance);

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




reply via email to

[Prev in Thread] Current Thread [Next in Thread]