Linked Questions

602 votes
19 answers
156k 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 ...
139 votes
8 answers
8k views

Can one identify the design patterns of Mathematica?

... or are they unnecessary in such a high-level language? I've been thinking about programming style, coding standards and the like quite a bit lately, the result of my current work on a mixed .Net/...
Verbeia's user avatar
  • 34.2k
90 votes
6 answers
3k views

How to avoid nested With[]?

With[ {v1 = #}, With[ {v2 = f[v1]}, g[v1, v2] ] ] How to avoid nested With[] like the above? I'd like to use <...
user13253's user avatar
  • 8,666
69 votes
10 answers
3k views

Injecting a sequence of expressions into a held expression

Consider the following toy example: Hold[{1, 2, x}] /. x -> Sequence[3, 4] It will give Hold[{1, 2, Sequence[3, 4]}] ...
Szabolcs's user avatar
  • 234k
75 votes
7 answers
5k views

Functions vs. patterns

Every time I define a new function, I wonder which construct I should use: true functions obtained by using Function, or rule-based syntax. For example, these are ...
David's user avatar
  • 14.9k
36 votes
6 answers
7k views

Finding all elements within a certain range in a sorted list

Suppose we have a sorted list of values. Let's use list = Sort@RandomReal[1, 1000000]; for this example. I need a fast function ...
Szabolcs's user avatar
  • 234k
121 votes
1 answer
8k 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 ...
Szabolcs's user avatar
  • 234k
32 votes
5 answers
2k views

Resource management in Mathematica

I am using a library that has functions like createSomeObject[] and deleteSomeObject[obj]. It is an interface to a C language ...
Szabolcs's user avatar
  • 234k
20 votes
4 answers
2k views

Implementing a function which generalizes the merging step in merge sort

One of the key steps in merge sort is the merging step. Given two sorted lists sorted1={2,6,10,13,16,17,19}; sorted2={1,3,4,5,7,8,9,11,12,14,15,18,20}; of ...
Michael Wijaya's user avatar
24 votes
3 answers
2k views

Select performance

I am fairly new to mathematica and working my way thru Paul Wellins book on Mathematica programming so experimenting with various language constructs. I was experimenting with ...
David McHarg's user avatar
  • 1,633
19 votes
3 answers
997 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, ...
Manuel Odendahl's user avatar
35 votes
1 answer
2k views

Customizing syntax highlighting for private cell styles

Is there any way to set up a cell style with a particular syntax highlighting? For example, I'd like to have a CProgram cell to write in blue the C special words. I have done it by setting ...
Rojo's user avatar
  • 42.6k
14 votes
2 answers
2k views

Mathematica Application in Real Life

As an 'user'-level in Mathematica, I mainly use built-in Mathematica function and benefit Mathematica as a mathematical tool-box for my specific scientific problem. My level is not yet programmer-...
16 votes
3 answers
1k views

How to check the validity of an option value

I have a user-defined function, func, which takes the following form: func[arg1, arg2, options] Here is the actual code ...
xyz's user avatar
  • 605
28 votes
1 answer
1k views

Convenient string manipulation

With Mathematica I always feel that strings are "second class citizens." Compared to a language such as PERL one must juggle a lot of code to accomplish the same task. The available functionality is ...
Mr.Wizard's user avatar
  • 271k

15 30 50 per page