# TIP 515: Level Value Reform
Author: Jan Nijtmans <[email protected]>
State: Final
Type: Project
Vote: Done
Created: 7-Sept-2018
Post-History:
Tcl-Version: 8.7
Vote-Results: 8/0/1 accepted
Votes-For: DKF, KBK, JN, JD, DGP, FV, SL, AK
Votes-Against: none
Votes-Present: BG
Tcl-Branch: tip-515
-----
# Abstract
Proposes reformed handling of Tcl level values. This TIP is inspired by TIP #502, which handles "index" values, realizing that "level" values have
kind of the same problems as described there.
# Background
Many Tcl programmers may be surprised by these results
% apply {{} {uplevel -4294967294 {puts OK}}}
bad level "-4294967294" (OK, this is expected ....)
% apply {{} {uplevel -4294967295 {puts OK}}}
OK
% apply {{} {uplevel -4294967296 {puts OK}}}
invalid command name "-4294967296"
I would expect the same "bad level" error in all 3 cases.
Or:
% proc todo arg {puts $arg}
% apply {{} {uplevel todo OK}}
OK
% proc 2do arg {puts $arg}
% apply {{} {uplevel 2do OK}}
bad level "2do"
Why can't we call a command "2do"? The parser appears to be confused because the command name starts with a digit.
# Proposal
Revise the parsing of values used as level values to accept all
integer representations acceptable to **expr**, optionally
preceded by "#".
Although this suggests an unlimited range of valid levels,
in practice all out-of-range levels (either a negative number,
either a number higher than the actual available number of levels) ,
will result in a "bad level" error.
# Compatibility
Examples like the ones in the Background above will incompatibly
change from one outcome to a different outcome.
This is a true incompatibility, but it is difficult to believe anyone
actually desires the outlier behaviors illustrated above, much less has
code that relies on them.
New behavior, one that succeeded in Tcl 8.6 but should actually fail:
% apply {{} {uplevel -4294967295 {puts OK}}}
bad level "-4294967295"
Another example, of a situation that failed in Tcl 8.6 but should succeed:
$ proc 2do arg {puts $arg}
% apply {{} {uplevel 2do OK}}
OK
# Implementation
Currently, the proposed implementation is available in the [tip-515 branch]
(https://core.tcl-lang.org/tcl/timeline?r=tip-515).
# Copyright
This document has been placed in the public domain.