Tcl Source Code

View Ticket
Login
Ticket UUID: f9c3463120117afc9c86cbfe2d57da81dbc942e4
Title: Proposal syntax for list
Type: RFE Version: 8.6
Submitter: anonymous Created on: 2016-08-29 19:39:03
Subsystem: - New Builtin Commands Assigned To: nobody
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2016-10-09 15:51:08
Resolution: Rejected Closed By: dkf
    Closed on: 2016-10-09 15:51:08
Description:
This is a proposal of a change in Tcl syntax:

When I want to create a big datastructure (with lists or dicts), I like to write the code in serveral lines for clarity. The problem with this expression: [comand_name arg0 arg1 arg2...] is that backslash are necessary if I want to write that expression in several lines. It's a little bit cumbersome:

set big_data_strucutre [dict \
                          key1 value1 \
                          key2 value2 \
                          key3 [list item1 item2 item3] \
                          key4 value4 \
                          key5 [list item1 [list item21 item22]] \
                          key6 value6]

Maybe it's better to make backslash optional inside square brackets (similar to braces). It's more clear and it's not necessary to type so much:

set big_data_strucutre [dict 
                          key1 value1 
                          key2 value2 
                          key3 [list item1 item2 item3] 
                          key4 value4 
                          key5 [list item1 [list item21 item22]] 
                          key6 value6]
User Comments: dkf added on 2016-10-09 15:51:08:
I concur. The likelihood that we'll make newline change interpretation in any context is very slight at best, and pretty much zero in this one as it is far more likely to break existing code. A <i>lot</i> of existing code at that.

ferrieux added on 2016-08-29 21:52:01:
And one can even make it simpler, knowing that Tcl will internally shimmer the value to a dict as soon as a dict primitive is used:

set big_data_strucutre "
                          key1 value1
                          key2 value2
                          key3 {item1 item2 item3}
                          key4 value4
                          key5 {item1 {item21 item22}}
                          key6 value6"

dgp added on 2016-08-29 21:35:02:
To be clear, you are not proposing a change to
list syntax.  You are proposing that a newline
cease being a command terminator in Tcl
script syntax.  The remaining option would be
a semi-colon, I suppose, but I can offer little
hope this bridge would ever be crossed.

The good news is you can already have almost
what you want without changing any of Tcl's
syntax rules at all:

set big_data_strucutre [dict {*}"
                          key1 value1
                          key2 value2
                          key3 [list item1 item2 item3]
                          key4 value4
                          key5 [list item1 [list item21 item22]]
                          key6 value6"]