Skip to content
Tcl Source Code View Ticket
Login

View Ticket

lappend no-op function changes when compiled

Closed / Fixed214cc0eb221912366d9bddbf04e660cf155393b9Created 12 years agoUpdated 2 years ago
Descriptionplain2014-11-04 23:48:17
Pointed out on comp.lang.tcl:

> % set str {# 1 2 3}
> # 1 2 3
> % lappend str
> {#} 1 2 3
> 
> % set str {# 1 2 3}
> # 1 2 3
> % [subst lappend] str
> # 1 2 3

The lappend command ought to behave the same whether
bytecode compiled or not.

The bytecode compiled behavior is what's new and creating
the inconsistency.
Referenced by4
  • 4c2a7cc393Ticket [e38dce74e2] Command line built with list not properly quoted status still Open with 3 other changes ticket2024-09-20 20:38:01
  • 3d1a4c2ddefix for [e38dce74e2] also for lappend etc (another variant to fix inconosistce of [214cc0eb22]); more coverage for that (all commands must behave the same way) check-in2024-09-20 20:25:51
  • fcc112066f[214cc0eb22] Add tests to make sure that this bug stays fixed. check-in2014-11-08 07:06:52
  • f40e585e4b[214cc0eb22] Restore [lappend $var] return value to the 8.6.1- behavior. If this is going to change, lets not do it by accident. check-in2014-11-05 06:36:07
dgpplain2014-11-05 05:39:05
Introduced in http://core.tcl.tk/tcl/info/17150b71d2
dgpplain2014-11-05 06:38:01
Simplest possible fix committed to trunk: disable compile of the
inconsistent case.

Leaving open in case dkf wants to pursue actually patching up
the behavior of all the new bytecode instructions instead.

There's a natural question to be asked here about whether
[lappend] ought to be always producing canonical lists.  It has
not been doing so up to now.  The argument in favor is to 
expand the set of commands one can use to create commands
for evaluation with complete confidence.

set script "a\nb"
eval [lappend script {*}$args] ;# one command or two?!

The argument against is that a no-op is best implemented as
a no-op (but in that case, why are we checking for list-ness?).
In particular, here a variable is involved and given the chance
to leave a variable's contents untouched, we should (and avoid
triggering traces, etc.).

I don't think either case is completely convincing to me, leaving
me uncertain which is more properly the best behavior to choose.
In that situation I break the tie by keeping consistency with
the historical practice.

Other opinions are invited.  In particular examples of existing
use of [lappend] to produce scripts for evaluation would be
good to know about, in particular, those combined with {*}
that might degenerate to the troublesome case.
dkfhtml2014-11-07 15:56:20

No, that's the right fix. The form lappend somevar is very strange in that it creates the variable if necessary, checks that value it contains is a well-formed list, yet doesn't otherwise modify the variable. Given how much of an evil edge case this is, I'm just going to leave it to the interpreted version; fixing things will require doing changes to the semantics of lappend (i.e., not Tcl 8.6).

Expansion isn't a problem: it currently always delegates to the interpreted code.

dkfhtml2014-11-08 07:07:00

I've added some tests so that we won't slip up like this again, including with expansion. It will make dealing with expansion much harder, but that's for the future.

jan.nijtmanswiki2024-11-14 10:34:47

Given [this] ticket, do we need to revisit this? Or do we consider the change for 9.0 but not for 8.x?

Log in (anonymous is fine) to add a comment.