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
9k 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
  • 235k
75 votes
7 answers
6k 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
  • 235k
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
  • 235k
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
  • 235k
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,643
19 votes
3 answers
998 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
  • 625
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
  • 272k
11 votes
2 answers
1k views

Developing domain specific languages and computational knowledge engines using Mathematica

In one of Leonid Shifrin's excellent summaries, he mentioned that MMA capabilities include developing Domain Specific Languages (DSL). I'd like to develop a Health care IT application that can ...
alancalvitti's user avatar
  • 15.1k
9 votes
5 answers
489 views

Truncate TreeForm to show only the top

For some expressions, TreeForm may grow very long. I'm only interested in the top levels of the expression. How can I get the tree form of only the first levels an ...
sjdh's user avatar
  • 7,757
14 votes
2 answers
1k views

How to REALLY Hold arguments and capture FullForm?

I'm trying to write an expression deconstructor or FullForm-capturer; might even call it a parser, maybe, but that might be too glorious a word. I got some great ...
Reb.Cabin's user avatar
  • 8,661
19 votes
1 answer
936 views

List manipulation to build a functional expression

Since Mathematica deals with Head[a, b] as an expression in this way The first Part of Head[a, b] is ...
Life's user avatar
  • 660
12 votes
2 answers
1k views

Workbench Profile[] question

I previously posted this question on Mathgroup but received no response I am using Workbench to profile my code. Suppose I have 2 modules, let's call them A, B (they are too long to replicate here). ...
Eric's user avatar
  • 333
8 votes
1 answer
505 views

Alternative to overloading Set

In the ideas shared in my answer to this post Struct equivalent in Mathematica? at the end I propose a solution that changes the way Set works in a particular case that can be expressed in plain words ...
faysou's user avatar
  • 11k
7 votes
4 answers
2k views

Delayed evaluation of assignment

I have a set of PDE's that depend on parameters. They depend on many parameters, but for simplicity we can here assume that they depend only on one, say a. I want ...
yohbs's user avatar
  • 7,046
18 votes
1 answer
437 views

Macro functions in GeneralUtilities?

Questions have been asked about the Macros package before (e.g., (83815)), but I'm interested if anyone has some examples of using the macro related functions in GeneralUtilities: ...
M.R.'s user avatar
  • 31.5k
3 votes
1 answer
266 views

Why am I not getting a numeric response?

Code ...
user avatar
2 votes
2 answers
205 views

Setting local variables with another function

I'm working on a package with a lot of functions using Module, which all begin by unpacking the arguments into local variables. I'd like to store this unpacking code in a separate function called ...
Chris K's user avatar
  • 20.2k
3 votes
1 answer
149 views

How to implement Outer with loops

I would like to implement a simplified version of Outer (Outer[f, vec1, vec2,..]) through a looping construct. Here are is one ...
TheGuest's user avatar