|
From: | Emanuel Berg |
Subject: | Re: How to read an integer from the minibuffer |
Date: | Tue, 16 Nov 2021 07:24:54 +0100 |
User-agent: | Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) |
Jean Louis wrote: > I do not see how it helps in my use case as I want to ensure > that number in the string is actual number and nothing else. See this function, it is a workaround. But the problem is that `string-to-number' returns 0 on "0" (which is good) but also on "not a number". Don't know what genious came up with that since it is an obvious collision/ambiguity. (defun read-integer () (let ((str) (str-number) (n) ) (cl-loop until (progn (setq str (read-string "integer: ")) (if (string= str "0") (setq n 0) (setq str-number (string-to-number str)) (unless (= str-number 0) (setq n str-number) )) (integerp n)) ) n) ) ;; (read-integer) -- underground experts united https://dataswamp.org/~incal
[Prev in Thread] | Current Thread | [Next in Thread] |