[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 09:00:43 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) |
Yuri Khan wrote:
>> (defun string-to-number-number (str)
>> (if (string= str "0")
>> 0
>> (let ((num (string-to-number str)))
>> (unless (zerop num)
>> num) )))
>> ;; (string-to-number-number "10")
>> ;; (string-to-number-number "1.5")
>> ;; (string-to-number-number "0")
>> ;; (string-to-number-number "-1.5")
>> ;; (string-to-number-number "-10")
>> ;; (string-to-number-number "not a number") ; nil
>
> ‘string-to-number’ has one more deficiency — it ignores additional
> non-digit characters.
>
> M-: (string-to-number "123foo") ; 123
I know, I don't know if this is really a problem tho ...
Maybe it can even be thought of as a feature, e.g.
(string-to-number "89.8 cm") ; 89.8
> You cannot build anything strict on such a lax parser.
Don't know how strict we will get but if we identify and patch
the singularities it will be something if not strict then at
least something that is useful.
But sure I think it should be changed in the C source ...
--
underground experts united
https://dataswamp.org/~incal
Re: How to read an integer from the minibuffer, Emanuel Berg, 2021/11/11
Re: How to read an integer from the minibuffer, Gregory Heytings, 2021/11/11
Re: How to read an integer from the minibuffer, Gregory Heytings, 2021/11/11