2026-11-05 11:19:41
— part of check-in
[71c944ab7a]
on branch tip-764_tcl90
— v16q (options and flags):
only tclTypes.c and tclTypeParse.c are modified.
A group is defined using the syntax {T}-o
tcl
proc {list}trier {
{flag}-decreasing;
{int}-index ?= -1;
{"ascii", "dictionary", "integer", {string}command}-mode ?= ascii;
{list}l
} {...}
trier -dec -index 1 -integer $L
Syntax and invocation
A field denoted as -x is an option, provided at the beginning of the call. Options end at the first word that is not an option, at --, or at a negative number (e.g., -5).
Prefixes: a unique prefix is sufficient (e.g., -dec). The corresponding local variable omits the leading hyphen.
Flags: {flag}-x results in a local variable set to 1 or 0. `flag` is a new, predefined type.
Options with values: {T}-x ?= v, where the value is validated. If the option is omitted and no default is provided, the local variable is not created.
Exclusive options (a sum type)
Each variant acts as an option: -ascii (a literal, value-less option), -command cmd (a typed variant with a value), or -mode ascii.
The local variable `mode` receives the name of the chosen variant, while the local variable `command` receives its associated value.
Selecting two different variants triggers an error: "options -ascii and -integer are exclusive." The default value must specify one of the variants.
Dependent options (a product type)
Example: {"flat", {{string}cmd; {int}-depth ?= 1; {flag}-follow}command}-mode.
The invocation -command ls -depth 3 -follow is accepted, whereas -depth on its own results in the error: "option -depth requires -command." Group
{triopts}-o: the `triopts` fields represent the available options—including variations of a "sum" field—where `o` is a specific `triopts` value.
A single group can be used for multiple procedures.
Messages and introspection
Error messages follow the Tcl style: e.g., `bad option "-zz": must be -ascii, -command, …`, `ambiguous option "-d": …`, or `option "-index" needs a value`.
The usage message lists the available options: `?-decreasing? ?-index value? ?-ascii|-dictionary|-integer|-command value?`.
`info args` and `info default` recognize these options; for a flag (boolean option), `info default` returns `0`.
(user:
Florentis,
size: 3196)
[annotate]
[blame][check-ins using]
2026-11-27 09:47:31
— part of check-in
[eacc36058b]
on branch tip-764_tcl90
—
v17z
Review of sum type notation.
- A variant of a sum is metadata, it must not appeat into the value :
If there is ambiguity to choose a variant of a sum, it must be an error.
- New commands to request variants of a sum type, or of a litteral sum :
type variant $v ?NAME? : empty for a litteral ; NAME select the variant of the value.
type variant -of T ?NAME?
type literal -of T ;
type is {sum?}T
type is {enum?}T
- New command to compare the type of a value :
type eq T1 T2 : true is types T1 and T2 are equal
type include T1 T2 : true if type T2 is included into T1
- New type 'num'
(user:
Florentis,
size: 3196)
[annotate]
[blame][check-ins using]