Skip to content
Tcl Source Code History Of Ticket aa69bce71e214872
Login

History Of Ticket aa69bce71e214872

Artifacts Associated With Ticket aa69bce71e214872

  1. Ticket change [5461560ec6] (rid 222896) by anonymous on 2024-03-11 21:26:09:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-fossil-plain"
    4. comment initialized to:
      I wanted to know if the 'expr' command when using the < operator compares its arguments as numbers or as strings. So I checked the documentation for expr. This is what it says:
      
      >> These operators may be applied to strings as well as numeric operands, in which case string comparison is used. <<
      
      https://tcl.tk/man/tcl/TclCmd/expr.htm#M12
      
      From this, I expect that I can compare two string, or I can compare two numbers, both will be ok for the operator. It should always compare as strings - as it says that strig comparison is used.
      
      But the implementation does not follow it
      
      % expr {12<2}
      0
      % expr {"12"<"2"}
      0
      
      When compared as strings the first should be smaller than the second. The result should be 1.
      
      The string comparison should be like this:
      
      % string compare 12 2
      -1
      
      I.e. the first string is less than the second.
      
      Or maybe the documentation is wrong?
      
    5. foundin initialized to: "8.6"
    6. is_private initialized to: "0"
    7. login: "anonymous"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "eb1592a11067c658ae62686070571429a9282829"
    10. resolution initialized to: "None"
    11. severity initialized to: "Minor"
    12. status initialized to: "Open"
    13. submitter initialized to: "anonymous"
    14. subsystem initialized to: "16. Commands A-H"
    15. title initialized to:
      expr comparison operator result does not follow the documentation
      
    16. type initialized to: "Bug"
  2. Ticket change [03aae72013] (rid 222909) by sebres on 2024-03-11 23:06:37:

    1. closedate changed to: "2460381.46293034"
    2. closer changed to: "sebres"
    3. icomment:
      From point of view of the Tcl-parser the tokens `"12"` and `12` (but also `{12}`) are the same. See [Tcl language syntax](https://tcl.tk/man/tcl/TclCmd/Tcl.htm) for basic details how Tcl-parser works.
      
      The mentioned documentation clarifying only that there is a fallback operation which would compare them as string, **if one of the operands is not numeric**.
      However by the operators like `<`, it'd always prefer numeric comparison (no matter whether it is enclosed in quotes or not).
      
      
      Since 8.7 ([TIP 461](https://core.tcl-lang.org/tips/doc/trunk/tip/461.md)), there is a lot of other operators which always use string comparison.
      
      In this case:
      
      ```
      % expr {12 lt 2}
      1
      % expr {"12" lt "2"}
      1
      % expr {{12} lt {2}}
      1
      ```
      (again, no matter they are enclosed in quotes or not).
      
      Before that (for 8.5 or 8.6) there are only two string comparison operators available - `eq` and `ne`, so one'd use `[string compare]` either.
      
      Another possibility would be to use the trick with string-concatenation to word-tokens, in order to force string comparison:
      
      ```
      % set a 12; set b 2; expr {$a < $b}
      0
      % set a 12; set b 2; expr {"s$a" < "s$b"}
      1
      ```
      
    4. login: "sebres"
    5. mimetype: "text/x-markdown"
    6. resolution changed to: "Invalid"
    7. status changed to: "Closed"
  3. Ticket change [70c4fe56c0] (rid 222940) by oehhar on 2024-03-12 08:14:04:

    1. closedate changed to: "2460381.84310304"
    2. closer changed to: "oehhar"
    3. icomment:
      please use "string compare" to compare strings in a relyable way with TCL 8.6.
      
    4. login: "oehhar"
    5. mimetype: "text/x-fossil-wiki"
    6. username: "oehhar"