digitalmars.D - Octal Literals
- Dave X. (11/11) Jul 17 2012 I'm a fresh college graduate who just got a job as a software
- Nick Sabalausky (13/25) Jul 17 2012 I wish D had been as far along as it is now back when I was in college!
- Dave X. (4/40) Jul 18 2012 Thanks! I guess I'll get used to it.
- travert phare.normalesup.org (Christophe Travert) (8/10) Jul 18 2012 By looking at the sources, if the template argument is a string, the
- Simen Kjaeraas (9/11) Jul 18 2012 It converts the passed number to a string, then works on a digit at a
- H. S. Teoh (7/19) Jul 18 2012 [...]
- Caligo (3/13) Jul 18 2012 This article by Walter might be of an interest to you:
- monarch_dodra (8/19) Jul 18 2012 Coming from C++, the only time I've EVER seen octals used is "by
- Andrei Alexandrescu (3/4) Jul 18 2012 This is never a good argument for adding things to a language.
- monarch_dodra (4/8) Jul 18 2012 Taken out of context, no it isn't. "It sounds like a good idea",
- Andrei Alexandrescu (4/13) Jul 18 2012 Yah, thought the same after posting, sorry. Nevertheless, 0o or whatnot
- Daniel Murphy (5/8) Jul 19 2012 It's a trivial amount of work to add '0o' octal literals to the language...
- Dave X. (4/4) Jul 19 2012 How was the reception of the idea of binary literals as opposed
- Daniel Murphy (3/6) Jul 19 2012 Binary literals were before my time, but AVR assembler also has them.
- David Nadlinger (4/8) Jul 19 2012 If they were introduced today, I guess they might well be
- Nick Sabalausky (9/13) Jul 19 2012 Binary literals have been there since way back around the beginning of
I'm a fresh college graduate who just got a job as a software developer, and I have been enthusiastically watching D for a while now (I program primarily in Java and C). I have some functional programming experience in Haskell and Scala as well. I like using octal numbers, and I've always been interested in D's octal literals. I'm glad to see that the traditional syntax of C's octal literals is being replaced by a more readable one. However, I can't help but think that the template solution ("octal!nnn") is a little too roundabout; is there a reason that that the "0o" prefix, which is already well established in languages like Haskell, OCaml, and Python, is not used?
Jul 17 2012
On Tue, 17 Jul 2012 23:53:47 +0200 "Dave X." <dxuhuang gmail.com> wrote:I'm a fresh college graduate who just got a job as a software developer, and I have been enthusiastically watching D for a while now (I program primarily in Java and C). I have some functional programming experience in Haskell and Scala as well.I wish D had been as far along as it is now back when I was in college!I like using octal numbers, and I've always been interested in D's octal literals. I'm glad to see that the traditional syntax of C's octal literals is being replaced by a more readable one. However, I can't help but think that the template solution ("octal!nnn") is a little too roundabout; is there a reason that that the "0o" prefix, which is already well established in languages like Haskell, OCaml, and Python, is not used?It was suggested a few times, but there was a lot of bikeshedding over it. Some people liked it, some hated it. One of the bigger objections was that octal literals were too rarely-needed to justify adding a new syntax into the language (this was at a time when D was far enough along that we were trying to start stabalizing the langauge rather than tossing in more stuff). The bikeshedding went around and around like that for awhile, during which time the awful old 0123 octal syntax remained. So when it was discovered that D's templates made it possible to implement octal literals in the library (octal!123), instead of in the language itself (0o123), that solved the deadlock and we went with it.
Jul 17 2012
On Tuesday, 17 July 2012 at 22:35:48 UTC, Nick Sabalausky wrote:On Tue, 17 Jul 2012 23:53:47 +0200 "Dave X." <dxuhuang gmail.com> wrote:Thanks! I guess I'll get used to it. Not that this really matters, but out of curiosity, how does this template work?I'm a fresh college graduate who just got a job as a software developer, and I have been enthusiastically watching D for a while now (I program primarily in Java and C). I have some functional programming experience in Haskell and Scala as well.I wish D had been as far along as it is now back when I was in college!I like using octal numbers, and I've always been interested in D's octal literals. I'm glad to see that the traditional syntax of C's octal literals is being replaced by a more readable one. However, I can't help but think that the template solution ("octal!nnn") is a little too roundabout; is there a reason that that the "0o" prefix, which is already well established in languages like Haskell, OCaml, and Python, is not used?It was suggested a few times, but there was a lot of bikeshedding over it. Some people liked it, some hated it. One of the bigger objections was that octal literals were too rarely-needed to justify adding a new syntax into the language (this was at a time when D was far enough along that we were trying to start stabalizing the langauge rather than tossing in more stuff). The bikeshedding went around and around like that for awhile, during which time the awful old 0123 octal syntax remained. So when it was discovered that D's templates made it possible to implement octal literals in the library (octal!123), instead of in the language itself (0o123), that solved the deadlock and we went with it.
Jul 18 2012
"Dave X." , dans le message (digitalmars.D:172680), a écrit :Not that this really matters, but out of curiosity, how does this template work?By looking at the sources, if the template argument is a string, the program just compute the octal value as a human would do, that is it makes the sum of the digits multiplied by their respective power of 8. If the template argument is not a string, it is transformed into a string and the previous algorithm is used. -- Christophe
Jul 18 2012
On Wed, 18 Jul 2012 16:45:58 +0200, Dave X. <dxuhuang gmail.com> wrote:Not that this really matters, but out of curiosity, how does this template work?It converts the passed number to a string, then works on a digit at a time. Basically: foreach ( digit; number ) { if ( digit >= '0' && digit <= '9' ) result = result * 8 + digit; } -- Simen
Jul 18 2012
On Wed, Jul 18, 2012 at 05:06:21PM +0200, Simen Kjaeraas wrote:On Wed, 18 Jul 2012 16:45:58 +0200, Dave X. <dxuhuang gmail.com> wrote:[...] And this is done at compile-time, so there is no runtime overhead (it just becomes a constant like an actual literal). T -- "640K ought to be enough" -- Bill G., 1984. "The Internet is not a primary goal for PC usage" -- Bill G., 1995. "Linux has no impact on Microsoft's strategy" -- Bill G., 1999.Not that this really matters, but out of curiosity, how does this template work?It converts the passed number to a string, then works on a digit at a time. Basically: foreach ( digit; number ) { if ( digit >= '0' && digit <= '9' ) result = result * 8 + digit; }
Jul 18 2012
This article by Walter might be of an interest to you: http://www.drdobbs.com/tools/user-defined-literals-in-the-d-programmi/229401068 On Tue, Jul 17, 2012 at 4:53 PM, Dave X. <dxuhuang gmail.com> wrote:I'm a fresh college graduate who just got a job as a software developer, and I have been enthusiastically watching D for a while now (I program primarily in Java and C). I have some functional programming experience in Haskell and Scala as well. I like using octal numbers, and I've always been interested in D's octal literals. I'm glad to see that the traditional syntax of C's octal literals is being replaced by a more readable one. However, I can't help but think that the template solution ("octal!nnn") is a little too roundabout; is there a reason that that the "0o" prefix, which is already well established in languages like Haskell, OCaml, and Python, is not used?
Jul 18 2012
On Tuesday, 17 July 2012 at 21:53:50 UTC, Dave X. wrote:I'm a fresh college graduate who just got a job as a software developer, and I have been enthusiastically watching D for a while now (I program primarily in Java and C). I have some functional programming experience in Haskell and Scala as well. I like using octal numbers, and I've always been interested in D's octal literals. I'm glad to see that the traditional syntax of C's octal literals is being replaced by a more readable one. However, I can't help but think that the template solution ("octal!nnn") is a little too roundabout; is there a reason that that the "0o" prefix, which is already well established in languages like Haskell, OCaml, and Python, is not used?Coming from C++, the only time I've EVER seen octals used is "by accident" when developers try to 0-align his variables. Good riddance to the "0" prefix. Seriously >:( That said, I did not know of this "0o" prefix. It sounds like a good idea, and I see no reason not to add it, other than it is hard work for the compiler devs of course, who already have a lot of work. :)
Jul 18 2012
On 7/18/12 10:29 AM, monarch_dodra wrote:I see no reason not to add itThis is never a good argument for adding things to a language. Andrei
Jul 18 2012
On Wednesday, 18 July 2012 at 17:37:02 UTC, Andrei Alexandrescu wrote:On 7/18/12 10:29 AM, monarch_dodra wrote:Taken out of context, no it isn't. "It sounds like a good idea", is a (relatively) good argument though.I see no reason not to add itThis is never a good argument for adding things to a language. Andrei
Jul 18 2012
On 7/18/12 1:39 PM, monarch_dodra wrote:On Wednesday, 18 July 2012 at 17:37:02 UTC, Andrei Alexandrescu wrote:Yah, thought the same after posting, sorry. Nevertheless, 0o or whatnot does not deserve, I opine, any attention. AndreiOn 7/18/12 10:29 AM, monarch_dodra wrote:Taken out of context, no it isn't. "It sounds like a good idea", is a (relatively) good argument though.I see no reason not to add itThis is never a good argument for adding things to a language. Andrei
Jul 18 2012
"monarch_dodra" <monarchdodra gmail.com> wrote in message news:srtxvzubdafcjzwwnkmz forum.dlang.org...That said, I did not know of this "0o" prefix. It sounds like a good idea, and I see no reason not to add it, other than it is hard work for the compiler devs of course, who already have a lot of work. :)It's a trivial amount of work to add '0o' octal literals to the language, but it was decided that octals are not used often enough to justify a language feature.
Jul 19 2012
How was the reception of the idea of binary literals as opposed to octal (I think it's an awesome feature, I think D, OCaml and Java 7 are the only ones that have it)? How long did it take to decide to implement it?
Jul 19 2012
"Dave X." <dxuhuang gmail.com> wrote in message news:cokspgduvpyzcbioawud forum.dlang.org...How was the reception of the idea of binary literals as opposed to octal (I think it's an awesome feature, I think D, OCaml and Java 7 are the only ones that have it)? How long did it take to decide to implement it?Binary literals were before my time, but AVR assembler also has them.
Jul 19 2012
On Thursday, 19 July 2012 at 14:13:06 UTC, Dave X. wrote:How was the reception of the idea of binary literals as opposed to octal (I think it's an awesome feature, I think D, OCaml and Java 7 are the only ones that have it)? How long did it take to decide to implement it?If they were introduced today, I guess they might well be implemented as a template too, similar to octal. David
Jul 19 2012
On Thu, 19 Jul 2012 16:13:05 +0200 "Dave X." <dxuhuang gmail.com> wrote:How was the reception of the idea of binary literals as opposed to octal (I think it's an awesome feature, I think D, OCaml and Java 7 are the only ones that have it)? How long did it take to decide to implement it?Binary literals have been there since way back around the beginning of D, just like hex literals, decimal literals and the now-dead old-style octal literals. Back when *everything* in D was a new feature. If octal literals had been like 0o123 or 0c123 instead of 0123 from the beginning, then I doubt we would have ever replaced them with octal!123 (since 0o123 or 0c123 aren't absolutely horrible like 0123 is).
Jul 19 2012