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:
% oo::class create C {
method foo {} { # reads the constant
classvariable CVar
puts $CVar
}
method bar {} { # tries to set the constant
classvariable CVar
set CVar "other value"
}
}
::C
% namespace eval [info object namespace C] {
# defines the constant in the class namespace
const CVar "My class variable"
}
% C create o
::o
% o foo
My class variable
% o bar
can't set "CVar": variable is a constant
Regards
--
Emiliano
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)