digitalmars.D.learn - More octal questions
- H. S. Teoh (7/7) Feb 14 2012 OK, so I know that octals are deprecated, and the compiler will refuse
- Timon Gehr (3/9) Feb 14 2012 Yes.
- Andrej Mitrovic (1/1) Feb 15 2012 Where do you see those literals? I'm only seeing strings.
- Timon Gehr (3/4) Feb 15 2012 Line 8322: _assertPred!"=="(SysTime.fromISOString("20101222T172201"),
- H. S. Teoh (6/12) Feb 15 2012 That unittest contains a lot of these literals. I'm not sure if this is
- Jonathan M Davis (7/17) Feb 15 2012 They're not left over at all, and they have nothing to do with octal. It...
-
Stewart Gordon
(12/13)
Feb 15 2012
- Jonathan M Davis (13/30) Feb 15 2012 They have nothing to do with octal in that they were not intentionally o...
- Jonathan M Davis (6/22) Feb 17 2012 They have nothing to do with octal in that they were not intentionally o...
- Daniel Murphy (5/13) Feb 17 2012 While we can't ever allow leading zeroes in the general case, to catch
- H. S. Teoh (11/17) Feb 15 2012 [...]
- Adam D. Ruppe (14/19) Feb 15 2012 The goal here is to make sure things either do what they
- H. S. Teoh (10/24) Feb 15 2012 True. Especially if a C coder tries calling chmod() with 0644 and it
- Jonathan M Davis (8/30) Feb 15 2012 Arguably more import is the fact that making 010 mean 10 would be a prob...
OK, so I know that octals are deprecated, and the compiler will refuse to compile code with octals unless the -deprecated flag is used. But I find that std.datetime has literals of the form 000, 01, 02, 03, and so on. Are these considered OK? Should my lexer accept them? T -- To err is human; to forgive is not our policy. -- Samuel Adler
Feb 14 2012
On 02/14/2012 10:24 PM, H. S. Teoh wrote:OK, so I know that octals are deprecated, and the compiler will refuse to compile code with octals unless the -deprecated flag is used. But I find that std.datetime has literals of the form 000, 01, 02, 03, and so on. Are these considered OK? Should my lexer accept them? TYes. On 02/11/2012 05:37 PM, Timon Gehr wrote:Octal literals whose value is larger than 7 must be rejected. Octal literals with values up to 7 must be accepted.
Feb 14 2012
Where do you see those literals? I'm only seeing strings.
Feb 15 2012
On 02/15/2012 09:30 AM, Andrej Mitrovic wrote:Where do you see those literals? I'm only seeing strings.Line 8322: _assertPred!"=="(SysTime.fromISOString("20101222T172201"), SysTime(DateTime(2010, 12, 22, 17, 22, 01)));
Feb 15 2012
On Wed, Feb 15, 2012 at 02:42:04PM +0100, Timon Gehr wrote:On 02/15/2012 09:30 AM, Andrej Mitrovic wrote:That unittest contains a lot of these literals. I'm not sure if this is leftover from older code? T -- What's a "hot crossed bun"? An angry rabbit.Where do you see those literals? I'm only seeing strings.Line 8322: _assertPred!"=="(SysTime.fromISOString("20101222T172201"), SysTime(DateTime(2010, 12, 22, 17, 22, 01)));
Feb 15 2012
On Wednesday, February 15, 2012 08:32:55 H. S. Teoh wrote:On Wed, Feb 15, 2012 at 02:42:04PM +0100, Timon Gehr wrote:They're not left over at all, and they have nothing to do with octal. It's simply a matter of the natural thing for me to do when dealing with dates and times is to put the 0 in front of single digit numbers. You'll note that in the string representations, you _have_ to (per the ISO standard). So, I ended up doing it with the integer literals without thinking about it. - Jonathan M DavisOn 02/15/2012 09:30 AM, Andrej Mitrovic wrote:That unittest contains a lot of these literals. I'm not sure if this is leftover from older code?Where do you see those literals? I'm only seeing strings.Line 8322: _assertPred!"=="(SysTime.fromISOString("20101222T172201"), SysTime(DateTime(2010, 12, 22, 17, 22, 01)));
Feb 15 2012
On 15/02/2012 16:41, Jonathan M Davis wrote: <snip>They're not left over at all, and they have nothing to do with octal.<snip> They are something to do with octal: because in D an integer literal beginning with 0 is defined to be octal, the compiler must interpret them as such if it is going to accept them at all. Of course, under current D2 without -d, the compiler rejects zero-led integer literals greater than 07. But it's because of this octal legacy that it accepts up to 07 but not 08, 09 or 010. Still, what's the long-term plan? To remove octal literals completely, and allow decimal literals to have leading 0s? Or to continue to allow just up to 07 until the end of time? Stewart.
Feb 15 2012
On Thursday, February 16, 2012 00:38:10 Stewart Gordon wrote:On 15/02/2012 16:41, Jonathan M Davis wrote: <snip>They have nothing to do with octal in that they were not intentionally octal. I was merely using the leading 0 without thinking about it, because having leading 0s generally makes more sense when dealing with the date/time stuff. The fact that they were octal is incidental. They result in the same number either way, save for 08 and 09 not working.They're not left over at all, and they have nothing to do with octal.<snip> They are something to do with octal: because in D an integer literal beginning with 0 is defined to be octal, the compiler must interpret them as such if it is going to accept them at all. Of course, under current D2 without -d, the compiler rejects zero-led integer literals greater than 07. But it's because of this octal legacy that it accepts up to 07 but not 08, 09 or 010.Still, what's the long-term plan? To remove octal literals completely, and allow decimal literals to have leading 0s? Or to continue to allow just up to 07 until the end of time?I expect that we will never allow decimal literals with leading 0s which would end up with different numbers than they would if we supported octal literals, because otherwise any C/C++ code which is ported to D and uses octal literals will then compile with different semantics, and that's generally verboten in D (there are a few exceptions, but they're quite rare). I'm not aware of Walter actually having stated what his longterm plan is though. - Jonathan M Davis
Feb 15 2012
On Thursday, February 16, 2012 00:38:10 Stewart Gordon wrote:On 15/02/2012 16:41, Jonathan M Davis wrote: <snip>They have nothing to do with octal in that they were not intentionally octal. I was merely using the leading 0 without thinking about it, because having leading 0s generally makes more sense when dealing with the date/time stuff. The fact that they were octal is incidental. They result in the same number either way, save for 08 and 09 not working.They're not left over at all, and they have nothing to do with octal.<snip> They are something to do with octal: because in D an integer literal beginning with 0 is defined to be octal, the compiler must interpret them as such if it is going to accept them at all.Still, what's the long-term plan? To remove octal literals completely, and allow decimal literals to have leading 0s? Or to continue to allow just up to 07 until the end of time? Stewart.
Feb 17 2012
"Jonathan M Davis" <jmdavisProg gmx.com> wrote in message news:mailman.508.1329531876.20196.digitalmars-d-learn puremagic.com...They have nothing to do with octal in that they were not intentionally octal. I was merely using the leading 0 without thinking about it, because having leading 0s generally makes more sense when dealing with the date/time stuff. The fact that they were octal is incidental. They result in the same number either way, save for 08 and 09 not working.While we can't ever allow leading zeroes in the general case, to catch errors porting ocal literals from c family languages, 08 and 09 could actually be supported in the future.
Feb 17 2012
On Wed, Feb 15, 2012 at 08:41:33AM -0800, Jonathan M Davis wrote: [...]They're not left over at all, and they have nothing to do with octal. It's simply a matter of the natural thing for me to do when dealing with dates and times is to put the 0 in front of single digit numbers. You'll note that in the string representations, you _have_ to (per the ISO standard). So, I ended up doing it with the integer literals without thinking about it.[...] Yes, I guessed as much. Which brings up a question of what exactly octal deprecation will entail. Seems like it would make sense to allow initial 0's in decimal literals once octal literals are phased out. Also, string escape sequences appear to allow backslash octal as well; are these being deprecated or are they here to stay? T -- Тише едешь, дальше будешь.
Feb 15 2012
On Wednesday, 15 February 2012 at 17:48:03 UTC, H. S. Teoh wrote:Yes, I guessed as much. Which brings up a question of what exactly octal deprecation will entail.The goal here is to make sure things either do what they look like, or don't compile. 010 doesn't do what it looks like to a person used to decimal; it is a C octal literal for decimal 8. So it is deprecated. But, making it mean decimal 10 is also a no go, because if you're used to C syntax, it won't do what you expect. That's why it is an error. It is sure to confuse *somebody*. 01, 02, 03, ... 07 though work in both cases, so they might still be allowed. (I'm not sure if they are or not). But since there's no confusion for decimal people or for C people, there's no problem with those small numbers.Also, string escape sequences appear to allow backslash octal as well; are these being deprecated or are they here to stay?I'm not sure.
Feb 15 2012
On Wed, Feb 15, 2012 at 06:52:09PM +0100, Adam D. Ruppe wrote: [...]The goal here is to make sure things either do what they look like, or don't compile. 010 doesn't do what it looks like to a person used to decimal; it is a C octal literal for decimal 8. So it is deprecated. But, making it mean decimal 10 is also a no go, because if you're used to C syntax, it won't do what you expect. That's why it is an error. It is sure to confuse *somebody*.True. Especially if a C coder tries calling chmod() with 0644 and it silently gets interpreted as decimal.01, 02, 03, ... 07 though work in both cases, so they might still be allowed. (I'm not sure if they are or not).[...] Currently the compiler accepts them (even without -deprecated). Otherwise std.datetime wouldn't compile. :) T -- Bomb technician: If I'm running, try to keep up.
Feb 15 2012
On Wednesday, February 15, 2012 18:52:09 Adam D. Ruppe wrote:On Wednesday, 15 February 2012 at 17:48:03 UTC, H. S. Teoh wrote:Arguably more import is the fact that making 010 mean 10 would be a problem for porting code from C/C++. In general, C/C++ is either valid D code with the same semantics, or it doesn't compile (though there are a few exceptions - e.g. static arrays being value types). Treating 010 as 10 would violate that. So, I'd be very surprised if Walter agreed to do that. It'll just permanently stay an error like it is now. - Jonathan M DavisYes, I guessed as much. Which brings up a question of what exactly octal deprecation will entail.The goal here is to make sure things either do what they look like, or don't compile. 010 doesn't do what it looks like to a person used to decimal; it is a C octal literal for decimal 8. So it is deprecated. But, making it mean decimal 10 is also a no go, because if you're used to C syntax, it won't do what you expect. That's why it is an error. It is sure to confuse *somebody*. 01, 02, 03, ... 07 though work in both cases, so they might still be allowed. (I'm not sure if they are or not). But since there's no confusion for decimal people or for C people, there's no problem with those small numbers.
Feb 15 2012