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 8113791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:56:42+00:00 2026-06-06T02:56:42+00:00

I have a question about variable scope in TCL, I have the following code:

  • 0

I have a question about variable scope in TCL, I have the following code:

 namespace eval ::hello {
    variable player
    variable name
    namespace export *
}


proc ::hello::setPlay {value} {
    set ::hello::player
}

proc ::hello::getPlay {} {
    return $::hello::player
}

proc ::hello::setName {value} {
    set ::hello::name
}

proc ::hello::getName {} {
    return $::hello::name
}

proc GET_NAME {} {
    #here I have a variable called name as well
    set name "RON"
    return $name
}

in the GET_NAME,if I set the variable name as “RON”, does it will set the variable name declaired in namespace? can I have the same variable name in GET_NAME and namespace? And if I add this line variable name in GET_NAME, does this mean, it will set the variable declaired in name space?

  • 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-06T02:56:44+00:00Added an answer on June 6, 2026 at 2:56 am

    Variables in procedures (and lambda expressions) default to being local to that procedure. If explicitly declared to be something else (e.g., with global, upvar or variable) then that actually couples a local variable to another variable elsewhere so that acting on one (e.g., reading or writing) is exactly like acting on the other. If you use a variable name with :: in it, that is a reference to a namespaced variable (the global namespace is just ::) which might be resolved either relative to the current namespace or the global namespace, depending on whether the name starts with :: or not. (Think of it a bit like a slash in a filename.)

    When executing code inside namespace eval, always use variable to declare variables before using them. This avoids problems with global variable shadowing that are really horrible but necessary to keep due to some existing code depending on them. (Technically, you don’t need to do this in namespace eval :: as global variables can’t shadow themselves, but it doesn’t hurt.)


    Dealing with specifics:

    in the GET_NAME,if I set the variable name as “RON”, does it will set the variable name declaired in namespace?

    No, not with the code you wrote.

    can I have the same variable name in GET_NAME and namespace?

    You can use the same name of variable in the two places. This can be confusing, but it limits surprises overall.

    And if I add this line variable name in GET_NAME, does this mean, it will set the variable declaired in name space?

    Yes. Exactly that. (It couples the two together precisely.)

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

Sidebar

Related Questions

I have a question about best practices for Ruby variable-scope using class_eval . In
I have a question about variable scope and memory management in C. I am
I have a question about variable scope in a C++ class. The problem I'm
I have couple of questions about AS3 variables handling by AVM/compiler/scope .1. This code
I have a question about the $_FILES global variable in php. When I do
This question is a follow-up on a question about Python variable scope . Additional
In this question I found an interesting detail about scope of a final variable
I'm currently developing some things in Python and I have a question about variables
I have a question about ruby on rails and the process of assigning variables
I have a very n00b question about Rails. What are the variables and methods

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.