• Providing const's in classes

    From Mark Summerfield@m.n.summerfield@gmail.com to comp.lang.tcl on Fri Dec 19 08:20:51 2025
    From Newsgroup: comp.lang.tcl

    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?
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Harald Oehlmann@wortkarg3@yahoo.com to comp.lang.tcl on Fri Dec 19 09:26:26 2025
    From Newsgroup: comp.lang.tcl

    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
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Mark Summerfield@m.n.summerfield@gmail.com to comp.lang.tcl on Fri Dec 19 11:21:02 2025
    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