Is it possible to create class-specific consts i.e., consts that exist inside a class's namespace?
Mark Summerfield <m.n.summerfield@gmail.com> 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 <m.n.summerfield@gmail.com> 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 <m.n.summerfield@gmail.com> wrote:
On Fri, 20 Jun 2025 13:28:13 -0000 (UTC), Rich wrote:
Mark Summerfield <m.n.summerfield@gmail.com> 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 <m.n.summerfield@gmail.com> 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,064 |
Nodes: | 10 (0 / 10) |
Uptime: | 163:56:40 |
Calls: | 13,691 |
Calls today: | 1 |
Files: | 186,936 |
D/L today: |
9,208 files (2,741M bytes) |
Messages: | 2,411,516 |