# Tag Info

### How to avoid nested With[]?

Introduced in V10.4 or earlier, but after V10.1 This functionality has snuck into With (ref: Daniel's comment). Note the use of the braces. ...
• 216k
Accepted

### What is the purpose of InternalLocalizedBlock?

InternalLocalizedBlock behaves the same as Block, but it can localize non-Symbols (e.g. f[1]...
• 1,196
Accepted

### Is the renaming mechanism of With flawed?

Short answer The local variables of the form varname\$... are used by the system, and it is unwise to use symbols with such names as local variables. ...
• 112k

### Should I always be using Module in functions unless I explicitly want global variables?

The short answer is "yes", we should always use Module to localize any intermediate variables within our functions. We might get away with using global variables ...
• 67k
Accepted

### What causes Module variables to leak?

Preamble I will try to summarize some cases I've seen or encountered, in a few rules, which I believe do hold and explain most or all of the cases I am aware of. The rules Here are the rules (...
• 112k

### SetOptions locally?

Version 12.2 In version 12.2, use the new function WithCleanup[]: ...
Accepted

### Strange behavior with Cases and Position with SetDelayed

What's happening This is not simple by any means. You have encountered another instance of a general situation with lexical scope leaks / emulation / over-protection by symbol renaming. The case at ...
• 112k
Accepted

### Do Table iteration variables need to be localized using Module?

In general, it is good practice to include i among the local variables. Table does not localize its variable (or, as some say, ...
• 67k

### Bug with iterated With: Referring to function arguments invalidates previous definitions

A long comment: Automatic renaming again: ClearAll[F]; F[x_] := Hold[With[{a = x}, {b = x}, a]]; F[0] ...
• 133k
Accepted

### StringReplace, ReplaceAll and Rule interact in a bizarre way

Preamble What happens can be understood when we recall that Rule is a scoping construct. The general issues related to variable renamings in scoping constructs ...
• 112k
Accepted

### Syntax highlighter shows error for Manipulate when it's inside a Block or a Module

Based on Mr.Wizard's answer and comments by Szabolcs and celtschk, I now understand that the code I posted does have undesirable side-effects and it should be avoided. Specifically, the scoping ...
• 9,776
Accepted

### I define a variable as local to a module BUT then the module uses its global value! Why?

What happens and why As Daniel Lichtblau pointed out in comments, this behavior can also be viewed as a flaw in the current behavior / design / implementation of lexical scoping in Mathematica. ...
• 112k
Accepted

### Why does the global variable exist here, where it was declared only in Module?

Why is this happening The explanation was basically given by ciao in comments. You can also find a lot of information on this in this great answer of Mr.Wizard. I will perhaps try to view it from a ...
• 112k

### Bug with Block & Lookup: Scope Variable Leak

Looks like a bug to me as well. Just as Michael I would suspect that the problem is more with Lookup than Block or ...
• 23.1k
Accepted

### Context of localised (dynamic) symbols

I will make no attempt to defend the fact that Mathematica simulates scoping by means of variable renaming. However, the behaviour that we see is consistent with the principles under which ...
• 67k

### SetOptions locally?

I have used several methods, including the ones in the other answers. I have found that the simplest method is InternalInheritedBlock as it allows for temporary ...
• 33.3k
Accepted

### Working with DynamicModule: SetDelayed + OwnValues

J. Fultz' answer indicates that it is not a bug but a feature which needs better documentation. Get a habit of defining your procedures with [], e.g. ...
• 133k
Accepted

### Parallelization inside a module: Proper use of local variables

There are multiple issues here. Let us take them one by one. Why do you get 0 as the output? There is a quirk in how ...
• 225k

### What does empty {} mean in Module?

Usually, when one defines a function that's not too complex (usually a one-liner) it is customary (here we mean Mathematica custom) to define it directly without any scoping constructs (...
• 32.5k
Accepted

### Internal DynamicModule steals scope of external DynamicModule

This answer builds on @AlbertRetey's answer where, in the comments, you wanted some guidance as to how Wolfram creates robust controls. Think very carefully about the division of labor between the FE ...
• 12.4k
Accepted

### Why can't I inject expressions in Compile using (only) With

Compile is considered a scoping construct by the outer With, and its bindings are protected. This will work: ...
• 112k
Accepted

### Rule rewriting behavior

Overview (tl;dr) Ultimately, the difference here is due to Module being lexically scoped, while Block is dynamically scoped. ...
• 8,208
Accepted

### A smarter nested With?

With this helper function: ...
• 112k
Accepted

### A With expression local variable specification without head List

This is a documentation bug. Our source notebooks do contain documentation for experimental and future features, but they are supposed to be stripped in the process of being bundled with the product. ...
• 13.4k
Accepted

### Where does a package have to be loaded?

tl;dr You need to call Needs before GetBoundaryMesh definition so it can be parsed (found in correct context) correctly or you ...
• 133k

### RecurrenceTable iteration variable not localized? Bug or user error?

As Bob Hanlon's answer points out, RecurrenceTable does not hold its arguments, but most especially, it does not hold its iterator arguments. This must surely be ...
• 67k
Accepted

### What is the accessibility of a package's Private context variables?

So how does MyFunction know the value of abc at the delayed function call (when it is called) if the ...
• 225k

### What is the purpose of InternalLocalizedBlock?

Disclaimer: these are all guesses, believe at your own risk. As the first argument, you specify a list of patterns to localize. For example, {x}, ...
• 41.6k