help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: How to read an integer from the minibuffer


From: Emanuel Berg
Subject: Re: How to read an integer from the minibuffer
Date: Tue, 16 Nov 2021 07:15:35 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Jean Louis wrote:

> That helped me realize I have to call function different:
>
> (defun string-is-positive-integer-p (s)
>   "Return number only if string is positive integer, otherwise
> NIL."

(checkdoc-current-buffer t)

  Argument ā€˜sā€™ should appear (as S) in the doc string

>   (let* ((s (string-trim s)))
>     (cond ((seq-empty-p s) nil)
>         ((string-match "[^0123456789\\.]" s) nil)

This regexp should be an interval or char class. (But I'm not
sure this calls for a regexp at all.)

>         ((numberp (string-to-number s)) (string-to-number s)))))

This function returns real numbers as well:

  (string-is-positive-integer-p "10.1") ; 10.1

Also, I think the predicates (certain functions with "-p" or
"p" as suffix) should return either t or nil, as in
(numberp 10.1) ; t

Instead, maybe

(defun positive-integer-p (n)
  (and (integerp n)
       (< 0 n) ))
;; (positive-integer-p  1.5) ; nil
;; (positive-integer-p  1)   ; t
;; (positive-integer-p  0)   ; nil
;; (positive-integer-p -1)   ; nil

https://dataswamp.org/~incal/emacs-init/math.el

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

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