All Questions
Tagged with scoping programming
12 questions
6
votes
4
answers
651
views
Expressions containing globally undefined symbols inside a function where they are defined
Consider the following code.
f[a_,b_]:=x
x=a+b;
f[1,2]
(* a + b *)
From a certain viewpoint, one might expect it to return 3 ...
10
votes
4
answers
1k
views
How to set Block local variables by code?
I need to create a user-defined Block function where the Block variables' values are defined by code. For example, imagine I ...
57
votes
2
answers
2k
views
How safe is the use of Block and Internal`InheritedBlock
For many questions on this site answers are given which suggest to use Block and, especially for more advanced topics, ...
32
votes
1
answer
964
views
Is the renaming mechanism of `With` flawed?
I'm confused about the renaming mechanism of With:
...
3
votes
1
answer
430
views
Call Functions From File Without Modifying Context (Sandbox)
Let's say I have file named test.m containing
test[arg1_] := ( Print[arg1];)
What is the best technique for calling test like ...
4
votes
1
answer
528
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 ...
9
votes
6
answers
956
views
How can you give a Module a context and have its local variables and Modules belong to that context?
What would be the best way to give a module its own context and have its local variables and Modules belong to that context?
17
votes
1
answer
541
views
Is the sharing of variables in Module/Block within Compile documented behavior?
Today I noticed something, I think for the first time.
When used inside Compile variable values within Module (and ...
17
votes
1
answer
564
views
Modules that initialize themselves on first call
I use a lot of functions that extract a specific data item from a file with many data items. I want these functions to load data (slow) and return the item (fast) on first call, but just return the ...
10
votes
1
answer
177
views
Is it possible to use the global definition of a symbol as part of its new local definition set in a Block?
Consider the following expression:
Block[{Print = CopyToClipboard}, doSomething[]]
Now all calls to Print from ...
5
votes
3
answers
238
views
Prevent iterator name from being confused with symbol passed into function body
I have a massive amount of code with lots of Table and Sum inside a Module. Each with their ...
5
votes
1
answer
637
views
How to avoid conflicts between local variable names and symbolic arguments in Block constructs?
I am using Block inside the definition of some recursive functions.
If the Block definitions use short variable names, like ...