Functional languages are experiencing something of a renaissance, or so I gather from reading reddit and the blogs. I have been known to dabble in lisp, erlang, and haskell. Each is beautiful language in its own way. But when I actually want to get something done, not just play, I turn to either python or mathematica.

Python has a rich ecosystem and hosts of users. It’s great. But everyone knows about it. There is no need for me to go on about python. Mathematica is not widely appreciated as powerful and expressive language, so I propose to do a series of posts illustrating some extremely elegant features.

Mathematica is a product of Wolfram Research. The word Mathematica refers to both a commercial software product, and the programming language implemented by the product. I will distinguish between the product, Mathematica, and the language, which I will call mma. This is an idiosyncratic distinction, so bear with me.

I propose to talk mostly about functional programming in mma, something I’ve enjoyed doing since version 3, too many years ago. Though I have been a programmer for many years, I was trained as a mathematician. I started programming in imperative languages (pascal, c, moving later to java). When I first discovered functional programming, it was like coming home from a long exile. Mathematicians think in terms of functions. The three fundamental objects in mathematics are numbers, sets, and functions. Of the three, functions are the most fundamental. A functional language let’s me think in something close to my native language. Enough philosophy, let’s get started.

The Mathematica “shell” is called a notebook. The notebook interface includes a read-eval-print interpreter loop, but also provides very sophisticated graphics and text layout. Here’s a bit of eye candy to illustrate the point. The first illustration shows a matrix equation.

The second illustrates a topological object known as klein bottle. Actual klein bottles, alas, cannot be embedded in our puny three dimensional space. The cut-away graphics allow one to look inside.

The notebook interface implements a host of other interesting features, including a very robust help system. The notebook communicates with the Mathematica kernel via a protocol called mathlink. This enables Mathematica to effectively separate the user interface from the system’s computational kernel. It also allows the notebook interface to run on one machine, a notebook say, and the kernel to run on some other (perhaps more powerful) machine.

So much for the intro. In the next installment, we get down to business.