From: Eli Zaretskii <eliz@gnu.org>
To: Ramesh Nedunchezian <rameshnedunchezian@outlook.com>
Cc: 59531@debbugs.gnu.org
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 [thread overview]
Message-ID: <838rk0ye7t.fsf@gnu.org> (raw)
In-Reply-To: <TY2PR0101MB3693F7DD75CC1CCBA0EB9543DA0F9@TY2PR0101MB3693.apcprd01.prod.exchangelabs.com> (message from Ramesh Nedunchezian on Thu, 24 Nov 2022 11:44:43 +0530)
tags 59531 wishlist
thanks
> Date: Thu, 24 Nov 2022 11:44:43 +0530
> From: Ramesh Nedunchezian <rameshnedunchezian@outlook.com>
>
> `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.
next prev parent reply other threads:[~2022-11-24 8:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-24 6:14 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 Ramesh Nedunchezian
2022-11-24 8:00 ` Eli Zaretskii [this message]
2022-12-14 16:40 ` Robert Pluim
2022-12-16 6:28 ` Jean Louis
2022-11-24 10:08 ` Jean Louis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=838rk0ye7t.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=59531@debbugs.gnu.org \
--cc=rameshnedunchezian@outlook.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).