From: cej on
Hi,

I had some code working fine in tcl 7.6, when I tried to use latest
8.5 tcl version this was no more working. I figured out after some
searching
that this was related to a behaviour change of lreplace, I put
together a sample to illustrate this.

In 7.6 lreplace returns 'something' where in 8.5 it returns
'{something}', if something contains []
Can somebody tell me if this is a regression or a wanted behaviour
change?
Thanks in advance.

Following code does not give same result in tcl 7.6 and tcl 8.5

puts "tcl_version=$tcl_version"
set l {first sec[]ond}
puts "List is '$l'"
puts "List without first element is '[lreplace $l 0 0]'"


tcl_version=7.6
List is 'first sec[]ond'
List without first element is 'sec[]ond'


tcl_version=8.5
List is 'first sec[]ond'
List without first element is '{sec[]ond}'



From: Alexandre Ferrieux on
On Jun 22, 6:07 pm, cej <chroh...(a)aol.com> wrote:
> Hi,
>
> I had some code working fine in tcl 7.6, when I tried to use latest
> 8.5 tcl version this was no more working. I figured out after some
> searching
> that this was related to a behaviour change of lreplace, I put
> together a sample to illustrate this.
>
> In 7.6 lreplace returns 'something' where in 8.5 it returns
> '{something}', if something contains []
> Can somebody tell me if this is a regression or a wanted behaviour
> change?
> Thanks in advance.
>
> Following code does not give same result in tcl 7.6 and tcl 8.5
>
> puts "tcl_version=$tcl_version"
> set l {first sec[]ond}
> puts "List is '$l'"
> puts "List without first element is '[lreplace $l 0 0]'"
>
> tcl_version=7.6
> List is 'first sec[]ond'
> List without first element is 'sec[]ond'
>
> tcl_version=8.5
> List is 'first sec[]ond'
> List without first element is '{sec[]ond}'

Technically, this is not [lreplace] specifically, but the whole
definition of the canonical string representation of lists.
In modern Tcl, to have a bullet-proof semantics, along with avoiding
too much code duplication between the code and list parsers, a few
chars like $\[] are now protected in the canonical form. So, even
though sec[]ond is a proper list, it is not canonical, and [list]
(along with [lreplace], [lrange], etc) will systematically brace it in
their results.

This change can be partially traced (thanks to the "changes" file) to
8.5a1, March 2004:

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

Which rightfully highlights the core of your problem: never assume the
exact form of canonical lists; use lists with list operations, and if
you want a specific way of representing lists, use [join] or dedicated
pretty-printing code.

-Alex