First of all, yes, I know this is all standardized and it is based on
legacy C conventions and it can't be changed and so on and so forth.
But if not a bug, it is certainly a misfeature.
I am referring, of course, to the convention that a number with a leading zero is interpreted as octal. I can't count the number of times I've been bitten by this - in various languages/environments all across the Unix ecosystem. Note the choice of newsgroups above - I have been affected by this in each of these environments - most recently in Tcl (Expect) and in
the VIM editor.
In fact, the really obnoxious part about it is that it means a number
string like "08" is invalid, because 8 is not a valid digit in octal. I
wish there was a global way to turn this off - some option to set that says "Don't do that!". I realize, of course, that it has to be on by default,
but it should be possible to turn it off.
Incidentally, and this was my motivation for posting this rant, I hit this
in VIM - where if the cursor is sitting on the zero in a string like Foo07 and you hit ^A, it changes it to - are you ready? - not Foo08, but Foo010.
Totally weird and unexpected.
I am referring, of course, to the convention that a number with a
leading zero is interpreted as octal. ... most recently in Tcl
(Expect) ...
First of all, yes, I know this is all standardized and it is based on
legacy C conventions and it can't be changed and so on and so forth.
But if not a bug, it is certainly a misfeature.
the VIM editor.
Vim is highly configurable. See ":help nrformats" for supported formats.
Not clearly documented in the version I have, but implied, is setting
it to a blank string to only recognize ordinary decimal numbers.
:set nrformats=
As a consequence, in Kornshell, I'm using a number prefix 10# to
counter that misbehavior. (I'd suppose this works also in other
major shells like Bash.)
I am referring, of course, to the convention that a number with a
leading zero is interpreted as octal. ... most recently in Tcl
(Expect) ...
For Tcl 9, leading zero decimal number strings are no longer
interpreted as octal:
https://www.tcl-lang.com/software/tcltk/9.0.html
Numbers
0NNN format is no longer octal interpretation. Use 0oNNN
In article <eli$2501042055@qaz.wtf>,
Eli the Bearded <*@eli.users.panix.com> wrote:
...
Vim is highly configurable. See ":help nrformats" for supported formats. >>Not clearly documented in the version I have, but implied, is setting
it to a blank string to only recognize ordinary decimal numbers.
:set nrformats=
Thanks for the tip. I'll look into that.
In article <vld4k2$2jao9$1@news.xmission.com>,
Kenny McCormack <gazelle@shell.xmission.com> wrote:
In article <eli$2501042055@qaz.wtf>,
Eli the Bearded <*@eli.users.panix.com> wrote:
...
Vim is highly configurable. See ":help nrformats" for supported formats. >>>Not clearly documented in the version I have, but implied, is setting
it to a blank string to only recognize ordinary decimal numbers.
:set nrformats=
Thanks for the tip. I'll look into that.
Yes, nf looks good. I set it to "alpha", which makes it do the right thing >with letters, while ignoring the stupid hex/octal/bin stuff.
In article <vld4k2$2jao9$1@news.xmission.com>,
Kenny McCormack <gazelle@shell.xmission.com> wrote:
In article <eli$2501042055@qaz.wtf>,
Eli the Bearded <*@eli.users.panix.com> wrote:
...
Vim is highly configurable. See ":help nrformats" for supported formats. >>> Not clearly documented in the version I have, but implied, is setting
it to a blank string to only recognize ordinary decimal numbers.
:set nrformats=
Thanks for the tip. I'll look into that.
Yes, nf looks good. I set it to "alpha", which makes it do the right thing with letters, while ignoring the stupid hex/octal/bin stuff.
I hit this in VIM - where if the cursor is sitting on the zero in a
string like Foo07 and you hit ^A, it changes it to - are you ready?
- not Foo08, but Foo010.
I updated my 'seq' code because of this thread:
https://wiki.tcl-lang.org/page/seq
First of all, yes, I know this is all standardized and it is based on
legacy C conventions and it can't be changed and so on and so forth.
But if not a bug, it is certainly a misfeature.
I am referring, of course, to the convention that a number with a leading zero is interpreted as octal. I can't count the number of times I've been bitten by this - in various languages/environments all across the Unix ecosystem. Note the choice of newsgroups above - I have been affected by this in each of these environments - most recently in Tcl (Expect) and in
the VIM editor.
There is an interesting "octal" problem left as an exercise 🙂
I can't help but think that this may be related to your post regarding
time calculation. I had left this quote in my reply:
There is an interesting "octal" problem left as an exercise
This was exactly the exercise as well. "clock format" leaves leading
zeros in the result depending on what time it was. It is missing "string >trimleft" calls which I'd discovered after some test runs before posting.
Luc <luc@sep.invalid> wrote:
I updated my 'seq' code because of this thread:
https://wiki.tcl-lang.org/page/seq
And, line one of the proc contains the common Tcl bug of "applying a
string operator" to a tcl list.
On Sun, 5 Jan 2025 21:04:46 -0000 (UTC), Rich wrote:
Luc <luc@sep.invalid> wrote:
I updated my 'seq' code because of this thread:
https://wiki.tcl-lang.org/page/seq
And, line one of the proc contains the common Tcl bug of "applying a >>string operator" to a tcl list.
**************************
While I admit that I never took the list to string conversion into consideration (I am repeat offender at that), you explore certain possibilities in your exposition that I did take into consideration,
and I decided that those don't matter.
Anyone who has ever used seq (or just merely understands it in spite
of never having used it) knows what the input is supposed to be: two
or three integers.
I improved on it by adding the ability to produce alphabetic sequences.
About your examples, being atypically blunt, no programmer is stupid
enough to input 08 and 08. Even I wouldn't that. Likewise, no programmer will be stupid enough to input #08. And if anyone actually does that,
they will get the empty string. The code intentionally refuses to
produce output when the input is incorrect.
So thanks to you, I have updated the code once again.
In article <vletuv$17djb$1@dont-email.me>, saito <saitology9@gmail.com> wrote:
...
I can't help but think that this may be related to your post regarding >>time calculation. I had left this quote in my reply:
There is an interesting "octal" problem left as an exercise
This was exactly the exercise as well. "clock format" leaves leading
zeros in the result depending on what time it was. It is missing "string >>trimleft" calls which I'd discovered after some test runs before posting.
It is, in fact, related to that other thread. In fact, I had developed an entirely different solution to that problem (very short, in fact) which had been running fine for a few weeks until it happened to hit the dreaded "08" and crashed. I fixed that basically by adding code using "regsub" to
remove any leading zero before doing the calculations.
I'll have to take a look at "string trimleft".
And, if you are willing to use lmap, the above four lines can become
this single line:
set args [lmap arg $args {scan $arg %d}]
First of all, yes, I know this is all standardized and it is based on*CUT* [ 16 lines 1 level deep]
legacy C conventions and it can't be changed and so on and so forth.
Totally weird and unexpected.
On Mon, 6 Jan 2025 03:12:48 -0000 (UTC), Rich wrote:
And, if you are willing to use lmap, the above four lines can become**************************
this single line:
set args [lmap arg $args {scan $arg %d}]
You are not going to believe this:
I never knew that lmap existed.
I've known lassign for a very long time.
Never knew about lmap until today.
The canonical Tcl way to handle decimal number strings with leading
zeros is to filter them through [scan] using the %d scan pattern.
$ rlwrap tclsh
% scan 08 %d
8
% scan 00000000000000000000008 %d
8
%
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 1,028 |
Nodes: | 10 (0 / 10) |
Uptime: | 142:22:36 |
Calls: | 13,330 |
Files: | 186,574 |
D/L today: |
863 files (242M bytes) |
Messages: | 3,355,589 |