# Questions tagged [scoping]

Questions on Mathematica's scoping constructs (Block, Module, With, etc.)

497 questions
Filter by
Sorted by
Tagged with
112 views

### Transferring a function between two modules in a package

I have a first module which outputs as forth output a function G I want to transfer to another module. The specific function is ...
97 views

### Sum of n sums, Permutations of the indices, how to write them in Mathematica?

I was wondering how to write a function $F (r, q, n, f)$ in Mathematica, defined in this way: F(r,q,n,f):=\sum_{i_0=1}^q f(i_0) \Biggl(\sum_{i_1=i_0+1}^{q+1} f(i_1)\biggl(\sum_{i_2=i_1+1}^{q+2} ...
328 views

### Best practice with Return in Module or Block

I am a bit confused on the use of Return in either Block or Module when defining a custom ...
193 views

### Using With[...] with a list specification as a variable [duplicate]

If you have some defined function, say f[a_, b_ c_, x], one can initialize this by using With[...] as ...
76 views

### Scoping construct for dependent constants

I sometimes want to write a function which needs to apply a bunch of transformations that are not functions of a single parameter only: ...
122 views

### function evaluation - I don't get it

this function returns Pi/4 for a[1,4] In[...]:= a[r_, n_] := Module[{an = Pi/n, h = r Cos[an], w = 2 r Sin[an]}, an]; a[1, 4] Out[...]= Pi/4 so the kernel ...
123 views

45 views

### K vs k in a module

Module[{K = 1, fn}, fn[p_] := Print[K]; ParallelTable[fn[p0], {p0, 2}]]; Prints K\$316 (or whatever the module counter is on)...
57 views

### What use is empty binding list in Block[{},...]? [duplicate]

Spelunking the Export function, I stumbled upon the following definition: ...
83 views

...
66 views

### Problem passing argument in hash table from global context to a module

I was experimenting with passing arguments via a hash table to a module. Found a very strange result. When I pass a function to be plotted inside the module, it comes out empty. Yet all argument ...
125 views

### Module and With do not work in some cases

I apologize if the title is too vague/general but I couldn't find a better one. I am trying to use either Module or With but it does not work if the object containing the local variables is defined ...
158 views

### A bug in Derivative?

Update This is a bug in v11.3 or earlier and is fixed in v12. Original Post Check this out: ...
110 views

### Want help with debugging a For-loop

I'm trying to run a simulation, which at the end gives a value 'qber'. Now I want to run this simulation multiple times with different values of 'p' each time. And these value of 'p' are actually the ...
429 views

### Clear variables inside Module

I have a function that uses Module. The function takes as input a .csv that can have as many columns as it wishes to, and it ...
214 views

### Create rule whose LHS is already defined

My question will be clearest if defined using an example. Consider the following code: Func[k_]:=Block[{a}, a[t_]:=t^k; {a[t]->a[t]} ]; However, calling ...
45 views

### Dependent variables in With operator [duplicate]

I want write something like this With[{x=1, y=x+1}, y] and get 2 as an answer. What is the correct way to do this?