View Ticket
Not logged in
Ticket UUID: ccc2c2cc983bf903292d23d1942e7255957de5bd
Title: lreplace on an empty list produces an error where it didn't use to.
Type: Bug Version: 8.6.2
Submitter: sbron Created on: 2014-09-04 08:31:53
Subsystem: 17. Commands I-L Assigned To: dkf
Priority: 8 Severity: Minor
Status: Closed Last Modified: 2014-09-05 12:18:00
Resolution: Fixed Closed By: dkf
    Closed on: 2014-09-05 12:18:00
Description:
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.
User Comments: dkf added on 2014-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.


dgp added on 2014-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].

dkf added on 2014-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).


dgp added on 2014-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.

dgp added on 2014-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!

dkf added on 2014-09-04 09:49:14:

Bother it! (This wasn't a test case, but perhaps should have been.)