www.digitalmars.com         C & C++   DMDScript  

D - Integer constants

reply Matt Gessner <mattg aiinet.com> writes:
Hi, all,

One thing that I loved in Ada (keep reading...) was that integer
constants could contain an underscore '_', ASCII 95, to be used
as a separator... i.e.

	1_000_000 or
       0xFFFF_FFFF or even better

0b1111_1111_1111_1111_1111_1111_1111_1111

I know this isn't a hard thing to put into the lexical scanner;
Walter: Do you think this would be useful?  Personally, as a
programmer for 19 years, I think that although it's a small
thing, I think it would be beneficial.

I'm looking forward to using this language!

Regards,

Matt Gessner
Aug 16 2001
parent reply "Walter" <walter digitalmars.com> writes:
Yes, it would be easy to put in the scanner.  I remember looking at the Ada
spec in 1979 and thinking then it was unimplementable <g>.

Matt Gessner wrote in message <3B7C151A.1060706 aiinet.com>...
Hi, all,

One thing that I loved in Ada (keep reading...) was that integer
constants could contain an underscore '_', ASCII 95, to be used
as a separator... i.e.

 1_000_000 or
       0xFFFF_FFFF or even better

0b1111_1111_1111_1111_1111_1111_1111_1111

I know this isn't a hard thing to put into the lexical scanner;
Walter: Do you think this would be useful?  Personally, as a
programmer for 19 years, I think that although it's a small
thing, I think it would be beneficial.

I'm looking forward to using this language!

Regards,

Matt Gessner
Aug 17 2001
parent reply Russell Bornschlegel <kaleja estarcion.com> writes:
Walter wrote:
 
 Yes, it would be easy to put in the scanner.  I remember looking at the Ada
 spec in 1979 and thinking then it was unimplementable <g>.
 
 Matt Gessner wrote in message <3B7C151A.1060706 aiinet.com>...
Hi, all,

One thing that I loved in Ada (keep reading...) was that integer
constants could contain an underscore '_', ASCII 95, to be used
as a separator... i.e.
While we're on the subject of integer constants, what do people think of abolishing the leading-zero notation for octal? - Octal is rarely used today except in the specification of unixy file permissions; in any case, we're not worried about C compatibility, right? - Unlike 0x or 0b, a leading zero in traditional mathematical notation is well-defined as a no-op, and having it mean "octal" is non-intuitive to anyone not coming from a C-language-family background. - Being able to specify octals is still useful, so for consistency we should provide a 0-letter prefix like 0x or 0b. However, 0o is misreadable (especially as 0O (zero-capital-oh)), and 0e ("eight") is confusable with scientific notation in the C/Fortran family. I could argue for 0c, but that might be too cute. Does anyone like the leading-zero octal notation? Does anyone ever get burned by it, intending a decimal value but accidentally specifying an octal? Will people get burned by removing the leading zero notation? Is this more attention than anyone cares to spend on octal? :) -Russell B
Aug 17 2001
next sibling parent reply Charles Hixson <charleshixsn earthlink.net> writes:
Russell Bornschlegel wrote:
 
...
 While we're on the subject of integer constants, what do people 
 think of abolishing the leading-zero notation for octal? 
 
 - Octal is rarely used today except in the specification of unixy
 ...
 
 -Russell B
 
I find this "plausible", but only in the context of some more general way to specify a base. Ideally I'd like to be able to specify an aggregation of characters to be used for display, etc. But it should certainly be feasible to specify any desired base up to 36, up to 62 (letters by case + digits). If two more chars could be added, then bases up to 64 could be handled. Most of this isn't used often, and it would certainly be better if it could be deferred, but in the languages that I've encountered, the specification of number representations is always frozen at an early stage, and there's no way to alter it later. Along this same line, the relation between the quote and the string class is important. There needs to be some way for descendants of the string class to specify constants. I'd really like it if they could, perhaps, override the quote operations, so that one could say, e.g., Unicode."This is a test", and have the quoted text processed by a quote as defined by the unicode class. If there's a better way, I'd like to hear what it is.
Aug 17 2001
parent reply Russell Bornschlegel <kaleja estarcion.com> writes:
Charles Hixson wrote:
 
 Russell Bornschlegel wrote:

 ...
 While we're on the subject of integer constants, what do people
 think of abolishing the leading-zero notation for octal?

 - Octal is rarely used today except in the specification of unixy
 ...

 -Russell B
I find this "plausible", but only in the context of some more general way to specify a base. Ideally I'd like to be able to specify an aggregation of characters to be used for display, etc. But it should certainly be feasible to specify any desired base up to 36, up to 62 (letters by case + digits). If two more chars could be added, then bases up to 64 could be handled.
a prefix (for "radix"): int permissions = 0r8.0377; // octal int magic = 0r16.DEADBEEF; // hexadecimal int key = 0r32.04PA; // base-32... I fear the case distinction for a lot of reasons, so I'd personally limit it to radix-36 at max. -RB
Aug 17 2001
parent reply "Sean L. Palmer" <spalmer iname.com> writes:
 While we're on the subject of integer constants, what do people
 think of abolishing the leading-zero notation for octal?

 a prefix (for "radix"):

 int permissions = 0r8.0377; // octal
 int magic = 0r16.DEADBEEF; // hexadecimal
 int key = 0r32.04PA; // base-32...

 I fear the case distinction for a lot of reasons, so I'd personally
 limit it to radix-36 at max.
I like this radix thing. I've never seen the 0b101010 form before, but I would like to have it in the standard. I often have need to specify a large value in binary, never a need for octal so far in my career. Sean
Oct 25 2001
parent reply "Walter" <walter digitalmars.com> writes:


"Sean L. Palmer" <spalmer iname.com> wrote in message
news:9r9v50$2as9$1 digitaldaemon.com...
 While we're on the subject of integer constants, what do people
 think of abolishing the leading-zero notation for octal?

 a prefix (for "radix"):

 int permissions = 0r8.0377; // octal
 int magic = 0r16.DEADBEEF; // hexadecimal
 int key = 0r32.04PA; // base-32...

 I fear the case distinction for a lot of reasons, so I'd personally
 limit it to radix-36 at max.
I like this radix thing. I've never seen the 0b101010 form before, but I would like to have it in the standard. I often have need to specify a
large
 value in binary, never a need for octal so far in my career.

 Sean
Nov 17 2001
next sibling parent "Pavel Minayev" <evilone omen.ru> writes:
"Walter" <walter digitalmars.com> wrote in message
news:9t6ha7$24e9$1 digitaldaemon.com...


 has anyone else?
I believe it could be useful in some cases. Say, fuzzy logic. Besides, it's quite easy to implement.
Nov 17 2001
prev sibling parent Russell Borogove <kaleja estarcion.com> writes:
Walter wrote:
 

Occasionally I've felt the need for radix-36 (0-9+A-Z), but mostly it's a nice generalization. -RB
Nov 17 2001
prev sibling parent reply "Robert W. Cunningham" <rwc_2001 yahoo.com> writes:
Russell Bornschlegel wrote:

 While we're on the subject of integer constants, what do people
 think of abolishing the leading-zero notation for octal?
Heck, I learned ASCII in octal! (That's the only way DEC expressed it, and DEC made the PDP and VAX systems I learned on.) It took me years to become able to "think" ASCII in hex! IIRC, all the "big iron" from the late 70's and early 80's (IBM, Burroughs, UNISYS (Sperry/Univac), Control Data, etc.) used octal, especially for machine language programming. The reason may have had more to do with the user interface than anything else: Sending the mixed letters and numerals required by hexadecimal notation caused more shift-in and shift-out codes to be stuffed into the tty code stream. Long after ASCII was accepted "inside" computers, many peripherals were still speaking in various other encodings. Anyone recall Baudot lookup tables? Five and seven level paper tape encodings? Hollerith? So, if all those interfaces are truly dead and buried, it may be time to bury octal notation as well. As part of a language definition, that is. I'm still a fan of arbitrary base and arbitrary length numeric systems. Sometimes, a problem is just easier to solve in base 13... -BobC
Aug 18 2001
parent Christophe de Dinechin <descubes earthlink.net> writes:
"Robert W. Cunningham" wrote:

 So, if all those interfaces are truly dead and buried, it may be time to bury
 octal notation as well.  As part of a language definition, that is.  I'm still
a
 fan of arbitrary base and arbitrary length numeric systems.  Sometimes, a
 problem is just easier to solve in base 13...
For information, the LX notation is: 16#FFFF_FFFE 13#ABC One corner case for scientific notation in bases >= 15: 16#FF.00#E2 = 255.00 * 16 * 16 Someone proposed a 0r<base> notation which is similar. If D has no better use for Christophe
Aug 18 2001