Linked Questions

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 ...
einbandi's user avatar
  • 4,024
32 votes
1 answer
959 views

Is the renaming mechanism of `With` flawed?

I'm confused about the renaming mechanism of With: ...
luyuwuli's user avatar
  • 2,814
29 votes
1 answer
438 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: ...
rhennigan's user avatar
  • 1,783
8 votes
1 answer
456 views

Rule rewriting behavior

This is kind of meta-programming attempt. Below are two snippets: Snippet 1: ...
Pavel Perikov's user avatar
6 votes
4 answers
307 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 ...
masterxilo's user avatar
  • 5,739
11 votes
1 answer
485 views

Variable scoping in Module

I don't understand why $a$ and $b$ are not local in the following code: ...
rogerl's user avatar
  • 4,239
5 votes
2 answers
244 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 ...
anon's user avatar
  • 53
7 votes
0 answers
199 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: ...
Kuba's user avatar
  • 137k
0 votes
2 answers
203 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 ...
dcjs34's user avatar
  • 1
3 votes
1 answer
116 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: ...
Tired_College_Student's user avatar