Is it possible to create class-specific consts i.e., consts that exist inside a class's namespace?
Mark Summerfield <[email protected]> wrote:
Is it possible to create class-specific consts i.e., consts that existTcl does not have "constants" in the vien of other languages
inside a class's namespace?
"constants".
However, there are several ways to "roll your own": https://wiki.tcl-lang.org/page/constants
On Fri, 20 Jun 2025 13:28:13 -0000 (UTC), Rich wrote:
Mark Summerfield <[email protected]> wrote:
Is it possible to create class-specific consts i.e., consts that existTcl does not have "constants" in the vien of other languages
inside a class's namespace?
"constants".
However, there are several ways to "roll your own":
https://wiki.tcl-lang.org/page/constants
According to https://www.tcl-lang.org/man/tcl9.0/TclCmd/const.html
"const — create and initialize a constant"
And I use them quite a lot since I'm using Tcl 9.
Perhaps the wiki needs updating?
Mark Summerfield <[email protected]> wrote:
On Fri, 20 Jun 2025 13:28:13 -0000 (UTC), Rich wrote:
Mark Summerfield <[email protected]> wrote:
Is it possible to create class-specific consts i.e., consts thatTcl does not have "constants" in the vien of other languages
exist inside a class's namespace?
"constants".
However, there are several ways to "roll your own":
https://wiki.tcl-lang.org/page/constants
According to https://www.tcl-lang.org/man/tcl9.0/TclCmd/const.html
"const — create and initialize a constant"
And I use them quite a lot since I'm using Tcl 9.
Ah, it seems Tcl 9 added "const" capabilities.
Perhaps the wiki needs updating?
Indeed, that would seem to be the case.
Is it possible to create class-specific consts i.e., consts that exist inside a class's namespace?
For example, this does _not_ work:
```
oo::class create Klass {
const SPECIAL special
method say {} { return $SPECIAL }
}
set klass [Klass new]
puts "$Klass::SPECIAL [$klass say]"
```
On Fri, 20 Jun 2025 07:58:37 -0000 (UTC)
Mark Summerfield <[email protected]> wrote:
Is it possible to create class-specific consts i.e., consts that exist inside a class's namespace?
For example, this does _not_ work:
```
oo::class create Klass {
const SPECIAL special
method say {} { return $SPECIAL }
}
set klass [Klass new]
puts "$Klass::SPECIAL [$klass say]"
```
Maybe there are more straightforward methods, but this one works:
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 1,070 |
Nodes: | 10 (0 / 10) |
Uptime: | 171:05:37 |
Calls: | 13,735 |
Calls today: | 1 |
Files: | 186,967 |
D/L today: |
184 files (54,870K bytes) |
Messages: | 2,419,004 |