Leonid Shifrin
• Member for 10 years
• Last seen this week
• St. Petersburg, Russia

I think that Mathematica is a great prototyping environment, and has a bright future as a system for both prototyping and implementation of complete components of other systems, from back-ends to ...

Linked lists: general discussion I would like to describe here a pattern which is IMO quite important yet seems to be generally under-appreciated and under-used in our community (and probably in ...

I will try to list some cases I can recall. The unpacking will happen when: The result, or any intermediate step, is a ragged (irregular) array. For example Range /@ Range[4] To avoid this, you ...

Preamble and motivation While I am much late to the party here, I hope this answer will not be totally useless. This is a first in a series of posts where I will advocate a wider use of Java in our ...

Compose and Composition There is, but it is deprecated (in favor of Composition): Compose: MapThread[Compose, {{a, b, c}, {1, 2, 3}}] (* {a[1], b[2], c[3]} *) I still use Compose myself, but I would ...

Safety Module is safer than Block because: It is a lexical scoping construct, which means that variable bindings are only tied to a specific piece of code. Variables outside that piece of code are ...

To my mind, there are at least two cases when For loops are ok: Inside Compile, or in code which is being written with Compile in mind When your inner loops are vectorized or made efficient by some ...

A lot depends on how you write your code in Mathematica. In my experience, the rule of thumb is that the generated code will be efficient if the code inside Compile more or less resembles the code I ...

You can use custom transformation rules, for example: -11 - 2 x + x^2 - 4 y + y^2 - 6 z + z^2 //. (a : _ : 1)*s_Symbol^2 + (b : _ : 1)*s_ + rest__ :> a (s + b/(2 a))^2 - b^2/(4 a) + ...

Using Outer is here one of the worst methods, and not just because it computes the distance twice, but because you can't leverage vectorization in this approach. This is actually a common issue and an ...

Yes, there is, although the speed-up is not as dramatic as for 1D memoization: ClearAll[CharlierC]; CharlierC[0, a_, x_] := 1; CharlierC[1, a_, x_] := x - a; CharlierC[n_Integer, a_, x_] := Module[{...

Per suggestion of rcollyer, I have moved this answer here, with a few modifications / additions. Recursive pure functions (#0) seem to be one of the darker corners of the language. They are mentioned ...

The answer of @R.M. already explains the essence of the problem. You can streamline the process of removing the Combinatorica from the $ContextPath by loading it via Block[{$ContextPath}, Needs["...

These two forms may be similar on the surface, but they are very different in terms of the underlying mechanisms invloved. In a sense, Function represents the only true (but leaky) functional ...

As a part of a larger sets of development tools which I am working on currently, I have developed a general syntax highlighter generator which does just that (not yet with styles though, this is ...

The role and meaning of Listable The Listable attribute serves to impose automatic threading over lists for symbols for which it is set (or present from the start, for some built-in functions). ...

One way is to set a shared variable that would be assigned to an iterator variable, and monitor that: SetSharedVariable[j] Monitor[ ParallelTable[j = n;Length[FactorInteger[2^n - 1]], {n, 50, 300}]...

Managing the complexity III: using powerful abstractions In this section I will list a few techniques which allow one to write more modular code and better separate the concerns, by using certain ...

I think, your question has 3 levels: convenient syntax, data representation, and efficiency. I can offer a very lightweight solution which addresses all of these in the simplest way: syntax is ...

Some observations on Removed Removed is not a normal head, but rather a print form. Consider a definition x := y Once we Remove the y, we invalidate x in a subtle but permanent way - reintroducing ...

In practice, enforcing strong types in Mathematica seldom pays off, just because, as mentioned by @belisarius, Mathematica is untyped (and perhaps more so than most other langauges, since it is really ...

There were several attempts to emulate structs in Mathematica. Emphasis on emulate, since AFAIK there is no built - in support for it yet. One reason for that may be that structs are inherently ...

Preamble It is hard to say what exactly is causing this without seeing the code, but, assuming that there are no memory leaks in the built-in functions you are using, I am only aware of a very few ...

UPDATE Since version 10, we have Associations. Here is the modified code for trie building and querying, based on Associations. It is almost the same as the old code (which is below): ClearAll[...

While I agree that the debugging tools could have been better developed by now, let me just throw in a few notes and links. Function chaining (f[g[h[...]]]): I'd argue that this is a good thing. Why: ...

I can now offer a solution which leverages the full power of the code formatter, in its new, more robust form. Load the formatter: Import["https://raw.github.com/lshifr/CodeFormatter/master/...

General usage Here is what I think Using strings and subsequently ToString - ToExpression just to generate variable names is pretty much unacceptable, or at the very least should be the last thing ...

Preamble I will interpret your question as a general question on how one can organize multi-file projects in Mathematica / WL. There are two main axes in this problem, and they are Loading procedure ...