Skip to content
Tcl Source Code View Ticket
Login

View Ticket

list handling routines return the first element of a list in

Closed / Invalid2817506fffffffffffffffffffffffffffffffffCreated 17 years agoUpdated 17 years ago
Descriptionplain2009-07-06 16:04:06
Problem also shows up in 8.6.b, not there in 8.4.4. Tested on Windows, Linux (32 & 64 bit) & Solaris.

Many list handling routines return the first element of a list incorrectly when that element starts with #.

Maybe the behaviour is due to a meaning of the # symbol that I don't know about or maybe it's a bug.
At any rate it's different in 8.5 & 8.6 from 8.4.


The problem can be demonstrated trivially. N.B. list and lrange are not the only routines that show this.

set l00 {#1 #2 #3 #4}
=> #1 #2 #3 #4
set l01 [list #1 #2 #3 #4]
=> {#1} #2 #3 #4

set l02 [lrange $l00 0 end]
=> {#1} #2 #3 #4

set l10 {1 #2 #3 #4}
=> 1 #2 #3 #4
set l11 [list 1 #2 #3 #4]
=> 1 #2 #3 #4

set l12 [lrange $l10 0 end]
=> 1 #2 #3 #4
set l13 [lrange $l11 0 end]
=> 1 #2 #3 #4

set l14 [lrange $l10 1 end]
=> {#2} #3 #4
set l15 [lrange $l10 1 end]
=> {#2} #3 #4


One workaround for these simple examples is to rebuild the list using append.

for {set i 0} {$i < [llength $l02]} {incr i} {
   append l03 " " [lindex $l02 $i]
}
puts stdout $l03
=> #1 #2 #3 #4


I've now noticed another oddity in this area.

concat $l02 $l02
=> {#1} #2 #3 #4 #1 #2 #3 #4
but
concat $l03 $l03
=> #1 #2 #3 #4 {#1} #2 #3 #4
dgpplain2009-07-07 01:07:51
allow_comments - 1

From the changes file:

 * [TIP #148] correct [list]-quoting of the '#' character
     *** POTENTIAL INCOMPATIBILITY ***
   For scripts that assume a particular (buggy) string rep for lists.

See TIP 148 and Tracker ID 489537 for the history of this bug fix.

http://www.tcl.tk/cgi-bin/tct/tip/148

https://sourceforge.net/tracker/index.php?func=detail&aid=489537&group_id=10894&atid=210894

If you have scripts that are bug-dependent on this bug, fix them
as part of moving to Tcl 8.5.
Log in (anonymous is fine) to add a comment.