TIP 395: New 'string is entier' Command

Login
Bounty program for improvements to Tcl and certain Tcl packages.
Author:         Jos Decoster <jos.decoster@gmail.com>
State:          Final
Type:           Project
Vote:           Done
Created:        13-Dec-2011
Post-History:   
Discussions-To: news:comp.lang.tcl
Keywords:       Tcl
Tcl-Version:    8.6
Obsoletes:	347

Abstract

The string is command supports tests for a number of Tcl's basic types, for example, integers, doubles, and booleans. One common case is missing: checking if a value is an integer number without particular storage width, unlike string is integer and string is wideinteger. This document proposes to augment the string is command with a string is entier.

Rationale

Tcl makes it easy to work with integers larger than 64 bit (big nums). The expr command supports operations on unlimited bit widths. Checking if a string contains a valid integer value is possible with the string is integer and string is wideinteger commands for integers of particular storage widths (e.g. 32 bit for integers and 64 bit for wide integers). But checking if a string contains a valid integer wider than a wideinteger is not possible with a string is command. Checking if a string contains a valid big num can now be done with a regular expression or by catch-ing the ::tcl::mathfunc::entier function.

Specification

This document proposes to augment the string is command with a string is entier which 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.

Compatibility

No incompatibilities are introduced.

Alternatives

The bignum was rejected in favor of entier because entier is already used in ::tcl::mathfunc::entier.

Reference Implementation

A reference implementation is available here:

<http://sites.google.com/site/josdecoster/Home/tip\_string\_is\_entier.diff>

Copyright

This document has been placed in the public domain.

History