• Re: [string is integer 08] == 0

    From Lawrence Woodman@21:1/5 to Roman Mishin on Mon Aug 15 23:06:32 2022
    Hello Roman,

    On Tuesday, 16 August 2022 at 06:53:05 UTC+1, Roman Mishin wrote:

    What is the reason [string is integer 08] and [string is integer 09] return 0, but not in other cases:
    [SNIP]

    Numbers with a leading 0 are interpreted as Octal numbers and 08 and 09 are invalid Octal.

    Best wishes

    Lorry

    ---
    XCCP: A Shell Extension for CP/M https://techtinkering.com/articles/xccp-a-shell-extension-for-cpm/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Roman Mishin@21:1/5 to All on Mon Aug 15 22:53:03 2022
    Hello,

    What is the reason [string is integer 08] and [string is integer 09] return 0, but not in other cases:

    tclsh8.6 [~/dl] puts $tcl_patchLevel
    8.6.12
    tclsh8.6 [~/dl] string is integer 01
    1
    tclsh8.6 [~/dl] string is integer 02
    1
    tclsh8.6 [~/dl] string is integer 03
    1
    tclsh8.6 [~/dl] string is integer 04
    1
    tclsh8.6 [~/dl] string is integer 05
    1
    tclsh8.6 [~/dl] string is integer 06
    1
    tclsh8.6 [~/dl] string is integer 07
    1
    tclsh8.6 [~/dl] string is integer 08
    0
    tclsh8.6 [~/dl] string is integer 09
    0
    tclsh8.6 [~/dl] string is integer 10
    1

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Arjen Markus@21:1/5 to Roman Mishin on Mon Aug 15 23:06:37 2022
    On Tuesday, August 16, 2022 at 7:53:05 AM UTC+2, Roman Mishin wrote:
    Hello,

    What is the reason [string is integer 08] and [string is integer 09] return 0, but not in other cases:


    This has the do with ominous octal notation: the leading zero makes the number appear as an octal number, so 08 and 09 are not acknowledged as a valid integer. This dates back to the dark years of computing.

    Regards,

    Arjen

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Roman Mishin@21:1/5 to All on Mon Aug 15 23:08:44 2022
    Thank you, Lorry and Arjen.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Harald Oehlmann@21:1/5 to All on Tue Aug 16 09:23:09 2022
    Am 16.08.2022 um 08:08 schrieb Roman Mishin:
    Thank you, Lorry and Arjen.

    Yes, this is annoying.
    It is hard to get an integer number within TCL.
    One may use:
    set var 08
    if {1 == [scan $var %d var]} {
    puts "$var is a number"
    }

    This nnovance is removed in TCL 9 AFAIK ;-).

    Enjoy,
    Harald

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)