Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7764577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:56:52+00:00 2026-06-01T14:56:52+00:00

Tcl 8.4. I have this namespace tree: namespace eval menu_tree { #————————————————————————– ## Main

  • 0

Tcl 8.4.

I have this namespace tree:

namespace eval menu_tree {

    #--------------------------------------------------------------------------
    ## Main Menu
    namespace eval main_menu {
        variable title "Main Menu"
    }

    #--------------------------------------------------------------------------
    ## Setup Menu
    namespace eval setup_menu {
        variable title "Show Setup Information"
    }

    #--------------------------------------------------------------------------
    ## Help Menu
    namespace eval help_menu {
        variable title "Show Help Information"
    }
}

The idea was to have a function like this:

proc print_title {menu} {
    puts $menu::title
}

This would work fine with global variables. However, from what I can find, using ‘$’ with namespace names is required. I have tried to find the answer on the web, but nothing came up.
Does anyone know how to do it, and if it is even possible?

Thank you,
-Ilya.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:56:53+00:00Added an answer on June 1, 2026 at 2:56 pm

    Well, the key approach here is to keep in mind that “the original Tcl” did not have that “$” syntactic sugar at all. The original way to get the contents of a variable is a one-argument call to set:

    set foo bar ;# sets variable "foo" to contain the value "bar"
    puts [set foo] ;# prints the value contained in variabe "foo"
    

    Hence you’ll probably should use something like

    proc print_title {menu} {
        puts [set ${menu}::title]
    }
    

    so that ${menu}::title expands to the name of a variable then set retrieves the value of that variable.

    Note the usage of curly braces around the word “menu”–without them, Tcl would try to dereference a variable named “menu::title” which is probably not what you intended.

    Another thing to observe is that the behaviour of print_title highly depends on the contents of the “menu” argument: after it’s expanded, the set command must see a string which it should be able to resolve, and this is subject to a set of rules. It’s hard to get further advice until more details is known though.

    Refer to this question for more info about on that $ vs set topic.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file named test7.tcl: namespace eval ::dai { variable name ratzip variable
I have two question about namespace in Tcl. namespace eval ::dai { set a
Is there an easy way to unroll the stack in Tcl? I have this
I have used some TCL, but this construction stumps me. When $res = Table
I have to write this code in tcl and I am really frustrated because
I have a Tcl/Tk app that generates many forms and would like to be
I inherited a TCL script (I have zero familiarity with the language) and need
I have a question about list in tcl, what is the correct way to
I have a small shell application that embeds Tcl to execute some set of
Greetings, I'm new to TCL scripting, and I have a very very basic xml

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.