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 $
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

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:

Missing ranges are:

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:

Functions already present but with unexpected behavior are:

Missing functions are:

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:

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[1].

Copyright

This document has been placed in the public domain.


Powered by Tcl[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