Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

In many programming languages one can define a namespace

with namespace abc

How can the similar be done in Mathematica? The Module and Block commands, can somewhat mimick this, but it is only in the command, it doesn't act as a definition.

How can this be done in Mathematica?

share|improve this question
2  
Have a look at Context. –  b.gatessucks Sep 24 '13 at 7:38
    
Ah, so with context I can do a`mass=2, b`mass=3. Is there any way to define a block, where everything inside inherits that context? –  Oskar Sep 24 '13 at 7:53
3  
@Oskar It sounds like you want to create packages. Please see: (29324). Be aware that you cannot use Begin and End in a Module without great care; see: (8295) –  Mr.Wizard Sep 24 '13 at 7:59
    
Here are two links to documentation pages relevant to your question. Namespace Management and Package Development. –  m_goldberg Sep 24 '13 at 9:48
    
Perhaps this will help clarify things for you. In Mathematica, namespaces are the called contexts and packages provide the means for defining persistent namespaces. –  m_goldberg Sep 24 '13 at 9:58

1 Answer 1

In Mathematica, $ContextPath contains a list of the contexts where the definition of a symbol is sought (when that symbol has no namespace qualifications). You can use

$ContextPath = Prepend[$ContextPath, "abc`"]

to achieve what you asked.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.