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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:18:57+00:00 2026-05-26T11:18:57+00:00

If we evaluate these lines one-by-one , x will be created in the context

  • 0

If we evaluate these lines one-by-one, x will be created in the context cc.

Begin["cc`"];
x = 1;
End[]

However, if we evaluate them together,

(Begin["cc`"];
x = 1;
End[])

then x will be created in Global. This is despite the following printing cc`:

(Begin["cc`"];
Print[$Context];
End[])

What is the reason for this behaviour? My guess is that contexts only matter during the parsing phase, not evaluation.

Use case: I wanted to create a palette Button that will define some symbols if they don’t exist yet, in a “private” context to avoid conflict with globals. What is the preferred method to do this, other than putting all the definitions in a package file and loading them from the palette? (I’d like to keep the palette self-contained.)

  • 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-05-26T11:18:57+00:00Added an answer on May 26, 2026 at 11:18 am

    Symbols (and their contexts) are created when parsing, not evaluation. If we use $NewSymbol we can see this in effect:

    $NewSymbol=Print["Name: ",#1," Context: ",#2]&;
    
    Print["first"];
    test1;
    Print["last"]
    
    (Print["first"];
     test2;
     Print["last"])
    

    The first one prints:

    first
    Name: test1 Context: Global`
    last
    

    because each line in the cell is treated as a separate input. The second one uses parentheses to force all three lines to be considered one input and prints

    Name: test2 Context: Global`
    first
    last
    

    from which we can see that test2 was created in the Global` context before any evaluation occurred.

    I think the easiest way to work with this is to use an explicit context on your symbol: cc`x = 1.

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

Sidebar

Related Questions

I'm trying to evaluate the purchase of a statistical tool. This will be used
I have an array with 16 elements. I would like to evaluate these to
I a modeling a system to evaluate expressions. Now the operands in these expressions
Is it generally acceptable that one repository can access another repository? Specifically in this
Despite this being one of the best error messages I've ever seen (second only
I think this is a great Ruby one-liner: someArray.sort_by {rand} It's concise, it's readable,
I gave up on this one. May be someone can see something obvious. I
Is there a way to evaluate the minimum requirements of a software? I mean,
Is there a setting in SQL Server to have null = null evaluate to
How to evaluate whether a career coach is beneficial?

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.