TIP: | 347 |
Title: | Align 'string is ...' to Type-Conversion Functions in 'expr' |
Version: | $Revision: 1.8 $ |
Author: | Jos Decoster <jos dot decoster at gmail dot com> |
State: | Withdrawn |
Type: | Project |
Tcl-Version: | 8.7 |
Vote: | Pending |
Created: | Monday, 09 February 2009 |
Discussions To: | news:comp.lang.tcl |
Obsoleted-By: | TIP #395 |
Keywords: | Tcl |
The string command supports tests for a number of Tcl's basic types, for example, integers, doubles, and booleans. The tcl::mathfunc mathematical functions provides sevaral functions to limit the number of bits used in integer numbers. This TIP proposes to align both groups of functions for int, long, wide and entier.
The string command includes tests for the common Tcl types: string is boolean, string is double and string is integer. Some of the integer ranges used in Tcl internals are missing from the list, making it difficult for an input validation procedure to determine whether, in fact, a string contains a valid integer number to be used for that specific Tcl command.
Ranges already present are:
integer
wideinteger
Missing ranges are:
long
entier
The ::tcl::mathfunc mathematical functions provides sevaral functions to limit the number of bits used in integer numbers. Some of the integer ranges used in Tcl internals are missing from the list, and other check an unexpected range.
Functions already present are:
wide
entier
Functions already present but with unexpected behavior are:
int actually does a long conversion
Missing functions are:
long
Providing a string is function for every integer range used in Tcl internals will make it possible to check every argument in input validation procedures before calling a Tcl command. Providing ::tcl::mathfunc for every integer range used in Tcl internals will make it possible to create values in a valid range before calling a Tcl command.
Having the same integer range names in the string is functions and in the ::tcl::mathfunc when they act on the same integer ranges would make the commands easier to recognise.
This document proposes:
augmenting the string is command with a string is long that functions the same as string is integer in every respect except for the fact that it accepts any string containing a substring that is valid as a long integer (that is, acceptable to Tcl_GetLongFromObj) possibly surrounded by whitespace.
augmenting the string is command with a string is entier that functions the same as string is integer in every respect except for the fact that it accepts any string containing a substring that is valid as a bignum integer (that is, acceptable to Tcl_GetBignumFromObj) possibly surrounded by whitespace.
modifying the ::tcl::mathfunc::int to convert to an integer (that is, acceptable to Tcl_GetIntFromObj).
adding the ::tcl::mathfunc::long to convert to a long integer (that is, acceptable to Tcl_GetLongFromObj).
keeping the string is integer command as it can be abbreviated to string is int to align with ::tcl::mathfunc::int.
keeping the string is wideinteger command as it can be abbreviated to string is wide to align with ::tcl::mathfunc::wide.
On platforms where a 'long variable has a different range than an int variable, renaming the ::tcl::mathfunc::int to ::tcl::mathfunc::long will let code like:
| set a [expr {int($b)}]
behave differently for long values outside the int range.
The bignum was rejected in favor of entier because entier is already used in ::tcl::mathfunc::entier.
Patches that implement the above, provide test cases for it, and update documentation to include it are available at SourceForge as Tcl Patch #2581150[1].
This document has been placed in the public domain.
[Index] [History] [HTML Format] [Source Format] [LaTeX Format] [Text Format] [XML Format] [*roff Format (experimental)] [RTF Format (experimental)]
TIP AutoGenerator - written by Donal K. Fellows