Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

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

  1. assignee changed to: "dkf"
  2. cmimetype changed to: "text/plain"
  3. 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
    
    
  4. foundin changed to: "obsolete: 8.5a1"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "nobody"
  9. subsystem changed to: "16. Commands A-H"
  10. title changed to:
    append and lappend with one arg undocumented & inconsistent
    
  11. type changed to: "RFE"