all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: Juanma Barranquero <lekktu@gmail.com>
Cc: Eli Zaretskii <eliz@gnu.org>, emacs-devel@gnu.org
Subject: Re: Inconsistency in `string-to-number'
Date: Tue, 01 Dec 2009 15:15:59 -0500	[thread overview]
Message-ID: <jwvhbsabglv.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <f7ccd24b0909041730j3ebfa3f4h5fc4728bb6301272@mail.gmail.com> (Juanma Barranquero's message of "Sat, 5 Sep 2009 02:30:39 +0200")

>> Actually it could also break code (tho it seems unlikely).  I wouldn't
>> mind postponing the fix to Emacs-23.2.  In the mean time, we need to
>> improve the docstring.
> The docstring was not improved, and we're now on the 23.2 track, so
> time for a reprieve.

Sorry, your email got misfiled.

> Reminder: The problem is the following inconsistency:

>   (string-to-number "1:")  =>  1
>   (string-to-number "1.2:")  =>  1
>   (string-to-number "1.2") =>  1.2

> Alas, the docstring talks about "leading spaces and tabs", but says
> nothing about trailing chars.

> Currently the behavior, depending of the first non-digit after the
> number, is as follows:

>  - \0, \s, \r, \n, \f and \t  => the number is read as a float (if
> base == 10) or integer, as intended.
>  - Any other char: the number is always interpreted as an integer.

> Possibilities:

>  0) Do nothing except clarifying the docs.
>      Pro: easier of all fixes.
>      Cons: inconsistency.

That would be documenting a bad behavior, so that would only be
acceptable if the new doc says "if there's something after the number,
you're on your own".

>  1) Disallow any trailing char.
>      Pro: follows the doc (sort of).
>      Cons: incompatibility with current uses of undocumented "1:", etc.

That's not a good option, no.  I know there is code out there in use
that relies on this behavior (I'm probably guilty myself), but I don't
know how to find it to fix it, so I'd rather stay away from this.

>  2) Allow only whitespace: the same chars that the float case admits right now.
>      Pro: quite intuitive (IMO), easy to implement.
>      Cons: Same as 1)

Indeed, same as above.

>  3) Allow any trailing char.
>      Pro: forgiving.
>      Cons: (unlikely) incompatibility with uses of undocumented "1.2:" => 1

That would be my choice.  The behavior is still fairly regular, so the
doc shouldn't be too scary, and it works about as well as now.

> I like 2), because it seems cleaner to just allow whitespace all
> around the number; it has a certain risk of incompatibility, though.
> 1) and 3) would require adding a new parameter to
> lread.c:isfloat_string() or somesuch; not hard, but not very clean.

I'd need to see the patch to pronouce myself on the uncleanliness.


        Stefan




  reply	other threads:[~2009-12-01 20:15 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-24  0:16 Inconsistency in `string-to-number' Davis Herring
2009-04-24 10:36 ` Eli Zaretskii
2009-04-24 11:45   ` Juanma Barranquero
2009-04-24 13:19     ` Eli Zaretskii
2009-04-24 14:13       ` Juanma Barranquero
2009-04-24 13:22     ` Stefan Monnier
2009-04-24 13:38       ` Juanma Barranquero
2009-04-24 14:06         ` Stefan Monnier
2009-04-24 14:16           ` Juanma Barranquero
2009-09-05  0:30           ` Juanma Barranquero
2009-12-01 20:15             ` Stefan Monnier [this message]
2009-12-04  3:21               ` Juanma Barranquero
2009-12-04  3:23                 ` Juanma Barranquero
2009-12-04 14:22                 ` Stefan Monnier

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvhbsabglv.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=lekktu@gmail.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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.