|
2014-09-05
| ||
| 12:18 | • Closed ticket [ccc2c2cc98]: lreplace on an empty list produces an error where it... artifact: e7fc6bc633 user: dkf | |
| 10:40 | • Ticket [ccc2c2cc98]: 3 changes artifact: 3229e307bf user: dgp | |
| 10:05 | [ccc2c2cc98]: lreplace edge case check-in: c20208530f user: dkf tags: trunk | |
| 09:01 | • Ticket [ccc2c2cc98] lreplace on an empty list produces an error where it didn... artifact: bcd28eab06 user: dkf | |
|
2014-09-04
| ||
| 16:10 | • Ticket [ccc2c2cc98]: 3 changes artifact: df29793982 user: dgp | |
| 15:43 | • Ticket [ccc2c2cc98]: 3 changes artifact: eb2cce2523 user: dgp | |
| 09:49 | • Ticket [ccc2c2cc98]: 6 changes artifact: 388d778a0d user: dkf | |
| 08:31 | • New ticket [ccc2c2cc98]. artifact: fef62f00d4 user: sbron | |
lreplace on an empty list produces an error where it didn't use to.
Closed / Fixedccc2c2cc983bf903292d23d1942e7255957de5bdCreated 12 years agoUpdated 12 years ago
Descriptionplain2014-09-04 08:31:53
In Tcl 8.6.2 the command [lreplace {} 1 1] produces an error: "list doesn't contain element 1". This conflicts with the manual page, which specifically mentions: "If list is empty, then first and last are ignored". In Tcl 8.6.1 the indicated command returns an empty list, as expected.
Referenced by1
c20208530f[ccc2c2cc98]: lreplace edge case check-in2014-09-05 10:05:05
dkfhtml2014-09-04 09:49:14
Bother it! (This wasn't a test case, but perhaps should have been.)
dgpplain2014-09-04 15:43:34
Oh my stars, what a mess! See http://core.tcl.tk/tcl/tktview?name=218675 for the mortifying history. Yeah, lets fix bugs by documenting them! That's the ticket!
dgpplain2014-09-04 16:10:21
Given the freedom to reboot, it's clear to me that
the behavior that would be both consistent and
useful would be for
lreplace $list $first $last $new1 ... $newN
to find the same range of existing elements specified
by
lrange $list $first $last
remove them and in their place insert $new1 through $newN
In the case where the element range to remove is empty,
insert the new elements at the position identified by $first
No errors for any syntactically valid indices.
Would be a big change around the edges though.
dkfwiki2014-09-05 09:01:47
Yuck. [218675] is just weird, as is the whole detail of how lreplace works in detail. The behaviour in 8.5 (which uses the interpreted code) is not to return the original object when it is an empty list, but rather to use the empty string (noticeable when you use an input containing nothing but spaces).
dgpplain2014-09-05 10:40:02
That detail doesn't bother me. It can be understood as part of a contract that [lreplace] is to return only lists with canonical string reps. As we just went through with [dict replace].
dkfhtml2014-09-05 12:18:00
Leaving aside the question of what the behaviour ought to be, I've added the extra check to the bytecode issued.
Log in (anonymous is fine) to add a comment.