Artifacts Associated With Ticket 1143805
Ticket change [9551919225] (rid 106139) by lars_h on 2005-02-18 13:59:28:
- assignee initialized to: "dkf"
- cmimetype initialized to: "text/plain"
- 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! - foundin initialized to: "obsolete: 8.4.9"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "lars_h"
- subsystem initialized to: "17. Commands I-L"
- title initialized to: "Impurity of empty [list]"
- type initialized to: "Bug"
Ticket change [ee37b57f78] (rid 104045) by dgp on 2005-02-19 04:13:18:
- 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.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [85bce5c5eb] (rid 131367) by dkf on 2005-04-29 21:11:12:
- assignee changed to: "kennykb"
Ticket change [584d44fa4e] (rid 117776) by kennykb on 2005-05-11 02:11:13:
- status changed to: "Closed"
Ticket change [093ab17d71] (rid 89685) by kennykb on 2005-05-11 02:11:14:
- closedate changed to: "2005-05-10T19:11:14"
- closer changed to: "kennykb"
- 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
- login: "kennykb"
- mimetype: "text/plain"
- resolution changed to: "Fixed"
- username: "kennykb"
Ticket change [cb8f2bae1a] (rid 95541) by lars_h on 2005-05-11 17:57:06:
- 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 - login: "lars_h"
- mimetype: "text/plain"
- username: "lars_h"
- icomment:
Ticket change [d5dddf82b3] (rid 123705) by dkf on 2005-05-11 19:21:31:
- status changed to: "Open"
Ticket change [d4f06c7d91] (rid 123528) by dkf on 2005-05-11 19:21:32:
- assignee changed to: "msofer"
- 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...
- login: "dkf"
- mimetype: "text/plain"
- resolution changed to: "Remind"
- username: "dkf"
Ticket change [47dabea6af] (rid 99780) by msofer on 2005-05-11 21:21:14:
- closedate changed to: "2005-05-11T14:21:14"
- closer changed to: "msofer"
- 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.
- login: "msofer"
- mimetype: "text/plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"
- username: "msofer"