From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#59531: 29.0.50: An alternative to `string-to-number` which throws an error (or returns a NIL value) when input is non-parseable as number Date: Thu, 24 Nov 2022 10:00:06 +0200 Message-ID: <838rk0ye7t.fsf@gnu.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6618"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 59531@debbugs.gnu.org To: Ramesh Nedunchezian Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Nov 24 09:00:22 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oy79h-0001Xh-2U for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 24 Nov 2022 09:00:21 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oy79R-00013s-Bm; Thu, 24 Nov 2022 03:00:05 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oy79P-00012W-3R for bug-gnu-emacs@gnu.org; Thu, 24 Nov 2022 03:00:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oy79O-0000e8-IB for bug-gnu-emacs@gnu.org; Thu, 24 Nov 2022 03:00:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oy79O-0004ED-D9 for bug-gnu-emacs@gnu.org; Thu, 24 Nov 2022 03:00:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 24 Nov 2022 08:00:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59531 X-GNU-PR-Package: emacs Original-Received: via spool by 59531-submit@debbugs.gnu.org id=B59531.166927679616194 (code B ref 59531); Thu, 24 Nov 2022 08:00:02 +0000 Original-Received: (at 59531) by debbugs.gnu.org; 24 Nov 2022 07:59:56 +0000 Original-Received: from localhost ([127.0.0.1]:57083 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oy79H-0004D6-KO for submit@debbugs.gnu.org; Thu, 24 Nov 2022 02:59:55 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:47212) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oy79F-0004Cp-UP; Thu, 24 Nov 2022 02:59:54 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oy79A-0000c4-IY; Thu, 24 Nov 2022 02:59:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=ZJrFrpljopL1Ei3wLoztnCiQhpWskiZdKlUwYVfPEl4=; b=VEdNDfHVuT2sDZyxLjAY C+pgxzSXvGQx4lzCgM4lfSx7v2EPPwniDBFbfMZtb+jZvZOfCZBrKvIEP9rT1oYo5zEm+fE9a9DKt CDSYvNEQpnW9WPKsIlm0QzbC1eX0deb3NXtVj6QvLhbqjgQfy6AMcsfw0EtuGSInkt/TI5gxpXDIL uIA7gP7rJUTF9TOmHxEwMEizDYcKbUtTCxWYRyJWorIevyF3ySIw3nm5azeyu+imgqNaIG3HI3Ouq rEyp5VPSyj/zEKgKxlf9fps2/7cFNpGDMlJ9lbnzuUlm8SiYZpEPBpxT0QG6yCqxTzCd+/lGbGdHw nKrH2740K55ixw==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oy79A-0007K5-0F; Thu, 24 Nov 2022 02:59:48 -0500 In-Reply-To: (message from Ramesh Nedunchezian on Thu, 24 Nov 2022 11:44:43 +0530) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:248824 Archived-At: tags 59531 wishlist thanks > Date: Thu, 24 Nov 2022 11:44:43 +0530 > From: Ramesh Nedunchezian > > `string-to-number` returns ZERO if the input is not a number.   > > > This return value is not very helpful.  The choice of a number ZERO as "Not A Number" doesn't help one to distinguish between the following two cases > > (1) Input was a valid number, and it parses to number zero > > (2) Input was NOT a valid number, and it was forcibly reported as ZERO > > Consider amending `string-to-number` to throw an error (or return NIL) when the input is not parseable as a number, or providing an alternative API to validate numbers.  I am trying to parse some fields in an org table, and see if the field value is a number or not; Thanks. Changing the default behavior to signal an error is out of the question, since this is used in the Lisp reader and elsewhere, all over the place. It is very useful there. However, as an enhancement, we could have an additional optional argument to request that the function signal an error if the string cannot be parsed as a number. > If there is already an alternative to what I am trying to accomplish, I would appreciate a recipe. You could match the string to a regexp that validates its numerical appearance, before calling string-to-number.