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: Fri, 12 Nov 2021 20:25:30 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Jean Louis wrote:

>> We see a problem BTW that `string-to-number' returns 0
>> on error!
>
> That problem I have solved in rcd-utilities.el with:
>
> (defun string-is-number-p (s)
>   "Return number only if string is pure number,
> otherwise NIL."

  A number is said to be pure if

    1. It has even number of digits.
    2. All the digits are either 4 or 5.
    3. And the number is a palindrome.

  First few pure numbers are 44, 55, 4444, 4554, 5445, 5555 ... [1]

Also the familiar docstring functional parameter issue.

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

Use a char class or an interval?

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

(string-is-number-p "-0")
(string-is-number-p "-5.3")

[1] https://www.geeksforgeeks.org/find-the-first-n-pure-numbers/

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




reply via email to

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