0
votes
1answer
45 views

Output a symbol from Module or Block

I have troubles to output an entire symbol, a function in this case, from a module or a block. For instance myf = Block[{f}, f[3] = 33; f[4] = 4; f] Then I want ...
1
vote
2answers
222 views

Error with “Newton's method” in Wellin's Mathematica book

In Wellin's Programming with Mathematica book, here's one of his implementations of the Newton method, where the iteration runs until the error tolerance is reached. ...
0
votes
1answer
73 views

Change input variable in a function [duplicate]

I'd like to write a function, that would take a matrix as an input parameter and would change it by multiplying one of its rows by a factor. I try to do it in the following way: ...
0
votes
1answer
89 views

Multiple Simulations of a Markov Chain

I am trying to create a simple series of Bernoulli bits whose probabilities follow a two-state Markov chain. ...
0
votes
3answers
142 views

Clean-up Code / Reduce variables

I'm writing a playing card simulator of sorts, and everything works fine, but some Modules use a disgusting amount of variables. For Example: ...
0
votes
2answers
113 views

Defining Piecewise Functions in Modules

In short, my question is the same as my previous one except that everything is now wrapped up in a module. The relevant code I'm working with is: ...
3
votes
2answers
193 views

How to declare a function that uses local variables of a module outside this module?

I have the following code Module[{f,x=0}, f[t_] := x + t; ..........; ...f[1]...; ..........; ] My aim is to put the declaration of the function ...
6
votes
1answer
132 views

Creating a Block from a list of rules

How can I create a function which works like Block but takes a list of rules as its first argument, rather than a list of assignments? The function needs to be ...
8
votes
1answer
139 views

Is it possible to write a function immune to symbol redefinitions in any Block surrounding its invocation?

Normally, semantics of symbols used in a function definition can be changed by their redefinitions in Blocks surrounding the function invocation: ...
8
votes
1answer
121 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 ...
7
votes
1answer
173 views

FullDefinition and Module local variable

I have a question about FullDefinition and how it interacts with the local variables of Module. I've created a few functions ...
8
votes
2answers
148 views

Possible to scope an anonymous function within Module?

This is my first question. I'm fairly new to Mathematica and completely new to SE, so I apologize if this question is trivial. I'm working on a problem that requires a function to be redefined ...
23
votes
4answers
467 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 ...
5
votes
1answer
1k views

Module with “local functions”

I am trying to use a Module having "local functions", i.e., those which I need to define only inside this module. So I tried this: ...
3
votes
1answer
142 views

Downvalues vs. Scoping for Functions

Regarding my recent question on using a default value for a function argument when a pattern was not met yielded some interesting answers, but the general consensus was "Yes this can be done, but ...
12
votes
1answer
280 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 ...