Tags and Properties for Check-in 1508c3d76a
- branch=tip-764_tcl90 inherited from [957c079f46]
- comment=Version 16p adds a field to the `Proc` structure. It allows for the typing of both the return value and the arguments of procedures. Example: tcl proc {pt}decale { {pt}p; {double}dx ?= 0; {double}dy ?= 0 } { set {pt}q [expr {$p(x) + $dx}] [expr {$p(y) + $dy}] return $q } set {pt}a 1 2 decale $a 1 1 ;# positional decale $a {dy:}5 ;# positional, followed by labels decale {dy:}5 {p:}$a ;# labels only, in any order Arguments Fields: Each field becomes a local variable subject to its defined contract. Defaults: `?= v` or `?= [cmd]`—evaluated at each procedure call; it may reference preceding fields. Remainder: A final field, `{list.T}args`, collects any excess arguments, each of which is validated. Automatic `upvar`: `{var.T}n` binds `n` to a variable in the callers scope, with its current value being validated. Call-site labels: Positional arguments following a label are disallowed; providing the same field twice or using an unknown label will also result in an error. Exception: If the target field is a sum type, the label selects the specific variant (e.g., `ps {s:}abc`). Messages: These take forms such as `wrong # args: should be "decale p ?dx? ?dy?"` or `argument "dx": expected floating-point number but got "abc"`. Return Value Cast: `proc {T}name` casts the result of a standard `return` to type `T`. Errors, `break`, `return -level 2`, `tailcall`, and `yield` are not subject to this cast. Local annotation: `return {U}$x` simply attaches an annotation, which expires when the procedure terminates. There is, therefore, no type overlapping (or "cumulation" of types). Tags: When a return value is a sum type, `return {point:}$z` selects the specific variant, and a strict sum type (`-strict`) mandates it. Using a tag that is not a valid variant, or applying one to a return value that is not a sum type, results in an error. Introspection and compatibility `type proc name returns args {…} return T`—`info args` and `info default` can "see" the fields. A valid Tcl list remains a standard list of arguments. An initial attempt caused the `proc-old-5.4` test to fail (due to an unclosed brace); this has been fixed, and the standard error is now correctly returned. Performance cost: A call with 3 arguments takes 1.2 µs, compared to 0.6 µs for an equivalent standard procedure. The return-type cast incurs no overhead if the value is already of the correct type. See next commit for complements added by [6db2c7794d] on 2026-11-05 09:31:42
- sym-tip-764_tcl90 inherited from [957c079f46]
Context
|
2026-11-05
| ||
| 09:31 | • Edit [1508c3d76a]: Edit check-in comment. artifact: 6db2c7794d user: Florentis | |
| 08:59 | Version 16p adds a field to the `Proc` structure. It allows for the typing of both the return value ... check-in: 1508c3d76a user: Florentis tags: tip-764_tcl90 | |
|
2026-10-13
| ||
| 08:17 | Annoted values and typed variables check-in: 957c079f46 user: Florentis tags: tip-764_tcl90 | |