Sign up ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I apologize first, because this has been asked, like in

Treat all variables as local in a module [duplicate]

Variable scope similar to other languages

But I don't get how to use them.

Some codes in these answers don't work when I just copy-paste blindly (because I really don't understand them.)

Are the above methods the standard way to "Treat variables as local by default (No need to specify them, like in Module)" in Mathematica? If so, please give me a working example, please.

I think there should be a standard way to do this, but I can't find it in the documentation.

share|improve this question
If you're a beginner it might be a good idea not to try to use these at all. Work with the language, not against it. – Szabolcs Feb 14 '14 at 22:27
If you plan on using Mathematica long term in a non-toy capacity, then I suggest learning to program effectively using the language's native constructs and semantics first. Once you nail that down, you can try expanding and using non-standard evaluation and scoping techniques. Otherwise, it will be difficult to understand when and why things go wrong sometimes... Trying to learn a new language by mimicking another language is generally a bad idea. – R. M. Feb 14 '14 at 22:27
I got your point. But I just feel that a lot of global variables in my code, or a lot of local variables specified at the beginning of Module are not good...I don't know how to balance them, or should I really care about this... – user565739 Feb 14 '14 at 22:34
When you work interactively, having global variables is typically not a problem. When you write a package for other users, you need to make sure that everything is properly localized, which is a bit extra work. – Szabolcs Feb 14 '14 at 22:43

Your Answer


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

Browse other questions tagged or ask your own question.