Skip to content
Tcl Source Code History Of Ticket 1143805
Login

History Of Ticket 1143805

Artifacts Associated With Ticket 1143805

  1. Ticket change [9551919225] (rid 106139) by lars_h on 2005-02-18 13:59:28:

    1. assignee initialized to: "dkf"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      A comment on the Tcler's Wiki page on [concat] (http://wiki.tcl.tk/
      1037) made me aware of the fact that the result of [list] is not 
      always a pure list; the result of [list] when called without 
      arguments is rather an empty string. This difference can be seen 
      on the script level as follows:
      
      % set third [expr 1.0/3]
      0.333333333333
      % expr {$third*3}
      1.0
      % expr {[lindex [concat [list $third] [list x]] 0]*3}
      1.0
      % expr {[lindex [concat [list $third] [list]] 0]*3}
      0.999999999999
      
      In the second case, the second argument of [concat] is not a pure 
      list, and thus [concat] operates on its arguments in string mode, 
      forcing a loss of the internal representation of the third.
      
      The bug is thus: The result of [list] is not always a pure list.
      
      Now, if anyone wants to argue that this is not a bug, then I can't 
      really object; since everything is (or at least should be) a string, 
      and in particular an empty list is the same thing as an empty 
      string, Tcl_ListObjCmd is completely right when it simply leaves 
      the empty result in the interpreter. Judging from the way it is 
      written, this is even by design:
      
      int
      Tcl_ListObjCmd(dummy, interp, objc, objv)
          ClientData dummy;                   /* Not used. */
          Tcl_Interp *interp;                 /* Current interpreter. */
          register int objc;                  /* Number of arguments. */
          register Tcl_Obj *CONST objv[];     /* The argument objects. */
      {
          /*
           * If there are no list elements, the result is an empty object.
           * Otherwise set the interpreter's result object to be a list 
      object.
           */
      
          if (objc > 1) {
              Tcl_SetObjResult(interp, Tcl_NewListObj((objc-1), 
      &(objv[1])));
          }
          return TCL_OK;
      }
      
      OTOH, the distinction between arbitrary lists and pure lists is 
      something that many programmers take care to observe, because 
      of the efficiency improvements this can bring, and then it seems a 
      bit odd that all return values from [list] _except_ the empty one 
      should be pure. This can lead to strange effects in cases like
      
         set extraOpts [list]
         foreach opt {-foo -bar -baz} {
            if {[needOption $opt]} then {lappend extraOpts $opt}
         }
         eval [list someCmd $someHugeDataStructure] $extraOpts
      
      where the [eval] suddenly takes much more time when no extra 
      options are passed, since $extraOpts will then not be a pure list.
      
      Also, I often find myself writing
      
         set res [list]
      
      rather than
      
         set res {}
      
      precisely because I know that this will be a list and want to "speed 
      things up" by initialising to an object with a list representation, and 
      I am not the only one who does this -- "set someVar [list]" is quite 
      common on the Wiki. It now turns out that this is in vain, since 
      what [list] returns actually doesn't have a list representation!
      
    4. foundin initialized to: "obsolete: 8.4.9"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "lars_h"
    9. subsystem initialized to: "17. Commands I-L"
    10. title initialized to: "Impurity of empty [list]"
    11. type initialized to: "Bug"
  2. Ticket change [ee37b57f78] (rid 104045) by dgp on 2005-02-19 04:13:18:

    1. icomment:
      Logged In: YES 
      user_id=80530
      
      
      IMHO...
      
      There is a bug here, but not the one
      you report.
      
      The bug is that floating point values
      don't make the internal -> string ->
      internal round trip without losing
      precision; in violation of "everything
      is a string".  That's a known bug in
      Tcl (not sure whether there's a SF
      Tracker ID for it), and the work on
      TIP 132 should eventually solve it.
      
      With that bug fixed, the difference
      in your two commands will
      disappear, and the "no script-level
      programmer should have to care
      about internal reps, 'pure' or
      otherwise" advice will actually become
      true.
      
      Far too many Tcl'ers are 
      preoccupied with "pure" representations
      and other internals details.
      Tcl ought to "just work" without
      requiring Tcl'ers to become C hackers.
      
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  3. Ticket change [85bce5c5eb] (rid 131367) by dkf on 2005-04-29 21:11:12:

    1. assignee changed to: "kennykb"
  4. Ticket change [584d44fa4e] (rid 117776) by kennykb on 2005-05-11 02:11:13:

    1. status changed to: "Closed"
  5. Ticket change [093ab17d71] (rid 89685) by kennykb on 2005-05-11 02:11:14:

    1. closedate changed to: "2005-05-10T19:11:14"
    2. closer changed to: "kennykb"
    3. icomment:
      Logged In: YES 
      user_id=99768
      
      TIP #132 fixes the user-visible manifestation; the purity
      of the empty list is irrelevant to the observed behaviour.
      Fixed in 8.5
      
      
    4. login: "kennykb"
    5. mimetype: "text/plain"
    6. resolution changed to: "Fixed"
    7. username: "kennykb"
  6. Ticket change [cb8f2bae1a] (rid 95541) by lars_h on 2005-05-11 17:57:06:

    1. icomment:
      Logged In: YES 
      user_id=938835
      
      How I wish the powers that be would spend more electronic ink on the 
      actual _issue_ than on the _symptoms_ of the issue.
      
      The issue in this report is *not* that real values can be distorted by loss of 
      internal representation; that was merely a (AFAICT standard) method of 
      demonstrating that the issue exists; a way of exhibiting a symptom. I 
      could instead have used the (less standard, and thus more obscure) 
      alternative of losing a wide internal representation of 65536 (as in 
      RFE#866469) to demonstrate the issue, but I chose not to, because I felt 
      that that could cloud the issue. However in view of how this report has 
      been examined, it seems it wouldn't have mattered; the issue got clouded 
      by concerns for symptoms anyway.
      
      The actual _issue_, that neither TIP#132 nor TIP#237 will address, is that 
      an impure return value from [list] can in some cases cause an essentially 
      constant time operation to effectively take linear time, thus (if one is 
      unlucky) increasing the exponent of just about any polynomial time 
      algorithm by one when implemented in Tcl. The response from dgp that 
      Tcl'ers should not be concerned with such matters is hopefully not a well 
      thought through position.
      
      On the bright side, TIP#157 ({expand}) will hopefully lead to a drastic 
      decrease in the number of [eval] constructions that may be harmed by an 
      impure list result, so the issue should become less and less important 
      over time. I still miss an explanation of why Tcl_ListObjCmd should have a 
      special case for no arguments however. Is it just a case of overdoing 
      optimisation, or does anyone have an actual motivation?
      
      And for the record, in case anyone wants a [list] equivalent that always 
      returns a pure list, they can do
         interp alias {} list {} lreplace x 0 0
      
      
    2. login: "lars_h"
    3. mimetype: "text/plain"
    4. username: "lars_h"
  7. Ticket change [d5dddf82b3] (rid 123705) by dkf on 2005-05-11 19:21:31:

    1. status changed to: "Open"
  8. Ticket change [d4f06c7d91] (rid 123528) by dkf on 2005-05-11 19:21:32:

    1. assignee changed to: "msofer"
    2. icomment:
      Logged In: YES 
      user_id=79902
      
      But that's all beside the point entirely. On one level, the
      "correct" way of fixing your problem would be to make [eval]
      go back to always having the horrible time behaviour. That'd
      make your complaint go away, but not in the way that you
      want. :^)
      
      The fact that "pure" lists have a few spots where they have
      more efficient processing (at virtually zero cost to
      everything else) is merely an optimization.
      
      Hmm, looking at Tcl_ConcatObj(), I see that it does not
      handle the newer concepts in shared empty objects perfectly.
      Assigning to Miguel for resolution...
      
      
    3. login: "dkf"
    4. mimetype: "text/plain"
    5. resolution changed to: "Remind"
    6. username: "dkf"
  9. Ticket change [47dabea6af] (rid 99780) by msofer on 2005-05-11 21:21:14:

    1. closedate changed to: "2005-05-11T14:21:14"
    2. closer changed to: "msofer"
    3. icomment:
      Logged In: YES 
      user_id=148712
      
      We had here one real bug (EIAS violation, fixed in HEAD),
      and one performance bug. As with all optimisations, there is
      a tradeoff: either an empty list has a list internal rep
      (and is therefore costly to create and destroy), or it
      doesn't (and it causes slowdowns in [concat]).
      
      As a side comment: having [list] return a listObj will not
      always speed things up. If you then lappend to it, you have
      to get rid of the empty list rep and replace it with a
      larger one. In that sense, the fact that it was created in
      the first place leads to a pure loss.
      
      Closing this, moving the [concat] issue over to [Bug
      1178805]. That will be addressed before 8.5a3 release. 
      
      
      
      
    4. login: "msofer"
    5. mimetype: "text/plain"
    6. resolution changed to: "Fixed"
    7. status changed to: "Closed"
    8. username: "msofer"