Page 2 of 3
Re: Allow underscore as separator for number literals
Posted: Sun Feb 21, 2021 12:00 pm
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.
Re: Allow underscore as separator for number literals
Posted: Sun Feb 21, 2021 3:51 pm
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.
Re: Allow underscore as separator for number literals
Posted: Sun Feb 21, 2021 7:01 pm
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.
Re: Allow underscore as separator for number literals
Posted: Sun Feb 21, 2021 8:43 pm
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.
Re: Allow underscore as separator for number literals
Posted: Sun Feb 21, 2021 9:38 pm
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.
Re: Allow underscore as separator for number literals
Posted: Sun Feb 21, 2021 11:30 pm
by Little John
Something like this has been requested already more than 7 years ago:
Commas in numbers
Re: Allow underscore as separator for number literals
Posted: Mon Feb 22, 2021 1:02 am
by Tenaja
Comma would never work because it's a procedure parameter separator.
Re: Allow underscore as separator for number literals
Posted: Mon Feb 22, 2021 6:24 am
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.
Re: Allow underscore as separator for number literals
Posted: Mon Feb 22, 2021 7:26 am
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.
underscore please. I'm not waiting for it though.
Re: Allow underscore as separator for number literals
Posted: Mon Feb 22, 2021 7:34 am
by Little John
#NULL wrote:underscore please. I'm not waiting for it though.
Exactly the same for me.
Re: Allow underscore as separator for number literals
Posted: Mon Feb 22, 2021 5:39 pm
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.
Re: Allow underscore as separator for number literals
Posted: Mon Feb 22, 2021 7:01 pm
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!
Re: Allow underscore as separator for number literals
Posted: Tue Feb 23, 2021 9:31 am
by Lord
Even if I don't like number seperators,
there are some characters left: ^°´`
for separetion.
Re: Allow underscore as separator for number literals
Posted: Tue Feb 23, 2021 9:35 am
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.
Re: Allow underscore as separator for number literals
Posted: Tue Feb 23, 2021 11:25 am
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.