Allow underscore as separator for number literals

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 538
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Re: Allow underscore as separator for number literals

Post by Sicro »

BarryG wrote:
Sicro wrote:The apostrophe is not yet used in the PureBasic language
Yes it is, to convert literal characters to their ASCII value:
Right. I forgot, although I often use it when working with string pointers. But it is the only case where the apostrophes are used.
Image
Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
User avatar
Tenaja
Addict
Addict
Posts: 1948
Joined: Tue Nov 09, 2010 10:15 pm

Re: Allow underscore as separator for number literals

Post by Tenaja »

Sicro wrote:
BarryG wrote:
Sicro wrote:The apostrophe is not yet used in the PureBasic language
Yes it is, to convert literal characters to their ASCII value:
Right. I forgot, although I often use it when working with string pointers. But it is the only case where the apostrophes are used.
Whether they are used elsewhere is moot. Numbers are used in identifiers, yet you can also use them in literal constants too. The separator would be treated the same, but would not be allowed as the leading character.
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 538
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Re: Allow underscore as separator for number literals

Post by Sicro »

Tenaja wrote:Whether they are used elsewhere is moot. Numbers are used in identifiers, yet you can also use them in literal constants too. The separator would be treated the same, but would not be allowed as the leading character
I think it always makes sense to look where a character is already used in the syntax to avoid making parsing the code unnecessarily more complicated or to avoid confusion when reading the code.

@All: Which character as number separator would you prefer?
In the meantime, I also tend to use apostrophes.
Image
Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Allow underscore as separator for number literals

Post by Josh »

Sicro wrote:I think it always makes sense to look where a character is already used in the syntax to avoid making parsing the code unnecessarily more complicated or to avoid confusion when reading the code.
Characters with multiple usage:

$ String identifier
$ Hexadecimal literal

% Modulo operator
% Binary literal

~ Bitwise NOT operator
~ Escaped string literal

# Constant
# Separator in macros

The above characters are used several times without problems (ok, the hash sign as separator in macros I find suboptimal, but it' s the way it is).


The single quotation mark as a separator in numeric literals would not lead to any conflicts and in my humble opinion it would be better to read than with an underscore.
sorry for my bad english
User avatar
Tenaja
Addict
Addict
Posts: 1948
Joined: Tue Nov 09, 2010 10:15 pm

Re: Allow underscore as separator for number literals

Post by Tenaja »

Josh, you skipped all of the numbers and letters that can make numbers as well as identifiers.

Sure, it makes sense to revaluate double use, but this is actually a perfect use case. I've used compilers that have done it.
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Allow underscore as separator for number literals

Post by Little John »

Something like this has been requested already more than 7 years ago:
Commas in numbers
User avatar
Tenaja
Addict
Addict
Posts: 1948
Joined: Tue Nov 09, 2010 10:15 pm

Re: Allow underscore as separator for number literals

Post by Tenaja »

Comma would never work because it's a procedure parameter separator.
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Allow underscore as separator for number literals

Post by Little John »

Tenaja wrote:Comma would never work because it's a procedure parameter separator.
If you read the whole thread, then you'll see that there was not only discussed about commas. It's also not necessary to repeat that old descussion again now.
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Allow underscore as separator for number literals

Post by #NULL »

Little John wrote:Something like this has been requested already more than 7 years ago:
Commas in numbers
freaks solution is both clever and stupid. :P
underscore please. I'm not waiting for it though.
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Allow underscore as separator for number literals

Post by Little John »

#NULL wrote:underscore please. I'm not waiting for it though.
Exactly the same for me.
User avatar
Tenaja
Addict
Addict
Posts: 1948
Joined: Tue Nov 09, 2010 10:15 pm

Re: Allow underscore as separator for number literals

Post by Tenaja »

Little John wrote:
Tenaja wrote:Comma would never work because it's a procedure parameter separator.
If you read the whole thread, then you'll see that there was not only discussed about commas. It's also not necessary to repeat that old descussion again now.
I have read this whole thread, as well as the one from 2013, which I also commented in. If we were required to refrain from duplication, we would have to delete this whole thread!

Statements of agreement, such as the one I made that you shunned, are merely comments. It was not, however, as unproductive than your presumptuous dig. Usually, you are a much more positive contributor than that.
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Allow underscore as separator for number literals

Post by Little John »

Tenaja wrote:It was not, however, as unproductive than your presumptuous dig. Usually, you are a much more positive contributor than that.
Just because you don't understand what it's all about, doesn't mean that you are allowed to take that tone with me!
User avatar
Lord
Addict
Addict
Posts: 847
Joined: Tue May 26, 2009 2:11 pm

Re: Allow underscore as separator for number literals

Post by Lord »

Even if I don't like number seperators,
there are some characters left: ^°´`
for separetion.
Image
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: Allow underscore as separator for number literals

Post by BarryG »

I don't think there's any point to this request anyway, because when you copy source codes from somewhere else (C++, StackOverflow, etc) then the separators aren't going to be there anyway. Are you going to manually change every number from the copied code?

So, -1 from me.
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Allow underscore as separator for number literals

Post by TI-994A »

A prefix should be implemented to indicate such formatting, similar to the tilde (~) for escaping strings. Best to keep literals and formatting separate.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Post Reply