Linked Questions
10 questions linked to/from I define a variable as local to a module BUT then the module uses its global value! Why?
50
votes
5
answers
3k
views
Enforcing correct variable bindings and avoiding renamings for conflicting variables in nested scoping constructs
Using global variables the following turns an "expression" into a Function:
expr = 2 x;
Function[x, Evaluate[expr]]
Of course ...
31
votes
1
answer
940
views
Is the renaming mechanism of `With` flawed?
I'm confused about the renaming mechanism of With:
...
29
votes
1
answer
426
views
Strange behavior with Cases and Position with SetDelayed
I feel like I must be missing something simple and obvious here, but this has me scratching my head.
This works as expected:
...
8
votes
1
answer
446
views
Rule rewriting behavior
This is kind of meta-programming attempt. Below are two snippets:
Snippet 1:
...
6
votes
4
answers
292
views
How to scope `Pattern` labels in rules/set?
Module[{x},
f@x_ = x;
p@x_ := x;
{x, x_, x_ -> x, x_ :> x}
]
?f
?p
gives
...
11
votes
1
answer
475
views
Variable scoping in Module
I don't understand why $a$ and $b$ are not local in the following code:
...
5
votes
2
answers
239
views
Conflict with variables in pure functions
Consider the following snippet of code.
Clear[f, g]
f[x_] := Function[{i}, x];
g[h_] := Module[{Z},
Z[i_] := Print[h];
Print[h];
Z[1];
];
When ...
7
votes
0
answers
194
views
Why patterns names aren't scoped by default?
In a recent question [1] OP asked how to make Module scope working inside Set, so how to get:
...
3
votes
1
answer
105
views
Variable scoping confusion
Forgive me if this question has been asked prior (I wouldn't even know where to start looking for an answer to this problem to be honest). I know the following code in Mathematica works:
...
0
votes
2
answers
170
views
How to plot functions from user input?
Manipulate[g[x_] = f;
Plot[{g[x], g[2]}, {x, -9, 9}],
{{f, "Enter a function...", "f(x) ="}}]
Hi, I'm relatively new to Mathematica and this ...