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: Drew Adams
Subject: RE: Internationalize Emacs's messages (swahili)
Date: Sun, 27 Dec 2020 15:41:15 -0800 (PST)

> Yes, I think <, = and > are the ones that are nice to have.  The /=, <=
> and >= are trivial to express via the others, so I didn't go there.

I agree with Stefan.  If you insist on defining
such predicates, please just do it in Lisp.

(defun length> (xs n)
  "Return non-nil if length of sequence XS is greater than N."
  (if (consp xs)
      (nthcdr n xs)
    (> (length xs) n)))

(defun length< (xs n)
  " Return non-nil if length of sequence XS is less than N."
  (if (consp xs)
      (null (nthcdr (1- n) xs))
    (< (length xs) n)))

(defun length= (xs n)
  " Return non-nil if length of sequence XS is N."
  (if (consp xs)
      (let ((ys  (nthcdr (1- n) xs)))
        (and ys  (null (cdr ys))))
    (= (length xs) n)))

or similar...
___

Of course, those can give values for some inputs
where the list is dotted, and raise errors for others.

But so can the C implementation you showed for `length<',
IIUC.  And testing for a `proper-list-p' anyway means
traversing the full list.

This is another reason I'm not crazy about Emacs adding
and promoting such predicates.  Better for users to try
to DTRT in any particular case.  Promoting these is likely
to encourage blind use.

At a minimum, the doc should say that if you want to be
sure a returned value makes sense then be sure the list
arg is a proper list.
___

An alternative (better, IMO), is to have such predicates
always return a nil or non-nil value.  The following
definitions do that.

For these definitions a dotted list acts just like the
same list without the dot, i.e., an atomic last cdr Z
is treated like (Z).  So the dotted list (a b . c)
behaves for these predicates just like (a b c).

And they apparently work fine for circular lists also.

(defun length> (xs n)
  "Return non-nil if length of sequence XS is greater than N."
  (if (atom xs)
      (> (length xs) n)
    (condition-case nil
        (nthcdr n xs)
      (error nil))))

(defun length< (xs n)
  "Return non-nil if length of sequence XS is less than N."
  (if (atom xs)
      (< (length xs) n)
    (condition-case nil
        (null (nthcdr (1- n) xs))
      (error t))))

(defun length= (xs n)
  "Return non-nil if length of sequence XS is N."
  (if (atom xs)
      (= (length xs) n)
    (condition-case nil
        (let ((ys  (condition-case nil
                       (nthcdr (1- n) xs)
                     (error nil))))
          (and ys  (null (cdr ys))))
      (error t))))



reply via email to

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