From unknown Thu Jun 19 13:59:25 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#59531 <59531@debbugs.gnu.org> To: bug#59531 <59531@debbugs.gnu.org> Subject: Status: 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 Reply-To: bug#59531 <59531@debbugs.gnu.org> Date: Thu, 19 Jun 2025 20:59:25 +0000 retitle 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 reassign 59531 emacs submitter 59531 Ramesh Nedunchezian severity 59531 wishlist thanks From debbugs-submit-bounces@debbugs.gnu.org Thu Nov 24 01:20:58 2022 Received: (at submit) by debbugs.gnu.org; 24 Nov 2022 06:20:58 +0000 Received: from localhost ([127.0.0.1]:56940 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oy5bH-0001eI-Nr for submit@debbugs.gnu.org; Thu, 24 Nov 2022 01:20:58 -0500 Received: from lists.gnu.org ([209.51.188.17]:51612) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oy5bG-0001eB-MP for submit@debbugs.gnu.org; Thu, 24 Nov 2022 01:20:43 -0500 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 1oy5bG-0006W1-HS for bug-gnu-emacs@gnu.org; Thu, 24 Nov 2022 01:20:42 -0500 Received: from mail-sgaapc01olkn20821.outbound.protection.outlook.com ([2a01:111:f400:feab::821] helo=APC01-SG2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oy5bE-0003Y0-Fc for bug-gnu-emacs@gnu.org; Thu, 24 Nov 2022 01:20:42 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Qn/nlnyjIPHDDsaLtoGfCx1Igtf2G8OVKpTVz8LLDZb7s1wvsEZFgk0hYqtdifbYIkrPbRYUUok1gC/uI8LT9JuJ8K1Gfamg3rrYI/LCX3b81FTxxdY9fv7DpNLG9LuvfGqQyld5IHNOyVZOSL5Uyo4i6+S/rzz9KISc5Mz5zJJ/Ig6rtKjNPZdTuoYs3Fp/zaw9rWy3+b3/4HHtqasOAFVl2NrKWdM7BTONHUjoq4/N4ZL6j5+C46VXGl/O5o/gIlk7RyrxcyX2en6YluvCs5IrCZ/RgOdAcTy40dPicsHI7MQzcFyfp8kz+LtlalC+sV67nWXaqnRNhZY+TYHNsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Q4UdU0FOqDmmpJEPNWXYetuqXjCP7P/W6CXQi/lMnwk=; b=mIQPlkLmxrgHIbzd5EioyTAa3tWMsfBPDdVNyNrhervoRvV//Mq9uQUNk2pSl6Rxo0PXCnrGARsOSKAQJQGuGkptj26ToDyj2U7+waMz9FLFQoyHB31SZOHwgFRRV0zDdboky28G6aqpBO8NbbqQ9eeMWsoEf4nSixhByLwCQ+3cmljIPyKcH35adg1/EjvpGl0ddWAt1yvFSbIa+xCBbDiVgcWo7ZzMEYZcZVDjDqoKsmtC1mzt3hjQ5FLbU7D4p6B2gknQM1ELGTVlAmeqlpRl73F9ArQxhz771o9pzVNBJIxwOdL0J4I/vglVPC7fUN+p/aJaoeJlHG9TL78WiQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Q4UdU0FOqDmmpJEPNWXYetuqXjCP7P/W6CXQi/lMnwk=; b=HHsjvBE6OoQlyr3qtrJmnK3pIrpDyssjNVez6XPHaO3nXhya41EABt28MYFmnVk9o0QcMIoghmxLR0qjqWUtTiN4d4fsHF1I4NPC3Tlfl6QN1fMdezVSiRFEeExMwSV/bgZ71fKQCfIKOCWFTQpNbFHHjBvUrxHyMUQUUFYHik5nDC3Z4etaAL8YfXxDAt+bRrHDJ905ZdrX84ogUeLRvZ1jApK/j4KsGUQPgxph1rOz6+6A9+Xm7YGRRQhJhDMOuzTIkzQJmohx2IVnyxNtfxwPwQ1NOvUZlVI7D6QRNq8/ZiA5+XX1oqjizTNFpY4rWh38tkc1gUs6XS4a0VQCXw== Received: from TY2PR0101MB3693.apcprd01.prod.exchangelabs.com (2603:1096:404:800f::16) by SEZPR01MB4208.apcprd01.prod.exchangelabs.com (2603:1096:101:4e::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.19; Thu, 24 Nov 2022 06:15:33 +0000 Received: from TY2PR0101MB3693.apcprd01.prod.exchangelabs.com ([fe80::43e:15e5:fd5b:c74a]) by TY2PR0101MB3693.apcprd01.prod.exchangelabs.com ([fe80::43e:15e5:fd5b:c74a%4]) with mapi id 15.20.5834.018; Thu, 24 Nov 2022 06:15:33 +0000 Message-ID: Date: Thu, 24 Nov 2022 11:44:43 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.2 Content-Language: en-US To: bug-gnu-emacs@gnu.org From: Ramesh Nedunchezian Subject: 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-TMN: [91vZ6UC1AX3dd2WyAd3jVC3HO5t4ePBv] X-ClientProxiedBy: MA0PR01CA0020.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a01:b8::8) To TY2PR0101MB3693.apcprd01.prod.exchangelabs.com (2603:1096:404:800f::16) X-Microsoft-Original-Message-ID: <6abfa53b-b972-df64-6512-05e72a2c11e9@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TY2PR0101MB3693:EE_|SEZPR01MB4208:EE_ X-MS-Office365-Filtering-Correlation-Id: 80473c28-1d8a-4c17-988f-08dacde34b31 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bnH49IYX/dPWhm62IJ57unnuJ2j+rPiwdB9TpaUmCKvEVIWPEgn3qCRr2B9wfRD6LZeFpL1lFTgISZgsgr9Oay/d6Wo4vtRGdYSvS51yEFeOPslD3GBxKs4DZeQtgDt5T3UEi46l6W4IXcd4dBuCHgFFwTlwcZvczAwhqGwLFMoxIYtpVk6LWXANX5ftcxh+PkPoR0jqq/BvWpgrMJ3BjpbrNZil5vsXpqIlCMpCMOX62AOrnF2BOMLfcQV86s+eEUkvcKD1h0zvT+UbkLAc+lcI/8mc7uB5IRzYyYXpR/x3HWUSQ2c9gDKWr4A7A2xKiH3zyo+6W0ehYBrxJGN+u9W88jH1q7UXxhf9xiGG92TqNooOY7llY5SPw0saL9SHuWes8LfYwDZQy5NEsTkmt9L4g/0TxUOS9aF5nWwwJh93l5GSHDPO0SAirDz/qt6VWXmU41Kiim6F5x5i+Homhx7pfH1zfIX+V+htSgMdYXgWsEW3reHQt/vT0V3rgkZTXQCvgDJ7wVKWlR1+5VoebR2eWEfeWqy5r5EYlx0N2i3BofUFGe8PksjyebRu6HEJ/ldus2/vlAUwoxfEGq8dtSTplA6FZHywSnzIaaV8eFg= X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?VzZ6STFEUUNhZ3pESzhvYk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ant-Network-Message-Id: 80473c28-1d8a-4c17-988f-08dacde34b31 X-MS-Exchange-CrossTenant-AuthSource: TY2PR0101MB3693.apcprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Nov 2022 06:15:33.5109 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEZPR01MB4208 Received-SPF: pass client-ip=2a01:111:f400:feab::821; envelope-from=rameshnedunchezian@outlook.com; helo=APC01-SG2-obe.outbound.protection.outlook.com X-Spam_score_int: 2 X-Spam_score: 0.2 X-Spam_bar: / X-Spam_report: (0.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FORGED_MUA_MOZILLA=2.309, FREEMAIL_FROM=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.3 (/) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.6 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: `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 Content analysis details: (1.6 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 1.0 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail) 0.0 T_SPF_HELO_TEMPERROR SPF: test of HELO record failed (temperror) 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (rameshnedunchezian[at]outlook.com) -1.0 MAILING_LIST_MULTI Multiple indicators imply a widely-seen list manager 1.6 FORGED_MUA_MOZILLA Forged mail pretending to be from Mozilla `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; If there is already an alternative to what I am trying to accomplish, I would appreciate a recipe. From debbugs-submit-bounces@debbugs.gnu.org Thu Nov 24 02:59:55 2022 Received: (at 59531) by debbugs.gnu.org; 24 Nov 2022 07:59:56 +0000 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 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 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==; 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 Date: Thu, 24 Nov 2022 10:00:06 +0200 Message-Id: <838rk0ye7t.fsf@gnu.org> From: Eli Zaretskii To: Ramesh Nedunchezian In-Reply-To: (message from Ramesh Nedunchezian on Thu, 24 Nov 2022 11:44:43 +0530) Subject: Re: 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 References: MIME-version: 1.0 Content-type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 59531 Cc: 59531@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) 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. From debbugs-submit-bounces@debbugs.gnu.org Thu Nov 24 03:05:41 2022 Received: (at control) by debbugs.gnu.org; 24 Nov 2022 08:05:42 +0000 Received: from localhost ([127.0.0.1]:57122 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oy7Er-0004Ov-OO for submit@debbugs.gnu.org; Thu, 24 Nov 2022 03:05:41 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46136) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oy7Eq-0004Oh-05 for control@debbugs.gnu.org; Thu, 24 Nov 2022 03:05:40 -0500 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 1oy7Ef-0004rU-6K for control@debbugs.gnu.org; Thu, 24 Nov 2022 03:05:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=crUHRavVGkgUnKkNlpjgCRr+o7kWuYlgYf6yiLHnMvQ=; b=TjWzEf1t1aO/ +q2ljgejbmjSnmKwwA8SCbK5UnwLsP2Xwg7XmBhJj6bNKg2iheUM/yOKwB/Cu0GuUOu8pX/nsm5hL UDrplu0644MFRt/Oi+y39VynxIGTYCVLRbWULu26RFXTnGlkVPTgVlN5CfJe14RTfHn5eKw4EW9FD VnaCQG0fc/VQcFyWdF68+3LolVNZGs52LYTcKoPqTeJQZye1F2m2zkqZOtfId9MQDnQbOFL9hnpHp v+MfojRCnNwghU0+j4ZyiGV10tADnqsNL98+yUgjS4DZHWjscHCVvAC9+To1azCdXU4+Us4n4bQ0L 3oJ/tdeMpTH5/wa0sGtAcw==; 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 1oy7Ed-0002Ox-Uz for control@debbugs.gnu.org; Thu, 24 Nov 2022 03:05:28 -0500 Date: Thu, 24 Nov 2022 10:05:48 +0200 Message-Id: <835yf4ydyb.fsf@gnu.org> From: Eli Zaretskii To: control@debbugs.gnu.org (GNU bug tracker automated control server) In-Reply-To: (control@debbugs.gnu.org) Subject: Re: Processed (with 1 errors): Re: 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 References: <838rk0ye7t.fsf@gnu.org> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) severity 59531 wishlist thanks From debbugs-submit-bounces@debbugs.gnu.org Thu Nov 24 05:32:46 2022 Received: (at 59531) by debbugs.gnu.org; 24 Nov 2022 10:32:46 +0000 Received: from localhost ([127.0.0.1]:57389 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oy9XC-0006Ri-6m for submit@debbugs.gnu.org; Thu, 24 Nov 2022 05:32:46 -0500 Received: from stw1.rcdrun.com ([217.170.207.13]:39293) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oy9Wz-0006RM-DW for 59531@debbugs.gnu.org; Thu, 24 Nov 2022 05:32:44 -0500 Received: from localhost ([::ffff:102.82.241.226]) (AUTH: PLAIN admin, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 00000000000F6138.00000000637F483F.00003FBB; Thu, 24 Nov 2022 03:32:30 -0700 Date: Thu, 24 Nov 2022 13:08:20 +0300 From: Jean Louis To: Ramesh Nedunchezian Subject: Re: 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 Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/2.2.7+37 (a90f69b) (2022-09-02) X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 59531 Cc: 59531@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) * Ramesh Nedunchezian [2022-11-24 09:22]: > `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; > > If there is already an alternative to what I am trying to > accomplish, I would appreciate a recipe. I had the same problem, so I have solved it this way. (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))))) As in my case I liketo know that string is really representing number and nothing else. (string-is-number-p "Hello") ➜ nil (string-is-number-p "") ➜ nil (string-is-number-p "0") ➜ 0 (string-is-number-p "0a") ➜ nil (string-to-number "0a") ➜ 0 (string-is-number-p "0.1") ➜ 0.1 (string-is-number-p "-2.5121212") ➜ -2.5121212 My function may not be perfect. -- Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns In support of Richard M. Stallman https://stallmansupport.org/ From debbugs-submit-bounces@debbugs.gnu.org Wed Dec 14 11:40:36 2022 Received: (at 59531) by debbugs.gnu.org; 14 Dec 2022 16:40:36 +0000 Received: from localhost ([127.0.0.1]:40279 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p5Uo7-00052o-VC for submit@debbugs.gnu.org; Wed, 14 Dec 2022 11:40:36 -0500 Received: from mail-wr1-f49.google.com ([209.85.221.49]:35772) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p5Uo4-00052e-4Z for 59531@debbugs.gnu.org; Wed, 14 Dec 2022 11:40:34 -0500 Received: by mail-wr1-f49.google.com with SMTP id y16so333107wrm.2 for <59531@debbugs.gnu.org>; Wed, 14 Dec 2022 08:40:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:from:to:cc:subject:date:message-id :reply-to; bh=klk4ZCuXOWoEWC2NNdIp1BKxM1ymLeJMCrgWYD1ZFDY=; b=VsawYg6B8646LgBzRQ9cW/oaA+9X/4MBVjKwj+xqkPvIwig5BvPrNlihjh+mtPqY5c ITWBaxpO0Pg/FUX+Q4vOeQTtzoJ3/pi0+mEwB6/rRDYKdnulgMXrBTnmJYNHrO+kEo73 X5CWg2ofl8kxEJ8oGX2xoI0g9MyykPQWePn9Hv0KJR89DjxD14wdqAvmrPh8tcXC27Ok X8l+AkX+YiL8m2YcTqhHuzuoLi4Fb2lVSUfX+6Oii7XE7XsP3PDTQ7/VyeNqFgycJs/p oCndrcmROLpnhhNoJ5pvyXo5nFUivGxHqA9OGwS2+JDCosM4m7kSij08SLPR2REZOCVD 7sqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=klk4ZCuXOWoEWC2NNdIp1BKxM1ymLeJMCrgWYD1ZFDY=; b=nOTFG2Nel0Oo4TBvBeCB7saVQr1HxRofaAx/vCuv+KbqETpmKKVgqdszzXwW7D1q5l /AOWI1Ijk7R2Rtx/BX5YS2g9lFKNfXfEYPLwuI5QDufjmeueyrFQ5GMMCAFpodTV4vRR 9CVdppJeBG7hOVglDGlaENj6cwkoxdHAhohyl+psf5z41gbwiVvmblIxFZkR4Vmnd3b+ YSOIc6pxA5nmqX1KGPaWAygXzIfRTvFB914Jtd5j+vEaFKj50FpkN57OLWXySaON1D8j 2TYf+leaQzhjaRhs+gAKVGs1Mh8M5OlbBJM91pf/QYHkL9/iPa+l88WZfz4H2ACA13BC I3ig== X-Gm-Message-State: ANoB5pnJVRqEX0Yt0JEFpdSIGkLLs3Ij/mObY3gJJzwU3cJKhimpgLt0 7Acwljjsq2ByphjvBw/0kgIjwMXlMJM= X-Google-Smtp-Source: AA0mqf5v7JkLPWUlnwGrUGpW+rXBwHoirjFYNGFejxZEKEtrHtmkVIsOiu0Hf7YB/L3nz91O2A0f1A== X-Received: by 2002:adf:dc89:0:b0:242:55fe:e055 with SMTP id r9-20020adfdc89000000b0024255fee055mr17077327wrj.66.1671036025681; Wed, 14 Dec 2022 08:40:25 -0800 (PST) Received: from rltb ([82.66.8.55]) by smtp.gmail.com with ESMTPSA id l1-20020adfa381000000b002423a5d7cb1sm3287132wrb.113.2022.12.14.08.40.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Dec 2022 08:40:25 -0800 (PST) From: Robert Pluim To: Eli Zaretskii Subject: Re: 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 In-Reply-To: <838rk0ye7t.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 24 Nov 2022 10:00:06 +0200") References: <838rk0ye7t.fsf@gnu.org> Date: Wed, 14 Dec 2022 17:40:24 +0100 Message-ID: <87zgbqndl3.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 59531 Cc: 59531@debbugs.gnu.org, Ramesh Nedunchezian X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) >>>>> On Thu, 24 Nov 2022 10:00:06 +0200, Eli Zaretskii said: >> This return value is not very helpful.=C2=A0 The choice of a number = ZERO >> as "Not A Number" doesn't help one to distinguish between the >> following two cases >>=20 >> (1) Input was a valid number, and it parses to number zero >>=20 >> (2) Input was NOT a valid number, and it was forcibly reported as ZE= RO >>=20 >> 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.=C2=A0 I am trying to parse some >> fields in an org table, and see if the field value is a number or >> not; Eli> Thanks. Eli> Changing the default behavior to signal an error is out of the que= stion, Eli> since this is used in the Lisp reader and elsewhere, all over the = place. It Eli> is very useful there. Eli> However, as an enhancement, we could have an additional optional a= rgument to Eli> request that the function signal an error if the string cannot be = parsed as Eli> a number. `cl-parse-integer' already has such an argument, but it only works for integers. Alternatively, you could use `read-from-string' and check if it returns something of type `integer' or `float'. Robert --=20 From debbugs-submit-bounces@debbugs.gnu.org Fri Dec 16 01:29:05 2022 Received: (at 59531) by debbugs.gnu.org; 16 Dec 2022 06:29:05 +0000 Received: from localhost ([127.0.0.1]:47406 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p64DR-0004SF-D0 for submit@debbugs.gnu.org; Fri, 16 Dec 2022 01:29:05 -0500 Received: from stw1.rcdrun.com ([217.170.207.13]:47061) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p64DM-0004Rg-Ve for 59531@debbugs.gnu.org; Fri, 16 Dec 2022 01:29:02 -0500 Received: from localhost ([::ffff:197.239.4.25]) (AUTH: PLAIN admin, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 000000000010383B.00000000639C102E.00007617; Thu, 15 Dec 2022 23:29:01 -0700 Date: Fri, 16 Dec 2022 09:28:14 +0300 From: Jean Louis To: Robert Pluim Subject: Re: 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 Message-ID: References: <838rk0ye7t.fsf@gnu.org> <87zgbqndl3.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline In-Reply-To: <87zgbqndl3.fsf@gmail.com> User-Agent: Mutt/2.2.9+54 (af2080d) (2022-11-21) X-Spam-Score: 2.6 (++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: (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) ((strin [...] Content analysis details: (2.6 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 2.6 RCVD_IN_SBL RBL: Received via a relay in Spamhaus SBL [197.239.4.25 listed in zen.spamhaus.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record X-Debbugs-Envelope-To: 59531 Cc: Eli Zaretskii , 59531@debbugs.gnu.org, Ramesh Nedunchezian X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.6 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: (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) ((strin [...] Content analysis details: (1.6 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 2.6 RCVD_IN_SBL RBL: Received via a relay in Spamhaus SBL [197.239.4.25 listed in zen.spamhaus.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -1.0 MAILING_LIST_MULTI Multiple indicators imply a widely-seen list manager (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))))) I use this function to make sure string is number and it returns either the number of nil, and function is not exhaustive. Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns In support of Richard M. Stallman https://stallmansupport.org/