Check-in [0b004d697b]

Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:New TIP: 526
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 0b004d697b9b97127aa6c3918e5c1e474f22b19ec499e81343d086f79af2de0d
User & Date: dkf 2018-11-08 10:16:11
Context
2018-11-10
09:26
Add precisions in TIP #466 about spaces trimming, -spacemode options, and the fact that no -spacemode value shows text completely identical to the legacy code (slight backwards incompatibility). check-in: 489ef3ca2b user: fvogel tags: trunk
2018-11-08
10:16
New TIP: 526 check-in: 0b004d697b user: dkf tags: trunk
2018-11-06
15:18
Corrected vote record check-in: af2513fa1b user: dkf tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to index.json.

     1      1   {"tip": {
            2  +	"526":{"url":"./tip/526.md","created":"08-Nov-2018","post-history":"","state":"Draft","tcl-version":"9.0","vote":"Pending","type":"Project","title":"# TIP 526: Make [expr] Only Accept One Argument","author":["Donal K. Fellows <[email protected]>"],"is-jest":false},
     2      3   	"525":{"url":"./tip/525.md","keywords":"Tcl, testing, continuous integration","state":"Final","type":"Project","author":["Donal K. Fellows <[email protected]>"],"vote-results":"8/0/0 accepted","votes-for":"KBK, SL, AF, DGP, FV, DKF, AK, JN","votes-against":"none","created":"24-Oct-2018","title":"# TIP 525: Make Tcltest Report Overall Success in a Machine-Readable Way","post-history":"","vote":"Done","tcl-version":"8.5","votes-present":"none","is-jest":false},
     3      4   	"524":{"url":"./tip/524.md","keywords":"Tcl, object orientation, customization","state":"Final","vote-summary":"Accepted 2/0/4","type":"Project","author":["Donal K. Fellows <[email protected]>"],"votes-against":"none","votes-for":"DKF, JN","created":"23-Oct-2018","title":"# TIP 524: Custom Definition Dialects for TclOO","post-history":"","vote":"Done","tcl-version":"8.7","tcl-branch":"tip-524","votes-present":"BG, KBK, FV, SL","is-jest":false},
     4         -	"523":{"url":"./tip/523.md","keywords":"queue, stack, pop","state":"Final","vote-summary":"Accepted 7/0/0","type":"Project","author":["Peter Spjuth <[email protected]>"],"votes-against":"none","votes-for":"DKF, KBK, JN, DGP, FV, SL","created":"22-Oct-2018","title":"# TIP 523: New lpop command","post-history":"","vote":"Done","tcl-version":"8.7","tcl-branch":"tip-523","votes-present":"BG","is-jest":false},
            5  +	"523":{"url":"./tip/523.md","keywords":"queue, stack, pop","state":"Final","vote-summary":"Accepted 7/0/0","type":"Project","author":["Peter Spjuth <[email protected]>"],"votes-against":"none","votes-for":"DKF, BG, KBK, JN, DGP, FV, SL","created":"22-Oct-2018","title":"# TIP 523: New lpop command","post-history":"","vote":"Done","tcl-version":"8.7","tcl-branch":"tip-523","votes-present":"none","is-jest":false},
     5      6   	"522":{"url":"./tip/522.md","keywords":"tcltest, error codes","state":"Final","type":"Project","author":["Peter Spjuth <[email protected]>"],"vote-results":"8/0/0 accepted","votes-for":"KBK, SL, AF, DGP, FV, DKF, AK, JN","votes-against":"none","created":"22-Oct-2018","title":"# TIP 522: Test error codes with Tcltest","post-history":"","tcl-branch":"tip-522","vote":"Done","tcl-version":"8.7","votes-present":"none","is-jest":false},
     6      7   	"521":{"url":"./tip/521.md","keywords":"Tcl, floating point, NaN, not a number","created":"21 October 2018","post-history":"","state":"Draft","tcl-version":"8.7","vote":"Pending","type":"Project","title":"# TIP 521: Floating Point Classification Functions","author":["Kevin B. Kenny <[email protected]>"],"is-jest":false},
     7      8   	"520":{"url":"./tip/520.md","keywords":"Tcl, floating point, NaN, not a number","created":"18 October 2018","post-history":"","state":"Draft","tcl-branch":"tip-520","tcl-version":"8.7","vote":"Pending","type":"Project","title":"# TIP 520: Make NaN Quiet","author":["Kevin B. Kenny <[email protected]>"],"is-jest":false},
     8      9   	"519":{"url":"./tip/519.md","":"","keywords":"TclOO","state":"Final","vote-summary":"Accepted 4/0/2","this tip proposes to extend the `method` subcommand of the `oo":":define` command","type":"Project","author":["Pietro Cerutti <[email protected]>"],"votes-against":"none","votes-for":"DKF, KBK, JN, SL","follows":"","oo":":define RPCClient {","created":"18-Oct-2018","title":"# TIP 519: Inline export/unexport option to TclOO method definition","the class definition in the previous example would then be as follows":"","post-history":"","vote":"Done","tcl-version":"8.7","tcl-branch":"tip-519","votes-present":"BG, FV","is-jest":false},
     9     10   	"518":{"url":"./tip/518.md","keywords":"Tk","state":"Final","vote-summary":"Accepted 6/0/0","type":"Project","tk-branch":"tip518-event-last-child-unmanaged","author":["Harald Oehlmann <[email protected]>"],"votes-against":"none","votes-for":"DKF, BG, KBK, JN, FV, SL","created":"22-Sep-2018","title":"# TIP 518: Virtual Event when Last Child is not Managed any more","post-history":"","vote":"Done","tcl-version":"8.7","votes-present":"none","is-jest":false},
    10     11   	"517":{"url":"./tip/517.md","keywords":"tk menu","created":"13-Sept-2018","post-history":"","state":"Final","tk-branch":"tip-517","tcl-version":"8.7","vote":"Done","type":"Project","title":"# TIP 517: Add -activerelief Configuration Option to the menu widget","author":["Francois Vogel <[email protected]>"],"is-jest":false},
    11     12   	"516":{"url":"./tip/516.md","keywords":"Tcl, TclOO","state":"Final","type":"Project","author":["Donal K. Fellows <[email protected]>"],"vote-results":"4/0/5 accepted","votes-for":"DKF, JN, JD, AK","votes-against":"none","created":"7-Sept-2018","title":"# TIP 516: More OO Slot Operations","post-history":"","tcl-branch":"tip-516","vote":"Done","tcl-version":"8.7","votes-present":"BG, KBK, DGP, FV, SL","is-jest":false},
................................................................................
   522    523   	"5":{"url":"./tip/5.md","created":"17-Oct-2000","post-history":"","state":"Final","vote":"Done","tcl-version":"8.4","type":"Project","title":"# TIP 5: Make TkClassProcs and TkSetClassProcs Public and Extensible","author":["Eric Melski <[email protected]>"],"is-jest":false},
   523    524   	"4":{"url":"./tip/4.md","created":"26-Oct-2000","post-history":"","state":"Draft","vote":"Pending","type":"Informative","title":"# TIP 4: Tcl Release and Distribution Philosophy","discussions-to":"news:comp.lang.tcl","author":["Brent Welch <[email protected]>","Donal K. Fellows <[email protected]>","Larry W. Virden <[email protected]>","Larry W. Virden <[email protected]>"],"is-jest":false},
   524    525   	"3":{"url":"./tip/3.md","created":"14-Sep-2000","post-history":"","state":"Accepted","vote":"Done","type":"Process","title":"# TIP 3: TIP Format","author":["Andreas Kupries <[email protected]>","Donal K. Fellows <[email protected]>"],"is-jest":false},
   525    526   	"2":{"url":"./tip/2.md","created":"12-Sep-2000","post-history":"","state":"Draft","vote":"Pending","type":"Process","title":"# TIP 2: TIP Guidelines","author":["Andreas Kupries <[email protected]>","Donal K. Fellows <[email protected]>","Don Porter <[email protected]>","Mo DeJong <[email protected]>","Larry W. Virden <[email protected]>","Kevin Kenny <[email protected]>"],"is-jest":false},
   526    527   	"1":{"url":"./tip/1.md","created":"14-Sep-2000","post-history":"","state":"Active","vote":"No voting","type":"Informational","title":"# TIP 1: TIP Index","author":["TIP Editor <[email protected]>"],"is-jest":false},
   527    528   	"0":{"url":"./tip/0.md","created":"11-Dec-2000","post-history":"","state":"Final","vote":"Done","type":"Process","title":"# TIP 0: Tcl Core Team Basic Rules","author":["John Ousterhout <[email protected]>"],"is-jest":false},
   528    529   	"@min": 0,
   529         -	"@max": 525
   530         -}, "@timestamp": 1541517293}
          530  +	"@max": 526
          531  +}, "@timestamp": 1541672033}

Changes to index.md.

   116    116   <th>Type</th>
   117    117   <th>Tcl Version</th>
   118    118   <th>Status</th>
   119    119   <th>Title</th>
   120    120   <th>Impl.</th>
   121    121   </tr></thead><tbody>
   122    122   
          123  +<tr class='project projectdraft projectdraft90 project90'>
          124  +<td valign='top'><a href='./tip/526.md'>526</a></td>
          125  +<td valign='top'>Project</td>
          126  +<td valign='top'>9.0</td>
          127  +<td valign='top'>Draft</td>
          128  +<td valign='top'># TIP 526: Make [expr] Only Accept One Argument</td>
          129  +<td></td>
          130  +</tr>
   123    131   <tr class='project projectfinal projectfinal85 project85'>
   124    132   <td valign='top'><a href='./tip/525.md'>525</a></td>
   125    133   <td valign='top'>Project</td>
   126    134   <td valign='top'>8.5</td>
   127    135   <td valign='top'>Final</td>
   128    136   <td valign='top'># TIP 525: Make Tcltest Report Overall Success in a Machine-Readable Way</td>
   129    137   <td></td>

Added tip/526.md.

            1  +# TIP 526: Make [expr] Only Accept One Argument
            2  +	Author:         Donal K. Fellows <[email protected]>
            3  +	State:          Draft
            4  +	Type:           Project
            5  +	Vote:           Pending
            6  +	Created:        08-Nov-2018
            7  +	Tcl-Version:    9.0
            8  +	Post-History:
            9  +------
           10  +
           11  +# Abstract
           12  +
           13  +This TIP proposes that `expr` should only accept a single argument and stop
           14  +accepting and concatenating arguments.
           15  +
           16  +# Rationale and Discussion
           17  +
           18  +A very common fault of `expr` usage is to fail to brace expressions. This was
           19  +semi-good practice in Tcl 7.6 and before as Tcl's substitution phase was
           20  +faster than the expression evaluation engine's, but it was always a little
           21  +tricky even then as it depended on you being sure that the substituted values
           22  +were numeric for safety. When that critical side condition didn't hold, it
           23  +resulted in unsafe code:
           24  +
           25  +    proc addFive {x} {
           26  +        expr $x + 5
           27  +    }
           28  +    puts [addFive 17];                 # ==> 22
           29  +    puts [addFive {[exec format C:]}]; # OOPS!
           30  +
           31  +From Tcl 8.0 onwards, this was no longer a good idea. The bytecode compiler is
           32  +able to generate compiled code ahead of time for braced expressions, but is
           33  +not able to do so (usefullly) if any of the arguments to `expr` are unbraced.
           34  +Of course, we want to be able to use an unbraced argument occasionally, such
           35  +as when we take an expression as an argument from elsewhere, but those are
           36  +very much the unusual case: almost always, a call to `expr` with any argument
           37  +unbraced is _both_ a performance bug and a security bug.
           38  +
           39  +Because this is so strongly the case, there are uses of Tcl that are almost
           40  +always a problem; for example:
           41  +
           42  +    expr $x >= "inf";   # where $x is expected to be a string
           43  +
           44  +# Proposal
           45  +
           46  +To reduce the incidence of this, I propose that in Tcl 9.0 the `expr` command
           47  +should only take a single argument. It most definitely isn't a total fix for
           48  +this — a total fix isn't really possible without making the `expr` command
           49  +special in the Tcl base language, and that goes against the general principle
           50  +that _nothing_ is special there — but it will at least reduce the incidence a
           51  +bit by encouraging people to either brace their expressions or be very clear
           52  +that they are not doing so.
           53  +
           54  +This will leave virtually all correct code working, and yet force code that
           55  +has a problem to acknowledge the fact.
           56  +
           57  +Supported cases:
           58  +
           59  + 1. Braced expressions:
           60  +
           61  +        expr {$x * 5}
           62  +
           63  + 2. Expressions in variables:
           64  +
           65  +        set theExpression {$x * 5}
           66  +        expr $theExpression
           67  +
           68  + 3. Expressions from commands:
           69  +
           70  +        expr [dict get $myExpressions thisCase]
           71  +
           72  +Cases that work because we can't stop them without breaking the language:
           73  +
           74  + 1. Expressions in double quotes:
           75  +
           76  +        expr "$x * 5"
           77  +
           78  + 2. Expressions with unquoted compound substitutions:
           79  +
           80  +        expr $x*5+[llength $y]
           81  +
           82  +Cases that are outright rejected:
           83  +
           84  + 1. Expressions with multiple arguments:
           85  +
           86  +        expr $x * 5
           87  +
           88  + 2. Expressions with multiple literal arguments (uncommon):
           89  +
           90  +        expr {$x} *5
           91  +
           92  +## Workarounds for Broken Old Code
           93  +
           94  +The cases where someone genuinely needs the old behaviour can be handled by
           95  +them using `concat` (or `string cat`, depending on exact requirements)
           96  +explicitly to make the expression:
           97  +
           98  +    set x {2 + 3}
           99  +    expr [concat $x * 5]
          100  +
          101  +That still has the faults, but now at least looks like it is doing something
          102  +tricky. Which it is, given that the actual behaviour of the equivalent code in
          103  +Tcl 8 is so messy. Another alternative (and a better one in this particular
          104  +case) is:
          105  +
          106  +    set x {2 + 3}
          107  +    expr {[expr $x] * 5}
          108  +
          109  +That also looks weird, but is better in that it only has the potential for
          110  +trouble in one place and allows for better compilation of the outer parts of
          111  +the expression. (Yes, it produces a different result from the other code. This
          112  +is likely to be a good thing in almost all cases.)