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: tomas
Subject: Re: How to read an integer from the minibuffer
Date: Fri, 12 Nov 2021 21:24:25 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

On Fri, Nov 12, 2021 at 11:02:10PM +0300, Jean Louis wrote:
> Improved check for number:
> 
> (defun string-is-number-p (s)
>   "Return number only if string is actual number, otherwise NIL."
>   (let* ((s (string-trim s)))
>     (cond ((seq-empty-p s) nil)
>         ((string-match "[^0123456789\\.-]" s) nil)
>         ((string-match "-" s 1) nil)
>         ((numberp (string-to-number s)) (string-to-number s)))))

Why not simply numberp?

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

Cheers
 - t

Attachment: signature.asc
Description: Digital signature


reply via email to

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