How does one list values in multiple lines without a backslash at the end of each line?
One can't create a list in multiple lines without having a backslash at the end.
For example, the following (wrong) code:
set pets [list
cat
dog
elephant
]
gives an error:
invalid command name "cat"
while executing
"cat"
invoked from within
"set pets [list
cat
dog
elephant
]"
It can be fixed by appending a backslash at the end of the line:
set pets [list \
cat \
dog \
elephant \
]
Which is ugly and prone to errors.
Please note that:
- I'm aware of using the curly braces (
{&}), but it doesn't allows executing commands and also keeps redundant whitespace characters. - Any other command may be used (e.g.
dict create), not onlylistas in my example.
Using Tcl 8.5