emacs-devel
[Top][All Lists]
Advanced

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

Use `floatp' for occurences of `(and (numberp <OBJ>) (not (integerp <OBJ


From: MON KEY
Subject: Use `floatp' for occurences of `(and (numberp <OBJ>) (not (integerp <OBJ>)))' idiom?
Date: Tue, 15 Jun 2010 16:24:27 -0400

The CL package's `subst' procedures has this conditional:

  (if (or cl-keys (and (numberp cl-old) (not (integerp cl-old))))

The tail of the `or' form seems to be a check for a floating point e.g.:

(let ((cl-old 3.3))
   (and (numberp cl-old) (not (integerp cl-old))))

(let ((cl-old 3))
   (and (numberp cl-old) (not (integerp cl-old))))

(let ((cl-old 3.3))
     (floatp cl-old))

(let ((cl-old 3))
     (floatp cl-old))

Is there any reason why this couldn't be replaced by `floatp'? e.g.:

,----
| (defun subst (cl-new cl-old cl-tree &rest cl-keys)
|   "Substitute NEW for OLD everywhere in TREE (non-destructively).
| Return a copy of TREE with all elements `eql' to OLD replaced by NEW.
| \nKeywords supported:  :test :test-not :key
| \n(fn NEW OLD TREE [KEYWORD VALUE]...)"
|   (if (or cl-keys (floatp cl-old))
|       (apply 'sublis (list (cons cl-old cl-new)) cl-tree cl-keys)
|     (cl-do-subst cl-new cl-old cl-tree)))
`----

Or, alternatively use `floatp-safe' above which seems to accomplish same?

This said, is there a reason why `floatp-safe' shouldn't evaluate `floatp'
as well? e.g.:

,----
| (defun floatp-safe (object)
|   "Return t if OBJECT is a floating point number.
| On Emacs versions that lack floating-point support, this function
| always returns nil."
|  (floatp object))
`----

This same idiom is used by the following other CL procedures:

 CL's `member*':

 (if (and (numberp cl-item) (not (integerp cl-item)))
 -->  (if (floatp cl-item)

 CL's `assoc*':

 (if (and (numberp cl-item) (not (integerp cl-item)))
 -->  (if (floatp cl-item)

Cl's compiler-macro `eql' _twice_ as:

 (if (and (numberp val) (not (integerp val)))
 --> (if (floapp val)

I also found use of this idiom is used with the following procedures:

eieio.el's `eieio--typep':

 ((eq type 'float)  (and (numberp val) (not (integerp val))))
 --> ((eq type 'float)  (floatp val))

caluclater.el's `calculator' twice:

 (and (numberp mh) (not (integerp mh)) (< mh 1))
 --> (and (floatp mh) (< mh 1))

 (and (numberp mh) (not (integerp mh)) (> mh 1))
 --> (and (floatp mh) (> mh 1))

Prob. there are other occurences in the subdirs e.g. lisp/*/*.el

--
/s_P\



reply via email to

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