From Newsgroup: comp.lang.tcl
On Fri, 19 Dec 2025 09:26:26 +0100, Harald Oehlmann wrote:
Am 19.12.2025 um 09:20 schrieb Mark Summerfield:
At the moment when I want a class to provide a const I write code like this: >>
oo::singleton create Mplayer {}
oo::define Mplayer initialize {
variable FILETYPES
const FILETYPES {{{Audio Files} {.mp3 .ogg}}}
}
oo::define Mplayer classmethod filetypes {} {
variable FILETYPES
return $FILETYPES
}
This means I can access the const outside the class using the method, e.g., >>
set filename [tk_getOpenFile -filetypes [Mplayer filetypes] ...]
I was wondering if there was a shorter/better way to do this?
I am not so much in Tcl-OO, but Tcl 9.0 has a const keyword. https://core.tcl-lang.org/tips/doc/trunk/tip/677.md
Maybe, this might help.
THanks for all,
Harald
Hi Harald,
I am using `const` already in the `initialize` method.
What I was wondering was if there was an easier/simpler
way to provide class constants. I'm fine with the
initialize/classmethod approach I'm using, but thought
there might be a better way I didn't know about.
--- Synchronet 3.21a-Linux NewsLink 1.2