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

learn more… | top users | synonyms (1)

1
vote
1answer
50 views

Module inside module in `Compile`

How can I make compilation to go through with a module inside module? I tried this, failed, a few other ways failed too. ...
0
votes
0answers
58 views

Is tensor argument passing to module expensive?

I wrote a simple module which is supposed to do recursive computation, however it turns out to be expensive even for 300 points. I am not sure why is it slow, all the computations seem to be ...
-2
votes
0answers
42 views
19
votes
1answer
190 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: ...
5
votes
3answers
169 views

Turning an expression into a function inside another function

Say I have an expression g=Sin[q]; It is easy to turn it into a function, and to perform manipulations on this function (this and variants of this were discussed ...
7
votes
2answers
102 views

Cannot Block Plus

It is customary to use the following idiom to partially evaluate something inside a held expression: ...
3
votes
2answers
98 views

Sections with unidirectionally shared variables

I have 2 sections is my notebook: ...
0
votes
0answers
30 views

Set::setraw error help includes Module

Simple program for euler's method. I changed it to this and it works, just not to the extent I want it to. Right now I have to define x and y locally, whereas I'd rather set them as a global initial ...
18
votes
1answer
216 views

A With expression local variable specification without head List

I just noticed a new form of With in its documentation: With[$x=x_0$, $expr$] specifies that all occurrences of the symbol $x$ in $expr$ should be replaced ...
0
votes
0answers
18 views

How to get rid of numerical scope error? [duplicate]

I am trying to perform a numerical maximization routine on a setdelayed function which involves a numerical integral and I'm getting an error message. The evaluation continues and gives the right ...
2
votes
0answers
63 views

Scoping all symbols

After working Mathematica for a couple weeks to write a larger program, beyond doing integrals, I am starting to gain an appreciation for the Wolfram Language. There are a couple issues that drive me ...
1
vote
0answers
15 views

Manipulate inside Module - “Order of evaluation conflicts” [duplicate]

In this example, Manipulate is contained within a Module: ...
3
votes
2answers
77 views

How to use locally scoped dynamic variables in Manipulate for expression and control parameters

I have a Manipulate that has dynamic variables that I want to use in the displayed expression and use in the parameters for the manipulate controls. I only ...
1
vote
0answers
78 views

Should I Remove the initial symbols of Module?

Often we use Module to construct complicate function. Consider that Module create new vars every time we run the function, should I remove the initial values at the end of Module-function?Or should I ...
3
votes
0answers
37 views

Cross referencing symbols in different packages [duplicate]

I have problems with name space shadowing which I do not know how to resolve. I have two packages which depend on each other. Here is example of two files fooPackage.m: ...
2
votes
1answer
52 views

How to write a function that returns the combined output of several built-in functions

I am trying to make a module that takes a Boolean function, and prints the following: the function's truth table the function's NOR epxression the function's minimal Disjunctive normal form So far ...
-1
votes
1answer
65 views

Module whose input is a function of 2 variables [closed]

I need to make a Module whose input is a function of 2 variables and 2 variables m,n so i can make a Matrix with Array. Basicaly, I need this: ...
0
votes
1answer
32 views

Behavior of custom file chooser code changes when placed inside DynamicModule

My primary objective is to build a file chooser that aides a user in selecting files into one of two categories. Files can be individually selected, or based on the clicking of a specific checkbox, ...
5
votes
1answer
84 views

Dynamics and Block interfere

As mentioned by Albert Retey in a comment, we can unintentionally interfere with our dynamics as follows ...
0
votes
1answer
64 views

Basic (?) dynamic module questions (If clause and refresh problems)

I'm building a dynamic module, but I'm stuck with a few things i don't know how to deal with. In particular I'm stuck with the "If" sentence and the refresh inside the dynamic module. Here's a ...
1
vote
0answers
30 views

Module does not evaluate the same way as without [closed]

I have a module as follows: ...
1
vote
1answer
37 views

Module and Manipulate: Why the Red Highlighting? [duplicate]

If I define a function that returns a Manipulate object, and the Manipulate has a local variable inside of it, the local ...
0
votes
2answers
80 views

Use a Module to return multiple plots

A program I'm running requires me to generate multiple plots over the same domain, so I thought it would be fairly simple to use a module and bury all of the plot commands within that that way I only ...
0
votes
0answers
48 views

What is the right way to combine a Package, Module, ParallelTable and NIntegrate?

I am stuck with a curious problem. I would like to to have a package from which i can call a function test[path], which then performs a time consuming numerical ...
3
votes
2answers
105 views

Memory Problem with Modules and NDSolve

I'm using NDSolve inside a module, and I appear to have a memory leak. The relevant code is: ...
1
vote
1answer
174 views

Combining Mandelbrot and Monte Carlo

I'm trying to combine plotting a Mandelbrot set with Monte Carlo randomization to plot an equation using random points for complex number z, for the function $z^3-2z+2=0$. Below is the code I have ...
1
vote
2answers
102 views

Random walk using Module [closed]

I want to create a random walk using Module. The walk start at {0, 0}. At every step, x ...
4
votes
1answer
103 views

Unwanted interaction between instances of a Manipulate function

The function trajectory below is defined in terms of Manipulate and calls the auxiliary function ...
3
votes
0answers
70 views

Decrease computation time of module [closed]

I need to compute the exponential of a matrix (in this caseR) by the summation method where R is a square matrix with symbolic ...
8
votes
1answer
171 views

Context of localised (dynamic) symbols

When you localise a symbol with Module, the created unique symbol is usually in the current context. There seems to be an exception to this which has further ...
9
votes
2answers
158 views

How does $CellContext` work?

The only official info about $CellContext` I was able to find is: placeholder for the context of a symbol inside Dynamic ...
14
votes
2answers
370 views

Messages leak out from Block

fixed in 10.1 When assigning message to a symbol localized by Block, I would expect that this message is not accessible outside of ...
2
votes
1answer
43 views

Local function becomes global after Plot [duplicate]

In the code below, I define and plot a local function f. Clear[f] Module[{f}, f[x_] := 1; Plot[f[x], {x, 0, 1}]] However, ...
2
votes
1answer
68 views

Writing a procedure that invokes Manipulate[]

I would like to write a procedure with the signature: Foo[vars, params] which produces a Manipulate object. The procedure ...
14
votes
2answers
449 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 ...
4
votes
1answer
128 views

ControlType -> None Vs. Module inside Manipulate (i.e. making everything local)

I'm building a program on another one made available in the Wolfram Demonstration Project. I've noticed that in the original code (working flawlessly) many variables were made local inside the ...
5
votes
1answer
99 views

Module does not remove a function definition

The following is a minor variant of the function uniqueTuples as given by Simon Woods in this answer. ...
15
votes
2answers
313 views

What is the purpose of Internal`LocalizedBlock?

I have come across the (internal) use of of the function: Internal`LocalizedBlock I am trying to determine its purpose. It seem to behave like ...
5
votes
4answers
271 views

Replacing parts of a matrix

I'm a beginner to Mathematica and to writing scripts in general. I'm currently trying to write a code that will take any element in a matrix higher than a certain threshold value n and set it equal to ...
2
votes
1answer
43 views

Substitution breaking the scope

A novice's problem, perhaps: it seems that /. substitution does weird things to the scope. ...
1
vote
2answers
119 views

Expressions containing globally undefined symbols inside a function where they are defined

Consider the following code. f[a_,b_]:=x; Clear[a,b]; x=a+b; f[1,2] It returns a+b. However, from a certain viewpoint, one ...
1
vote
2answers
87 views

Localised variable shows up as Global [duplicate]

Why does this local variable show up as Global? ?q Information::notfound: Symbol q not found. >> ...
-6
votes
2answers
111 views

Module function corrupts string? [closed]

I have the module who should replace some elements of a matrix with checkboxes ...
2
votes
1answer
60 views

How to protect function variables [duplicate]

I am sure this has been asked before, but I can't seem to find the right solution. I want a function to be the solution to a differential equation ...
5
votes
2answers
191 views

A better way of handling Module output?

I am sure this has been asked before in a way or another. I need to Save or DumpSave some symbols that contain the result of ...
1
vote
1answer
51 views

Global variales, Paralell computation and Limiting notebook's contex

If I limit the context of each notebook: and use parallel computation: ParallelTable[ToExpression["b" <> ToString[j]], {j, 1, 10}] then after ...
8
votes
1answer
147 views

How to assemble and disassemble a function into steps

I've watched many programmers (both novice and expert) write functions in Mathematica and have observed a common behavioral pattern. This pattern has many elements that would be automated and thus ...
0
votes
0answers
93 views

Best practices for breaking up functional blocks?

Say I have a main function that does some job, and I'm only interested in the final result of ans, i.e., the local functions are not important and produce no ...
3
votes
1answer
62 views

Should “counters” used in Do, Table, … within Module be declared as local?

I have little to no understanding of how Mathematica handles scoping, so the question may seem a little bit funny. What is the preferred way: ...