TIP #347: Align 'string is ...' to Type-Conversion Functions in 'expr'
_____________________________________________________________________________
TIP:	347
Title:	Align 'string is ...' to Type-Conversion Functions in 'expr'
Version:	$Revision: 1.8 $
Authors:	Jos Decoster <jos.decoster@gmail.com>
State:	Withdrawn
Type:	Project
Tcl-Version:	8.7
Vote:	Pending
Created:	Mon Feb 09 00:00:00 UTC 2009
Keywords:	Tcl
Abstract
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.
Rationale
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.
Specification
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.
Compatibility
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.
Alternatives
The bignum was rejected in favor of entier because entier is already used in ::tcl::mathfunc::entier.
Reference Implementation
Patches that implement the above, provide test cases for it, and update documentation to include it are available at SourceForge as Tcl Patch #2581150[http://sourceforge.net/tracker2/?func=detail&aid=2581150&group_id=10894&atid=310894].
Copyright
This document has been placed in the public domain.
_____________________________________________________________________________
Colophon
TIP AutoGenerator - written by Donal K. Fellows