Linked Questions
14 questions linked to/from Is the renaming mechanism of `With` flawed?
1
vote
0
answers
102
views
Why does With return a temporary symbol? [duplicate]
Why does
With[{x0 = 1, y0 = 2},
f[x_] = a + b x /. First[
Solve[{y0 == a + b x0, b == 0.1}, {a, b}]]]
evaluate to
...
257
votes
9
answers
18k
views
What are the use cases for different scoping constructs?
Mathematica includes three functions that I know of which can be used to effectively (if not actually) define a variable and give it a value within a local scope: ...
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 ...
22
votes
2
answers
1k
views
I define a variable as local to a module BUT then the module uses its global value! Why?
I have a question about modules and local variables.
Here's my example:
h = 5;
Module[{a, h}, a[h_]= h^2; a[4]]
(*Out[2] = 25*)
I expected the module to ...
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:
...
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
3
answers
199
views
Why does `Block` reset `Attributes`?
Not even "formal symbols" such as \[FormalX] are guaranteed to always be symbolic. Their Protected argument is forgotten when ...
7
votes
2
answers
191
views
Is Function broken is this example?
This program
f[x_] := g[Function[a, x]];
g[fn_] := Module[{h}, h[a_] := fn[a]; h[0]];
f[999]
returns
Function[0, 999][0]
but ...
3
votes
1
answer
86
views
Antiderivative of a piecewise function evaluates wrong inside a subroutine
It's very helpfull to use antiderivative of a given function in the form Derivative[-1][fun][t]!
Here my example with a simple piecewise function:
...
4
votes
0
answers
143
views
Why does `... := With[{var = ...}, ...]` create `var$`?
EDIT
This issue is specifically different from the "duplicate" question. The creation of variables in the active context during parsing is of no surprise and is the expected behavior.
What I'm ...
0
votes
2
answers
126
views
Spurious renaming in nested Function construct
From the documentation of Function, I take this example (slightly simplified). Renaming the dummy or bound variable (y->y$ in the inner ...
2
votes
1
answer
97
views
How to force evaluation of RuleDelayed?
(I'm not sure if the title of this question is appropriate, sorry!)
After defining selfApply function that resolves the mutual references contained in Association, I wrote the following code:
...
4
votes
0
answers
76
views
Temporary symbol leaks into public context?
This phenomenon has confused me a long time. Consider the following package example,
...