Skip to content
Tcl Source Code Changes To Migrating scripts to Tcl 9
Login

Changes To Migrating scripts to Tcl 9

Changes to "Migrating scripts to Tcl 9" between 2023-12-20 13:36:50 and 2024-04-12 09:38:01

︙
182
183
184
185
186
187
188







189
190
191











192
193
194
195
196
197
198
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216







+
+
+
+
+
+
+



+
+
+
+
+
+
+
+
+
+
+







line argument to `tclsh` is utf-8 in Tcl 9 instead of the system
encoding as in Tcl 8.

No changes are required for scripts that were pure ASCII and used
the `\u` or `\U` escapes for non-ASCII characters. Scripts that were
saved using a (non-utf8) system encoding will have to be modified
or sourced using an explicit `-encoding` option.

In TCL8.6, it is anyway good practice to include the `-encoding` parameter to the source command for portability.
A pckIndex.tcl file may look like this:
```
package ifneeded mypackage 1.0 [list source -encoding cp1286 [file join $dir mypackage.tcl]]
```
This will still work in 9.0 for any supported codepage.

See [TIP 587](https://core.tcl-lang.org/tips/doc/trunk/tip/587.md).

## strict encoding profile for scripts

The strict encoding profile applies to the source command.
The source command may throw encoding errors.

Scripts with non ASCII characters, even in comments, may now fail if the encoding is wrong.
A typical example is a copyright glyph in a non UTF-8 codepage "©" script file.

In TCL8.6, those errors did not arise, as the active tcl8 profile silently changed those characters to inline iso-8859-1 characters.
If it was real code (like text), the script changed in functionality.

## Full Unicode support

In Tcl 8, characters outside the BMP were stored as a surrogate pair
and effectively treated as a string of length 2. This is no longer
the case in Tcl 9 which has full support for the entire Unicode range
and will (correctly) treat these characters as strings of length 1.

︙