# Questions tagged [scoping]

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

482 questions
Filter by
Sorted by
Tagged with
44 views

### Variables I defined in Module are not evaluated as I expected

I want to make and use object like stuff of Object-Oriented Programming language(like JavaScript) in Mathematica and am trying it by referring to the answer of this question using ...
114 views

### How to define a version of Table[] which localizes iteration variable by Module[]?

For reusable code it's good practice to use Module[] to localize iteration variables used by Table[], as explained by this post. ...
42 views

### It would be possible to visualize the value of the integral together with the graph (in the same Manipulate command)

f[x_, y_] := x - 3 y Manipulate[RegionPlot[ 0 <= x <= a && 0 <= y <= b (1 - (x/a)), {x, 0, a + 2}, {y, 0, b + 2}], {a, 1, 20, 1}, {b, 1, 20, 1}] ...
22 views

### Create a table of plots in manipulate with redundant variables

I'm trying to create a table of diagrams of which each shows a different variable on the x axis and fetches the remaining parameters from the enclosing scope, a Manipulate object. So I have this code ...
51 views

### Using With[] vs. Using a Pure Function for Constants

There are many cases where I am conflicted over using With[] versus using pure functions when dealing with constants, knowing the output is the same either way. For ...
30 views

### Numerical errors in compiled function involving real and complex numbers as output

I am trying to use the Compile command in Mathematica to reduce the computation time because of its fast execution within Mathematica and ability to use the ...
67 views

### Why some variables get substituted and others don't

I was running into some trouble with my math and I whittled it down to this nugget: ...
39 views

### How to Show Velocity and Time Measurements in Manipulate (Wolfram Demonstrations)

I am working with a Wolfram Demonstration that uses the Manipulate function (which I am not yet familiar with). The code is ...
29 views

### How can I create a PasteButton that changes its “contents” dynamically?

I'm trying to make a units palette to help with my various engineering courses. I thought about creating a "meta-palette" of sorts, maybe one that changes on the fly, or one where I can ...
28 views

### Display more outputs inside Module and Which

As it can be seen in the following piece of code, i would like to display more outputs which are inside a Module, part of a function definition. In turn this is ...
68 views

### Passing symbols, variables and defining functions within functions

Moderators state: “You will be brief and straight to the point”, and so do I. All codes test whether a polynomial is even or odd, using different approaches. This works: ...
1k views

### Can you unpack a list of values into variables in a With expression?

For instance, if I am trying to draw a graph with 5 vertices labeled a through e, and I want to draw edges connecting a and b, a and c, a and d, a and e, b and c, b and d, and c and e, I would run the ...
45 views

### Unique symbol for parallel kernels

For each kernel, a unique symbol can be generated with Unique[]. However, since it's basically defined by the growing ...
54 views

### Autoloading MaTeX and Rubi via DeclarePackage[] in the user init.m does not work

Former question: Autoloading and adding code to a package in the user init.m I am using MaTeX, and I found the updateMaTeX[] function] at the GitHub repo. I tried ...
41 views

### Function does something bizarre with formal parameters

I think this may overlap with existing questions, including one I asked years ago, but I'm not sure how, because the behavior I'm seeing is confusing enough I can't even really describe it except to ...
90 views

### DynamicModule Error when assigning Nothing to variable

Assigning Nothing to a variable inside Module works as expected: ...
37 views

### Strange Replace problem within RuleDelayed within function [duplicate]

I've run into a strange anomaly with Replace when it is performed inside the first argument of RuleDelayed within a function ...
80 views

### Combination of Block and With - Unexpected results

I'm trying to use Block to prevent a function from executing. In this example, the function I'm trying to block will simply be ...
908 views

### SetOptions locally?

Is there a way to SetOptions locally? For example, I have a Module and inside it I am doing a lot of ...
83 views

### Context Manipulation within Scoping Constructs

In the following the full context form of Test is not required as "Aaa" is added to ...
35 views

### Strange behaviour of SubValues of a definition in a context

First we define a context: Begin["Ctx"]; ClearAll[f]; f[m_][n_] := n // (Range /* Append[m]); End[]; We can check that ...
70 views

### Compile - Optimization of function calls - does it matter?

I was surprised to see that, in the results of CompilePrint for a function made with Compile, calls to ...
184 views

### Wolfram modules returning functions

I am trying to get a With / Module pair to return a set of functions. ...
107 views

### Scoping problem? [duplicate]

Why (f[1, 0] /. {x : 0 | 1 :> 1 - x}) -> 0 returns (expectedly) f[0, 1] -> 0, while ...
61 views

### Functions within modules within Compile

I've noticed that if I try to define a Function within a Module within Compile, I get errors ...
75 views

### More control over plotstyle in TwoAxisListPlot

I don't understand how to modify the ColorData in the mapIndexed for the code from another post found here and is copied below for reference. What I want to do is control the color of each trace as ...
34 views

### How to Inherit Arrowheds size?

I'm trying to write a Module that produces some arrows with custom Arrowhead shapes. However, I want the code external to the <...
29 views

### Replace the output of a module containing local variables by their actual value

I want to construct a function as the output of a Module, but I obtain the local variables as part of the output. This is a problem when I try to construct many of these functions in a parallel table, ...
62 views

### Implement Table and Sum replacements scoped with Module

Functions like Table and Sum are scoped with Block, rather than ...
108 views

### Memory isolation autochecker

I'm working on a project in which I'm putting everything in modules to make sure I can run multiple instances without them interfering with each other, however I'd like to have it automatically let me ...
69 views

### Manipulate not showing the four curves I want to manipulate

I've tried to display four functions in a single plot without success and I don't know how I should change my code in order to see the function. Indeed when I run the command I just see the axises but ...
45 views

### Why is my code for counting function calls not working?

I am tryin to calculate how many calls to a function my code is using. ...
63 views

### How can I prevent my special symbols to conflict with other global symbols?

I am building a tool to manipulate Feynman diagrams and depict them using the Graph functionality. A diagram might have the following syntax ...
65 views

### Getting error when I substitute PDE for ODE

The following code works perfectly: ...
47 views

### Getting error messages form Set while trying to implement the bisection method with a For-loop [duplicate]

My objective is to build a function using modules that runs the bisection method. I have a working bisection method but when I try to implement it as a module I keep getting this error and I can't ...
151 views

### How to use a list of indexes as a variables inside a Module?

This is a trivial function, just to show that Module does not recognize the list generated by Table. ...
494 views

### Using block or module to free cache

I'm writing some code at the moment that schematically looks like: (set initial conditions for some differential equation for given parameters (M,R,...)) ...
40 views

### Locally remove definition of function

Consider the following code g[x_]:=x^2 f[x_]:=2*g[x] f[x] (* returns 2 x^2*) test[x_]:=Module[{g},f[x]] test[x] (* returns 2 x^2 as well*) What I would like to ...
68 views

### Problem reusing Dynamic variables illustrated by synchronized Panes code

Suppose I have several plots that represent different views of a common set of time sequence data but each Plot contains too much data (all of which I want ...
43 views

### How to “Hold” variables assigned value inside DSolve?

Consider the following ODE: a = 0.8; b = 8; v = DSolveValue[{ u[x] == a*(b* u'[x] + u''[x]), u[4.925] == 4, u'[4.925] == 0.625 }, u[x], x] which gives ...
48 views

### Recursiveness in backtracking algorithm

In order to familiarise with using basic algorithms in Mathematica, I am coding a sudoku solver using a backtracking algorithm. I am treating the sudoku itself as an association (I want to learn to ...
45 views

### How to use two separate colours for two lines in a single 'Plot' within the 'With' command?

'''With[{k = {1, 10}}, Plot[k*x^2, {x, 0, 1}]]''' I want to use two separate colours for two k values. How to do that? Thanks in advance.
42 views

### Returning (not displaying) graphics from a Module

I want to create a Module which puts several parametric surfaces together as one object. For example, say I want to create a module which returns a cylinder that has a top, bottom, and cylindrical &...
87 views

### Is it a good idea to unprotect standard commands?

I often see in code by other people some standard functions like Sum, NonCommutativeMultiply etc get unprotected, supplemented ...
83 views

### Strange Behavior of Compile[] inside With[]

Consider, in the examples below, the difference between defining $n$ as a global variable or as an argument to function comp[], which includes a compiled function ...
54 views

### Keep irrelevant variables outside function arguments

I want to define several functions of variables x,y say ...
62 views

### NDSolve and NIntegrate with parameters

I have a problem with a numeric computation. I should solve a numeric ODE and the rhs is a numeric parametric function that I find with several NIntegrate. I'd like ...
30 views

### Return exact solution in one variable from Series as an option

I have a module which expands many functions, depending on expansion order input parameters. Here's an MRE: ...