~sircmpwn/hare-dev

4 4

Proposal: digit separator

Details
Message ID
<wekk4GO4F4o6SJkEo8_fSfobRCc4g9CIRsomrlTnTMn61szREIqWve3DVVpDeDUAB7gMltq-YgugjJ4pKqtDPK-0RSZUnvCE13vEzdOD5Q0=@pm.me>
DKIM signature
missing
Download raw message
Pre-emptive apologies, if it would have been better to post this in hare-rfc instead.

Digit separators are useful for breaking up long numbers, e.g. in english: 1,000,000,000 is easier to visually parse than 1000000000. They're common in modern programming languages. Even C has a digit separator after C23. 

The most common separator is `_`, as in `1_000_000_000`.
C and C++ use `'` as the separator, as in `1'000'000'000`.

I propose that Hare allows the use of a separator, probably `_`, in integer (and float?) literals. This is a non-breaking change that will ideally only affect the lexer.

Some details worth clarifying before implementation:
- Allow more than one separator in a row, like `1__000_____0`?
- Allow trailing separators, like `1_000_`?
- Allow separators immediately after an integer prefix, like `0x_ACAB`?
- Allow separators before a type suffix, like `420_i32`?
- Allow separators in float literals: is `1_000_000.00` ok? what about `1.000_000_001`?
- Update the `strconv::sto*` functions to allow separators? (probably not)
Details
Message ID
<CWUVN3QZ7E8C.2W314DDKY8PZA@d2evs.net>
In-Reply-To
<wekk4GO4F4o6SJkEo8_fSfobRCc4g9CIRsomrlTnTMn61szREIqWve3DVVpDeDUAB7gMltq-YgugjJ4pKqtDPK-0RSZUnvCE13vEzdOD5Q0=@pm.me> (view parent)
DKIM signature
missing
Download raw message
i'd be open to this. i think we've discussed it at some point in the
past but i don't think it went anywhere

On Fri Nov 10, 2023 at 12:26 AM UTC, JTurtle wrote:
> I propose that Hare allows the use of a separator, probably `_`, in integer (and float?) literals. This is a non-breaking change that will ideally only affect the lexer.

i'm in favor of _ as the separator, and i think we should probably? do
it for both integers and floats

> Some details worth clarifying before implementation:
> - Allow more than one separator in a row, like `1__000_____0`?
> - Allow trailing separators, like `1_000_`?
> - Allow separators immediately after an integer prefix, like `0x_ACAB`?
> - Allow separators before a type suffix, like `420_i32`?
> - Allow separators in float literals: is `1_000_000.00` ok? what about `1.000_000_001`?

sure, unless for some reason it's hard to specify

> - Update the `strconv::sto*` functions to allow separators? (probably not)

probably not, the lexer can get rid of them before passing them to
strconv::
Details
Message ID
<CWVCCH68P7SK.1SOE18YIFUIDR@torresjrjr.com>
In-Reply-To
<CWUVN3QZ7E8C.2W314DDKY8PZA@d2evs.net> (view parent)
DKIM signature
missing
Download raw message
+1 for _

On Fri Nov 10, 2023 at 5:19 AM GMT, Ember Sawady wrote:
> i'd be open to this. i think we've discussed it at some point in the
> past but i don't think it went anywhere

I suggested this feature myself on IRC ages ago. Drew struck it down,
but perhaps his mind has changed.

> On Fri Nov 10, 2023 at 12:26 AM UTC, JTurtle wrote:
> > I propose that Hare allows the use of a separator, probably `_`, in
> > integer (and float?) literals. This is a non-breaking change that
> > will ideally only affect the lexer.
>
> i'm in favor of _ as the separator, and i think we should probably? do
> it for both integers and floats

+1

> > Some details worth clarifying before implementation:
> > - Allow more than one separator in a row, like `1__000_____0`?
> > - Allow trailing separators, like `1_000_`?
> > - Allow separators immediately after an integer prefix, like `0x_ACAB`?
> > - Allow separators before a type suffix, like `420_i32`?
> > - Allow separators in float literals: is `1_000_000.00` ok? what about `1.000_000_001`?
>
> sure, unless for some reason it's hard to specify

+1

> > - Update the `strconv::sto*` functions to allow separators? (probably not)
>
> probably not, the lexer can get rid of them before passing them to
> strconv::

+1
Details
Message ID
<CWVYAT0GH9S4.39AYPQYZS5ZKT@taiga>
In-Reply-To
<CWVCCH68P7SK.1SOE18YIFUIDR@torresjrjr.com> (view parent)
DKIM signature
missing
Download raw message
On Fri Nov 10, 2023 at 7:25 PM CET, Byron Torres wrote:
> +1 for _
>
> On Fri Nov 10, 2023 at 5:19 AM GMT, Ember Sawady wrote:
> > i'd be open to this. i think we've discussed it at some point in the
> > past but i don't think it went anywhere
>
> I suggested this feature myself on IRC ages ago. Drew struck it down,
> but perhaps his mind has changed.

I still don't think it's all that, but I'm not going to block it. I
guess there are a few places where I would benefit from a _ digit
separator.
Details
Message ID
<CWWFNR9PTS9F.ZOL8NFYFSIN@smlavine.com>
In-Reply-To
<CWUVN3QZ7E8C.2W314DDKY8PZA@d2evs.net> (view parent)
DKIM signature
missing
Download raw message
Would we want to actually enforce that the digit separator "makes
sense", i.e. actually separating the hundreds, thousands, etc? I don't
believe Rust does, not sure on C++. I don't think we should. The easiest
way to implement would probably be just to allow and ignore `_` in number
literals.
Reply to thread Export thread (mbox)