TIP 347: Align 'string is ...' to Type-Conversion Functions in 'expr'

Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2017 Conference, Houston/TX, US, Oct 16-20
Send your abstracts to tclconference@googlegroups.com
by Aug 21.
Author:         Jos Decoster <jos.decoster@gmail.com>
State:          Withdrawn
Type:           Project
Vote:           Pending
Created:        09-Feb-2009
Post-History:   
Discussions-To: news:comp.lang.tcl
Keywords:       Tcl
Tcl-Version:    8.7
Obsoleted-By:	395

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 #2581150http://sourceforge.net/tracker2/?func=detail&aid=2581150&group_id=10894&atid=310894 .

Copyright

This document has been placed in the public domain.

History