Overview
| Artifact ID: | 22f93f3085d649c91e2ab67edc0a5fc69cb89fd1 |
|---|---|
| Ticket: | 1049119fffffffffffffffffffffffffffffffff
append and lappend with one arg undocumented & inconsistent |
| User & Date: | nobody on 2004-10-18 10:20:28 |
Changes
- assignee changed to: "dkf"
- cmimetype changed to: "text/plain"
- comment changed to:
Behavior of append and lappend with one argument is undocumented and inconsistent. Using both lappend and append with just one argument is allowed according to 8.5 (and likely all previous) manual pages, arguments to both are specified as: varName ?value value value ...? It is however undocumented what happens when just varName is present. Manual suggests consistent behavior of lappend and append: "Lappend is similar to append except that the values are appended as list elements..." However in 8.3 (and likely in all versions), lappend can create new variable this way while append cannot: ~>tclsh % append x can't read "x": no such variable % lappend y % This should probably be considered as bug in append as the manual says: "If varName doesn't exist, it is given a value equal to the concatenation of all the value arguments." so one might expect that concatenation of no value arguments is an empty string which should become the value of newly created variable. Furthermore, it is unclear whether lappend with one argument will normalize any pre-existing value into the canonical list form or not. In 8.3 it will not, which might be regarded as an inconsistency with behavior when used with more arguments: % set x { a} % puts /[lappend x]/ / a/ % puts /[lappend x b]/ /a b/ This slight difference might become important if applications use current behavior of "lappend x" as a nice way to create x or leave it unchanges if it exists. Future versions of tcl might change this undocumented 'feature' and break these applications. Both lappend and append are quite basic commands and should not have uncertain behavior. Recommended action: a. fix append so that "append x" can create x b. document behavior of "append x" and "lappend x" Alternatively, consider these (IMHO inferior) solutions instead: c. document that "append x" cannot create x while "append x a" can d. change lappend so that "lappend x" list-normalizes x (By a quick manual scan, I did not find any other list operation which could become no-op like "lappend x" with pre-existing x. If there is any, it should be made consistent whether they all list-normalize x or not.) e. disallow "append x" and "lappend x" This last solution would be the worst (IMHO) as is would deprive users of very convenient: lappend x set x [concat x y] which creates x when needed and works regardless of (d.) Vaclav Hanzl, email: hanzl (x@x) noel.feld.cvut.cz - foundin changed to: "obsolete: 8.5a1"
- priority changed to: "5 Medium"
- resolution changed to: "None"
- status changed to: "Open"
- submitter changed to: "nobody"
- subsystem changed to: "16. Commands A-H"
- title changed to:
append and lappend with one arg undocumented & inconsistent
- type changed to: "RFE"