Linked Questions

2
votes
2answers
321 views

Local variables whose definitions depend on each other [duplicate]

Consider the following (pseudo-)function definition: f[l_] := Let[{ a = Length[l], b = First[l], c = b/a, }, c*10] So for ...
3
votes
1answer
357 views

Is there any way to implement a "sequential" With[] in Mathematica? [duplicate]

I want the equivalent of Scheme's let*, or basically, a sequential With that works like this: ...
2
votes
1answer
277 views

Reuse local variable in declaration within With [duplicate]

Considering the richness of Mathematica.SE, I am quite surprised I could not find my answer... I am very sorry if it is a duplicate. Consider the following example: ...
1
vote
0answers
80 views

What's the best practice for nested local constants? [duplicate]

Possible Duplicate: How to avoid nested With[]? I have many situations where I have a constant that is local to a function, with other constants that are computed from it. I see that I can ...
1
vote
0answers
48 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?
573
votes
19answers
146k views

Where can I find examples of good Mathematica programming practice?

I consider myself a pretty good Mathematica programmer, but I'm always looking out for ways to either improve my way of doing things in Mathematica, or to see if there's something nifty that I haven't ...
78
votes
3answers
9k views

Metaprogramming in Mathematica

Being functional, and having no "quotation", i.e. essentially treating data and programs semantically same, Mathematica seems naturally capable of doing metaprogramming. But could anyone construct a ...
46
votes
5answers
4k views

How to create symbols from strings and set values for them?

I am trying to convert a list of string names into symbols, which will then be used to store data. I have 24 files (where the name of each file is a member of the list mentioned above) that I need to ...
119
votes
1answer
7k views

File-backed lists/variables for handling large data

Background Currently I am working with some large data (most of it generated by Mathematica itself). I usually find it a hassle to do this. For example, I just exported a large amount of data to ...
24
votes
4answers
2k views

How to match a pattern with a pattern?

UPDATED This question is about: "What is the pattern to match a pattern-definition, exactly as it is written?" My original question is now split according to Mr.Wizards insightful answer below. This ...
19
votes
3answers
923 views

Generating assignments and transforming code inside held forms when generating code

I have been playing with slightly above trivial code manipulations in Mathematica. I thought Mathematica would be great for this kind of work because of rule replacement and expression manipulation, ...
21
votes
2answers
667 views

Should I always be using Module in functions unless I explicitly want global variables?

I define functions a ton. In the past, I've mostly just defined my functions like: myFunc[var1_]:=( var2=var1^2; Return@var2; ) And I haven't run into too ...
20
votes
2answers
537 views

Clean and handy Options management/filtering

the case I want to be able to create a function with some default options but also without need to add full explicit list of options available for it. And then inside I want to be able to filter ...
22
votes
1answer
437 views

Bug with iterated With: Referring to function arguments invalidates previous definitions

Thank you for your report. I have forwarded your report to the appropriate team for review. - WRI ...
18
votes
1answer
581 views

Removing calls to MainEvalute when using inlined compiled closures

This question is tightly related to the answer Shaving the last 50 ms off NMinimize. There @OleksandR shows how inlined closures can be used to eliminate calls to ...
25
votes
1answer
979 views

A debug utility to print or extract intermediate data from a program

Is there a way to print variables using their names, or to extract the corresponding information for later analysis ?
13
votes
2answers
2k views

Why can't I change the value of MaxRecursion in NIntegrate when integrating BesselJ?

Bug introduced in 8.0.4 or earlier and persisting through 11.0.1 or later I am trying to evaluate this integral numerically $$ \int_0^{\infty } J_0(q R) \tanh(q) \, \mathrm{d}q $$ for large values ...
6
votes
1answer
721 views

Functional programming Style & Performance

Hello i have been spending time to convert my R tools into Mathematica Packages mainly because i like the functional programming style in Mathematica. In doing so it seems that i run into one ...
6
votes
4answers
242 views

Put local variables for Block in a variable

Is is possible to assign {x = 2, y = 3, z = 4} to a variable var so that one can write ...
9
votes
1answer
470 views

A smarter nested With?

I often find myself writing code that looks a bit like this: ...
26
votes
1answer
327 views

SyntaxInformation cannot reproduce syntax coloring of Block

Is there any way to have the same syntax coloring with SyntaxInformation that Block has? ...
4
votes
2answers
441 views

Defining a sequence slot programmatically

This question is related to: Composition of functions using slots `Slot` (#) interfering with evaluation Consider a toy example: ...
4
votes
2answers
406 views

Comparing LetL and Module efficiency

I was recently introduced to the LetL macro thanks to Leonid's answer to one of my prior questions. I was, needless to say, impressed by the simplicity of its ...
8
votes
1answer
233 views

Replace nested external definitions in Compile

f = #^2 &; Compile[{{x, _Real, 1}}, f /@ x, CompilationOptions -> {"InlineExternalDefinitions" -> True}] // CompilePrint works fine. ...
6
votes
1answer
164 views

Where can I put my conditions?

I just learned in this answer that you can put conditions inside a With and thus use computed values in them, like this: ...
3
votes
1answer
501 views

Permuting indices to form fully symmetric tensor with repeated indices

I have written a function (version 8) that takes as an input a list of indices such as {i,j,k} and outputs a fully symmetric tensor function containing $p_i$ and $...
1
vote
2answers
135 views

Getting past "infinite expression 1/0 encountered"

The following function ...
3
votes
2answers
140 views

make a slider for a list of matrices

I have a list of matrices, called $matList$, which are sequentially multiplied by another matrix $G$. I created a slider for $matList$, but the slider does not work. Here is the ...
2
votes
1answer
101 views

Block assignments not quite sequential?

With scalars, Block acts like Scheme's let*, that is, the assignments (appear to) happen sequentially: ...
8
votes
1answer
110 views

Local variables in sums and tables - best practices?

Stumbled on Local variables when defining function in Mathematica in math.SE and decided to ask it here. Apologies if it is a duplicate - the only really relevant question with a detailed answer I ...

15 30 50 per page