Types
Types provide a mechanism
for validating parameters to Tcl command and/or proc calls.
A type is simply defined as a string-name followed optionally by parameters.
The special type "." can also be used
for typeless strings. Following is a list of teh builtin types:
int double bool array avar blist choice channel char cmd
code subcode dict dir date datetime dictvar enum eval
expr exprn file float intersect list long match matchi
opts options ns noquote regexp regexpi short string time
tkwin tkfont tkcolor tkcursor tkpixel tkbitmap tkimage
topts uchar uint ulong union ushort uwide var void vopts
wide win _ . *
Type Arguments
Some types take arguments. eg.
{choice A B C}
{match [0-9]*}
Type arguments allow fine grained checking of command arguments.
Strictness
When a type is used with
the first letter uppercased, it implies strict typeness.
Generally a non-strict type will accept the empty string as a value, but
the definition of strictness can vary from type to type.
Special Types
Four types opts, topts, vopts, and choice perform a special function.
They are used in externs, particularly for many of Tcl and Tks builtin commands.
Types opts and topts are exclusively applied to the "args" argument, ie. the
trailing arguments. The vopts type
describes a set of options that precede the last or trailing args
argument. An extern that uses vopts must also use args, but when the
command really does take variable arguments, it should end with a "*", eg.
extern exec {arg args} {. {vopts ?-keepnewline? ?--?}} I
extern switch {string body args} {. {vopts ?-exact? ?-glob? ?-regexp? ?--? *}} I
Types List
The list of the standard types (with brief description) follows:
int - Tcl int
double - Tcl double
bool - Tcl bool
blist - A binary list (even number of elements).
choice - Select one value from a list of choices
char - Tcl char.
cmd - Argument is count of args that will be added to Tcl command
code - Tcl script that will be evaluate.
dict - A dict value.
date - A date with no time.
datetime - A date with time.
dictvar - A variable containing a dict.
expr - A valid Tcl expression is expected.
file - A file name.
float - Tcl float
list - Tcl list.
long - Tcl long
match - Argument is used in a string match.
matchi - Argument is used in a string match.
opts - Name/value pairs where name is from a list of choices.
noquote - N/A
regexp - Argument is used in a regexp.
regexpi - Argument is used in a regexp, case insensitive.
short - Tcl short
string - A string. Same as .
time - Time with no date.
topts - Name/value pairs where name/type is from a list of choices
uchar - Tcl unsigned char
uint - Tcl unsigned int
ulong - Tcl unsigned long
ushort - Tcl unsigned short
uwide - Tcl unsigned wide
var - A Tcl variable.
void - A proc returns an empty string
vopts - Variable or optional choices preceding an argument.
wide - Tcl wide.
win - A Tk window path.
_ - A TOD object.
. - A string.
Experimental Types
The following are extended types for the typedef and rec facility.
These are still under development.
array - An array.
enum - An enum.
struct - A struct or record defn.
tablearray - Array of records.
tabledict - Dict of records.
tableiarray - Array of records, integer indexed.
tableidict - Dict of records, integer indexed.
tablelist - List of records.
field - A field in a struct.
fieldst - VARIDX that must point to a struct
fieldts - VARIDX must point list/array of structs.
fieldtsa - VARIDX must point assoc list/array of structs.
fieldval - Field and next arg must match the type.
© 2008 Peter MacDonald