Sujet : Re: Hex string literals (was Re: C23 thoughts and opinions)
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.cDate : 19. Jun 2024, 11:17:45
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240619025524.144@kylheku.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-06-19, David Brown <
david.brown@hesbynett.no> wrote:
On 19/06/2024 00:00, Keith Thompson wrote:
David Brown <david.brown@hesbynett.no> writes:
On 18/06/2024 02:19, Keith Thompson wrote:
[...]
I forgot about digit separators.
C23 adds the option to use apostrophes as separators in numeric
constants: 123'456'789 or 0xdead'beef, for example. (This is
borrowed from C++. Commas are more commonly used in real life,
at least in my experience, but that wouldn't work given the other
meanings of commas.)
>
Commas would be entirely unsuitable here, since half the world uses
decimal commas rather than decimal points. I think underscores are a
nicer choice, used by many languages, but C++ could not use
underscores due to their use in user-defined literals, and C followed
C++.
C already uses '.' as the decimal point, though half the world uses ','.
>
Sure - a programming language has to pick /one/ such option. And since
C was written by Americans, they got to choose. (I don't mind - we use
a decimal point in the UK too.) However, if someone from one of several
European countries sees "1,234" they will read it as 1.234, not 1234.
This means using a comma as a separator would be a bad idea.
That is what I chose to integrate in TXR Lisp:
1> (+ 1,234.56 2,000)
3234.56
That format lets me copy and paste figures from the outside world (e.g.
financial or scientific reports or applications) and have them be
understood.
As you can see, commas are not used as separators between items; simple
whitespace is. That helps to make this possible.
The pic macro I developed also only outputs commas and decimal points.
1> (pic "#,###,###" 1)
" 1"
2> (pic "0,###,###" 1)
"0,000,001"
3> (pic "0,###,###.##" 1)
"0,000,001.00"
4> (pic "0,###_###.##" 1)
** expr-1:1: pic: insufficient arguments for format
4> (pic "0,###_###.##" 1 2)
"0,001_ 2.00"
I don't care about conventions outside of North America.
Computing is Amerian, basically. Almost any big co. you can think of,
current or historic, was or is American. IBM, DEC, Sun Microsystems,
Microsoft, Google, Apple, ...
Everyone doing any programming in any mainstream programming language
for which there are significant job postings has to begrudingly accept
the period as the fraction separator, and English keywords and function
names.
(I suspect that one day the world will convert to a single standard for
this, and it might not be far off.)
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca