# Having used Mathematica as a “gateway” language, where to from here?

I have been using Mathematica for about a year. It is the first language that I have attempted to learn. I'm still very much a newbie, but there are moments I feel more like I am waving than drowning. As with many addictions, at first it left an unpleasant taste, but with time, using Mathematica started to open up new possibilities and I have come to depend on it.

It has occurred to me that there are a number of reasons why at some stage I would like to learn some new language(s) to complement Mathematica and further nurture my 'coding brain'. At times I feel slightly handicapped by not really understanding the capabilities/pitfalls of, for example, Do loops and other constructs that seem common in many languages. Indeed, it would be nice to be able to understand/relate to programmers that don't use Mathematica.

Although a lot of coding paradigms can be used in Mathematica, I feel it would be instructive to spend some time learning strictly procedural, object-oriented, etc. programming styles in the context of another language. Which other programming languages should a Mathematica-only user be interested in, so as to appreciate the underlying programming principles and constructs that one takes for granted with Mathematica?

Alternatively, I understand that there are a number of languages that can be implemented or interfaced from within Mathematica. Would it be a worthwhile trying to learn other languages/coding styles without leaving the notebook environment?

• This doesn't appear to be a question about Mathematica as such. Moreover, I would say that in the plethora of languages that exist, it depends what you might want to do with them as to which ones you should chose. You could learn about Do loops in a few minutes in a way which is independent of any particular language (or indeed within Mathematica) but the desired implementation should perhaps drive the tool of choice. Right now there are many nice languages being taught online, see for example codecademy.com, which might be an easy way to start. – Jonathan Shock May 23 '13 at 2:34
• As quite a few gentlemen here I am in favor of keeping the question - it is rather an interesting topic. – Vitaliy Kaurov May 23 '13 at 3:34
• FWIW, I vote against closing. – J. M.'s ennui May 23 '13 at 11:33
• I don't want to close this question, but I would ask that people posting answers address some key issues that would be relevant to Mathematica users: (1) integration with Mathematica; (2) learning curve for someone already familiar with Mathematica and functional programming; (3) value-add of things Mathematica doesn't do so well (o/o, performance etc). – Verbeia May 23 '13 at 13:33
• @Jens I think this question is of that rare type which,while having no definite answer, may allow us as a community to reflect our place in the programming universe. So, just for this alone, I would make an exception and keep it. Perhaps, this is a close proxy to another question which many of us might be interested in: how does one productively expand his/her programming skills to be able to do more powerful things, having Mathematica as a base, and so that this base background is used most effectively. This is pretty much what was asked. – Leonid Shifrin May 23 '13 at 15:23

## A personal view

I was in a similar situation about 5 years ago. By then, I knew Mathematica well, but not much of anything else (I had some prior experience with a number of languages, but that was from the academic, rather than programming, perspective).

What I did was to learn C. I did it because I knew that otherwise I would be forever scared of low-level stuff, memory management, etc. High-level languages bring you the comfort of not worrying about low-level issues, but it is still good to be exposed to them at some point. I still think this was a right move, and would recommend learning C.

Where to go from there is a personal thing, and depends greatly on the goals you set for yourself. If you have some free time and want to learn some all-around useful and practical language, I'd then go with Python. If you have even more free time, some Lisp flavor would be great to learn.

But if you want to learn something really practical where lots of active development is going on right now, learn Javascript. It is rapidly becoming the assembly language for the web, in the sense that more and more languages compile to it as a target. It is a cool language in its own right, with all its short-comings, and it is very widely used. Some people consider it a Lisp wrapped in C-like syntax. I can certainly say from my own experience with it that it doesn't get in the way and is very fluid and nice to work with. The good thing about Javascript is that you can use it for OO and for functional programming, and there are currently tons of projects people are actively working on in Javascript, so you can pick some projects and learn from them.

## How to leverage Mathematica

Those considerations I gave above are rather general, and more based on my personal story and views. But there are objective matters here too, many of which were mentioned in other answers. I would still add here my version of these arguments.

There are two "dimensions" where your Mathematica background may help (or, in any case, will be important). First is to become a better programmer through learning and using powerful abstractions, ways of thinking and programming techniques. For this direction, it is crucial to critically assess what Mathematica is and is not, its strong and weak points (as a language), good habits and bad habits we acquire as a result of doing some serious development in it.

### Becoming a better programmer

I will mention a few strong and weak points, and the languages which would either share a strong point or help with the weak one

Strong points include

• Ultra-rapid development due to multi-paradigm dynamic language. The characteristic features are

• Bottom-up development,
• Using immutable code and functional programming

Pretty much any language of the Lisp family will share and reinforce this point, although perhaps Mathematica is unmatched here, both due to an extremely high-level nature and to its notebook interface. Python and Javascript will too, but they don't have such an explicit support for functional programming. Still, it is the dynamic and untyped nature of the language which is most important here, not the FP support per se

• Many ways to solve a given problem. This is a mixed blessing, but for a beginner it is probably better than the opposite, since it encourages experimentation. I've heard that Perl and Ruby share this property. It seems important that the language is untyped and dynamic to have this.

• Elegant and terse code for many problems - I've heard that some Lisp dialects (such as Arc) also have this feature. However, the Mathematica's type of terseness seems more of the type that strongly-typed languages like SML/OCaml/F# provide, or APL-family languages if you are interested in array-based operations.

• Powerful meta-programming facilities. This comes from the facts that Mathematica is symbolic language, and also is homoiconic and supports the code-is-data paradigm. All or mmost Lisp-family languages also have this feature. At the same time, meta-programming in Mathematica is hindered by the lack of its widespread use in the community, and the lack of certain metaprogramming libraries which would make many things easier. But I think this is a temporary difficulty.

Some of the weaker points

• Evaluation process too general and too complex for many programming problems. In other words, many or most programming problems don't require full symbolic power of the evaluator,but because you can't "switch off" part of it, there is a large mental overhead involved. In other words, Mathematica quite strongly violates principle of minimal surprise. I consider this as one of the weakest sides of Mathematica as a programming language, while at the same time one of the strongest sides of it as a general symbolic system. Almost any functional (or OO) language you pick will not have this problem to such extent.

• Incomplete support of functional programming. What I mean here is that recursion and linked lists are not supported as a main idiomatic tool for thinking about programming. You can still use it, but not as natural as in other FP languages. Besides, lexical scoping is an emulation, which reflects itself both in "leaks" and the user's ability to break it, and in e.g. closure creation being essentially a hack using leaked Module variables, rather than officially-supported feature. In this respect, many well-known FP languages (e.g. both Lisp and ML families) will have a more clean foundation for learning more FP techniques.

• No systematic tools to scale for larger code bases. Strongly -typed langauges (Java, Scala, F#, ML/OCaml, Haskell) use type system for that, Lisp-family languages use macros and closures, and OO-supporting languages (Python, Java) also use object-orientation (inheritance, polymorphism). Mathematica sort of is able to do all of this, but none is simple and automatic enough to be used as a tool. So, while scaling to larger code bases is certainly possible in Mathematica, it requires experience and discipline. In any case, I would certainly use other language to learn how this is done.

• Performance and the lack of native general efficient data structures. This is a problem typical for scripting languages with two or more performance scales. To a lesser extent, it is present also in MATLAB and R, while most other languages (Python, Scala, Lisp-family languages, ML-family languages, Haskell, Javascript, C of course, etc) don't have this issue much or at all. I would certainly pick some of general-purpose languages to learn the algorithms/ data structures, although Mathematica can be extremely useful for this as well, when writing prototypes (it just has often unacceptable time constants for many simple implementations). I think that data structures are best learned either with C or some strongly-typed language (ML/Ocaml/F#, Haskell).

### Getting practical

In this respect, one very sensible suggestion was given by Vitaliy: try to use languages which have already (or potentially) a good linking with Mathematica. This will help a lot because you can use Mathematica as an incredible high-level testing and development environment for those languages.

All languages running on the JVM (Scala, Clojure, Groovy, Jython, JRuby) should have a very good potential for intergation with Mathematica, due to the existence of JLink (of course, Java is too). Of course, C is also well-integrated with Mathematica via MathLink and LibraryLink, and .Net - based languages too, via .Net/Link.

By learning these languages in integration with Mathematica, you will not just learn the languages, but add some more parts to the "technology stack" which you might be able to use in the future to create more complex systems, for which Mathematica alone (as well as other languages alone) may not be as good as their combination. While currently such integration tools are not yet well-developed, I feel Mathematica has a huge potential as a system integrator and a medium which may serve as a catalyst in rapidly producing hybrid systems written in a number of different languages. Traditionally, the majority of efforts for such systems seem to have been spent on overcoming cross-language barriers, but if all these languages are interconnected through Mathematica as a central "hub", this problem may be seriosly alleviated.

So, from this perspective, you may pick the language which is best - integrated with Mathematica - as Vitaliy already suggested.

• I'd suggest C too, for the reasons you've stated. If nothing else, it will give geordie a new appreciation of Mathematica :-) – Simon Woods May 23 '13 at 14:32
• @SimonWoods Well, I really love C. It just so happens that recently I did not have many chances to work with it, but I hope that will change. Actually, I empirically found that I tend to really like languages which are good to both write code in them and to generate code automatically. From the langauges I know reasonably well and like a lot, all - Mathematica, C and Javascript - do have this property. – Leonid Shifrin May 23 '13 at 14:52
• Oh I didn't mean to imply that geordie would dislike C, just that having Mathematica as a first language it must be easy to underestimate just how much low-level stuff is going on behind the scenes. It sounds like I should be adding Javascript to the list of "languages I would like to learn but never seem to find the time to do so". (Currently Python is at the top of that list, Julia looks interesting too) – Simon Woods May 23 '13 at 16:05
• @Jens I have not used Python for anything serious, so can't comment on that, but I have no problem to believe that it is great as a technology integrator (I also know that lots of people are using it in this capacity). The reason I think that Mathematica still has huge potential here is that I think it is important what thinking mode does the integrating medium impose on the developer. This mode will naturally be limited to what that language allows (again, in terms of thinking process). I think Mathematica allows very powerful generic thinking process which would be hard to achieve otherwise. – Leonid Shifrin May 23 '13 at 18:02
• @Stefan Re:"hub" - yes, it won't be very easy, but I think it's quite possible, and also I feel that this direction has a huge potential. Generally, we seem to live in a very eclectic time, where a lot of knowledge and resources have been accumulated in narrow (sub)fields, while few attempts were made so far towards the synthesis. Since the common denominator must be a broad and permissive medium, imposing least possible contraints (in the first place, on thinking / expressing ourselves), I view Mathematica as a viable candidate for such an integration medium for programming. – Leonid Shifrin May 23 '13 at 18:20

Leonid has presented a nice overview of some of MMA's weak and strong points. I'll present here some arguments why Python might be worth learning next. These are based on personal experience, since I did not get the point of Python until after I attended this workshop.

Go with Python. You'll be surprised how quickly it's possible to get some things done.

Python is a well designed object oriented general purpose dynamically typed scripting language. Apart from OOP it supports procedural and limited functional programing, so you will be able to practice a different way of writing programs.

Python currently has a lot of momentum in the scientific computing community: (see here, here, here for some nice introductions). The core scientific packages are Numpy, Scipy and matplotlib. But then there is a rich ecosystem for almost anything from HDF5 to antigravity:)

For most stuff Python is fast enough. Critical parts can easily be written in Cython or by hand in any low level language capable of producing a DLL.

Python is open-source and cross-platform.

Regarding MMA integration: I have no personal experience here. But there are options.

I'll sign off with a classic xkcd:

On dark nights I sometimes regret my thesis code is not written in Python (but in MMA). Why you might ask? I'm doing some numerical stuff on large vector arrays ($10^7$ of 2D points). Somewhere deep down MMA unpacks them for a short while and eats GB of RAM. Loading a 40MB text file takes 3 GB. There is no real pass-by-reference (can be faked with HoldFirst), so I never know when copies are made. It's not open source or widely used, which makes the code I publish along with any article less attractive.

Don't get me wrong, MMA is the second language I learned (with Object Pascal being first) and I like it. But if I knew then what I know now, I'd go with Python.

• I completely agree with Ajasja. Python is go-go for the newcomer. 1. written code easily understandable. 2. Gradual learning curve: Whatever you want to do with python, you can do it. You can easily start with scripts, then use list and databases, handle processes, threads, exceptions, object orientation. You don't have to be afraid that there is something that can't be done in python, but it's very easy to start using it. – Kobor42 May 23 '13 at 12:41
• I upvoted this because one has to know at least one non-commercial language in order to be more independent and mobile. – Jens May 23 '13 at 18:10
• @MarkMcClure Does the edit help? – Ajasja May 24 '13 at 17:39
• It's definitely better (+1). I cannot stress how much I hate hidden unpacking of lists, and very recently, I was in the same situation as you — I had a 3GB matrix, which after a series of transformations, was reduced to a 1GB matrix. Somewhere along the line, some hidden unpacking occurred which blew up memory usage to 11GB and was extremely hard to debug. It's under control now (and the changes made were minimal and subtle), but it was very frustrating to see otherwise "clean" code result in terrible performance (2-3 hrs vs. 60s after fixing) – rm -rf May 24 '13 at 21:57
• I agree about the copying issues, but I think Python suffers from this almost as badly at times. For example, "advanced indexing" into an ndarray produces a copy of the data, and this operation seems to be used quite often internally (which is not surprising given how powerful it is). I've written programs using advanced indexing that run quickly with datasets below some threshold size but slow down dramatically when this threshold is exceeded, apparently due to some sort of memory management issue related to this copying. – Oleksandr R. May 26 '13 at 2:07

I think similarities and differences between the languages is very interesting discussion and I am glad Andrew replied something in that manner - I hope comments/answers will follow ;) On the other hand, concentrating rather on practical matters - a natural choice seems the languages that Mathematica is linked with. While you keep sharpening your Mathematica skill, you might find beneficial to learn, for example, C and then compile to it for speed in some cases. Wouldn't be also wonderful to master CUDA and OpenCL to employ GPUs in your Mathematica programming? R, Java, .NET - may come handy in some specific cases - so I'd recommend to read through:

Systems Interfaces & Deployment

Also related recent interesting discussion here - what a fun read:

Why Would a Mathematica User Care about R?

• +1 This is really the kind of information I'm looking for. – geordie May 23 '13 at 3:34
• The note on 'linking to R' is really interesting. – geordie May 23 '13 at 11:40

Geordie,

The simplistic answer is install a copy of Dartmouth Basic or Pascal and fiddle with it. Not necessarily a bad starting point, but I think a far more detailed subjective approach will offer longer term benefits. For what its worth I'll share my experience.

So, for me, learning other languages was and is a practical matter dependent on motivation and purpose, what you're doing, who you're doing it for and most important longer term considerations of what you want to do - the proverbial 'where do you want to be in five years'. Operating at the quanta level in some cosmic enterprise may immediately require various language skills, specifically mandated or clear in context. And, of course, in that situation it's important to be able to hold your own professionally. In contrast, in a start-up, Mathematica is very helpful stand-alone or to model and prototype for other coding. In this case, other code depends on your circumstances and is less motivated by competitive professional pressures.

My second act was a start-up, and like you, Mathematica was my first programming language. I had started a boutique fixed income money management firm in 1989. Having come from twenty years at a large Wall Street firm with state of the art analytics, I understood that the ability to 'roll my own' analytics translated to a totally customized solution for clients.

As I researched languages and software, I tripped over an odd duo in a Palo Alto Mac software store, Wolfram and Theo Gray peddling Mathematica (literally, shirts sleeves rolled up talking to anyone who would listen, including me.) Wolfram made noises about aspects of his product that made little sense at the time, but when he talked about efficient programming relative to other languages, I plunked down my $299 and took home the package, v1 Mathematica. I suffered an horrendous learning curve ... many years. But, by the mid-nineties I was writing Mathematica packages which included the usual suspects of fixed income packages, options and futures packages capable of moderate data access, a GARCH package (with significant help from Wolfram) and some customized indexes. I was quite pleased with myself, competitive, the clients were happy, billings were paid promptly. By that time it was apparent that APIs might have value. So I fiddled with MathLink and learned some C. The number of pertinent vertical apps was too small to justify the time commitment. My needs were satisfied almost entirely with Mathematica. From day one I had a significant problem with Mathematica and large data sets. ReadList and later Import were slow and painful, streaming was better but not much and the SQL interface introduced in v4 was better but marginally so. The problem persisted through 2005. In the last eight odd years, with the advent of Big Data solutions in the guise of Hadoop and its offspring and platforms like Talend Open Studio, my demands on Mathematica have morphed. Being able to write Mathematica command line scripts has become invaluable. For example, Talend is a marvelous platform, but some of its GUI components lack granularity. In those cases it is far more efficient to write on the fly scripts than create new Java components for things like date and string parsing, analytics and file handling. You need some Unix which if you don't have you should acquire. (see Powers, Peek, O'Reilly, Loukides "Unix Power Tools") Over the last eighteen-months I have happily learned enough Java and J/Link to effectively interact with in-memory database solutions, in this case VOLTDB, which is written in Java. This solution is exponentially faster than disk based solutions with an enormous benefit. I can write my own GUI in Mathematica. Over the years, I've looked at a variety of languages and longed to learn them all. My work with Mathematica has allowed me to conceptualize various programming paradigms and techniques. And I've received invaluable help from folks like Roman Maeder, Stan Wagon, David Wagner, Patrick Tam, Tom Wickham-Jones, Hal Varion, Heikki Ruskeepaa, and Sal Mangano.They all make it look oohh so easy. If you can get their books you should. I have always found the cookbook formats to be useful. If it's practical for you, you might take a look at O'Reilly's SafariBooksOnline.com . I would find an efficient way to grasp the basics (the Basic Pascal approach) but then be driven by circumstances and desire. And read read read. Best of luck. • Welcome to the site! What a great story--it sounds like Mathematica appeared in just the right place at the right time for you. In the interests of making the advice more appropriate to the modern day than the 1970s, though, I wonder if Pascal and Dartmouth BASIC ought to be replaced by Ruby and Python? Even though my first language was BASIC, I wouldn't recommend it to anyone today. Fortunately, there are far better languages available now, from which one can learn much more, far more quickly, and without developing bad habits. – Oleksandr R. May 30 '13 at 22:33 • Tks, I was fortunate. Mathematica was very helpful in so many ways. I dare say at the very least Python with which I've spent some time would be better. I don't know much about Ruby. – jcm May 31 '13 at 0:57 I knew more than a dozen languages before I learn Mathematica, so just like Andrew, I am also surprised that Mathematica is your first language. But, you are such a lucky person that your supervisor uses Mathematica, not Matlab (I am not joking)! There is not a simple answer to your question, because if there was a single best programming language, we shouldn't have had so many of them out there. First of all, I should mention that, in theory, almost all of the programming languages have the same power. They are all Turing Complete. So, essentially, every program which is written in Mathematica, could also be written in C, C++, Python, Prolog, Haskell, or Java. However, in practice, each programming language is good in doing a few things and bad in other ones. Second, why should someone learn a new language? (1) Sometimes, you want to do something that Mathematica is not the best language for. (2) Some of the techniques that can be helpful in your favourite language are much more obvious or focused-on in other languages. For instance, I learned about some of the list operations such as folding, mapping, zipping, and pattern matching when I was using Haskell, but I use them frequently in Ruby and Groovy. My skills in other programming languages are helpful while I am programming in Mathematica as well. Third, what programming language should you learn next? Well, it really depends on your job and your interests. If you are always solving equations symbolically or plotting them, stick with Mathematica. Otherwise, my short answer is: Python or Ruby are good choices for the first step. Java and Scala are good for the next step. A long answer follows. Mathematica is a functional (but not purely function), untyped, interpreted, symbolic language. The programming environment (notebooks) of Mathematica is also different from pretty much any other programming language I have ever seen (maybe Maple is the only similar one that I remember). There are generally two types of programming languages: Declarative languages (in which the program specifies what is the desired output, but not how to compute it) and imperative languages (in which the program specifies how to compute it as well). Functional languages (such as Haskell and SML) and logic programming languages (such as Prolog) are in the first category while most of the well-known programming languages such as C/C++, Python, Java, Fortran, Pascal, Basic, ... fall into the second category. Mathematica falls somewhere in between because it has some of the features of the functional languages (such as pattern matching and higher order functions) and some of the features of procedural languages (Do/While loops and mutable variables, for instance). So, learning a purely functional or purely imperative language would be instructive. Another important aspect of any programming language is its typing system. There are two different semantics that are being confused very often: (1) Static typing (i.e., type of a variable cannot change) vs. dynamic typing. (2) loosely typed (i.e., any operator/function can be applied to any any variable/constant) vs. strongly typed. As an example, Java is a statically and strongly typed language. If you define the type of a variable as integer, you cannot (1) change the type, (2) assign a float value to it, and (3) pass it to a function that accepts strings. Mathematica typing system is totally unclear for me. I can say it's an untyped language since everything is considered as an expression in Mathematica. You can apply any (defined or undefined) function on any expression. But, in some other sense, you can use patterns to specify the types or heads (e.g., Integer, Real, List, ...). So, I would say it's something in between loosely/dynamically typed and untyped. So, learning a statically and strongly typed language, such as Java or Scala, would be helpful too. • Do you have any view on Scala vs. F#? I have heard good things about both of these but have no practical experience of either. – Oleksandr R. May 23 '13 at 13:26 • I love Scala but I don't know really so much about F#. Scala is quite a complicated language since it combines OO with functional programming (and it does it in a good manner). Learning Scala is not as easy as learning Python for sure. About F#, you should ask yourself if you want to put your eggs in Microsoft's basket or not. – Helium May 23 '13 at 13:34 • @Mohsen from my opinion this is the best answer so far although it DOES NOT MENTION PERL AT ALL!! :) Where I can't agree with is that the experience in other programming languages helped with Mathematica. Very often I am struggling because I expected a totally different behavior and had to force myself towards Mma idiosyncrasies... Said that...Kudos! Very good answer indeed...upvote! – Stefan May 23 '13 at 15:02 • @Stefan: Thanks Stefan. About Perl: I was surprised by Perl for a while before I knew Ruby. Believe it or not, Perl's programs are messy and unreadable. Yes, you can convert a 50 lines C++ program to a 5 line Perl code. But, if you want to write large scale maintainable programs with perl, you would be disappointed. Go read about Ruby ruby-lang.org/en/about. Larry Wall (the creator of Perl) is the hero of Yukihiro “Matz” Matsumoto (the creator of Ruby). – Helium May 23 '13 at 19:21 • About the second part: I agree with you to some extent about the Mathematica's different behaviour. But just assume you already know about the fast-fail nature of some languages like Java, C++, C#, or Pascal and then you move to Mma. You might be able to change the Mma's slow-fail behaviour by a bit of extra effort. – Helium May 23 '13 at 19:27 I think that there has been interesting discussion here, but perhaps an appropriate reaction to the original poster is to change the question, and then answer it. The new question: What language should I learn next so as to make me a better Mathematica programmer? In my view there are several possibilities, but the one that strikes me as (likely) the best, is to learn Scheme from the Abelson-Sussman text. The Scheme (dialect of Lisp) is the distilled essence of an easily-learned functional programming language. The book, which should be read by programmers regardless of their original language, reveals to the attentive reader a style of programming and data structuring that opens up new pathways to solving problems. It is especially pertinent to Mathematica because, as some have observed, there is a strong element of Lisp in Mathematica. Under the complex syntax, anything can be re-expressed in what is effectively Lisp syntax by displaying in FullFormat. I cannot say for sure that other languages and books are necessarily inferior for your choice of a second language -- after all your context is different from mine. Since you mention "do" in particular, you may find that Scheme doesn't need a do-loop, but you can really really understand what a do-loop is by implementing a language feature which is a do-loop by writing simple code in Scheme. Understanding functions, functional applications, recursion of programs and recursive data structures like trees may inspire you to write better Mathematica programs, and even to understand the programs you've already written or others have written, better. • Not enough love for this answer! Unfortunately, the fate of many good answers added much later is a long period of relative obscurity - which is a certain flaw of the current SE model. I only bumped into it today, by a pure accident. – Leonid Shifrin Sep 16 '14 at 13:55 There are so many interesting programming languages to choose from that you would need more than one lifetime to explore them all. Going back to the Lisp origins of Mathematica would lead you to Clojure, to Scheme and the practical Racket, and then to Common Lisp, which is a behemoth a bit like Mathematica, and there's plenty there to stretch your brain cells (and to remind of you of the early days of learning Mathematica). The book by David Wagner, "Power Programming with Mathematica", now freely-available thanks to the efforts of Todd et al. shows this table of correspondences between Lisp and Mathematica: so your experience with functional programming will give you a head start. Haskell is interesting. Here's the basic Fibonacci: fib :: Integer -> Integer fib 0 = 1 fib 1 = 1 fib n = fib (n-1) + fib (n-2)  compared with a Mathematica definition: fib[0] = 1; fib[1] = 1; fib[n_] := fib[n - 1] + fib[n -2];  and mapping a Haskell 'pure function' over a list:  map (\x -> x + 1) [1,2,3,4]  Or you could do something unpredictable and look at Factor, which will get you thinking backwards. • If we're talking about research languages, maybe it's also worth mentioning Maude, a term rewriting system, and Clean, a dynamically typed pure functional language. – Oleksandr R. May 23 '13 at 13:05 • And Julia as well... – Ajasja May 24 '13 at 17:47 • @OleksandrR. I was looking at Pure the other day. As far as I know, it's the only general purpose language based on term rewriting that has a potential of being useful. (It's predecessor, Q, is not developed any more.) It even has some math libraries (a GSL interface). – Szabolcs May 30 '13 at 20:17 • Not fair fib[n_] := fib[n - 1] + fib[n -2]; would have to be fib[n_] := fib[n]=fib[n - 1] + fib[n -2]; – nilo de roock Feb 20 '16 at 10:14 It's really fascinating to hear from someone who learned Mathematica first! This is something I have thought about a bit. Among mainstream languages, I think the overall closest in spirit is Scala. Selected similarities: • Case classes for rudimentary pattern matching • A strong emphasis on functional programming Selected differences: • Strong type checking • Scala, like most non-Lispy languages, is not homoiconic • +1 I think this could be an interesting discussion ;) – Vitaliy Kaurov May 23 '13 at 3:19 • Considering how blurry the boundary between code and data is in mma, I take it then that mma is homoiconic? – rcollyer May 23 '13 at 3:20 • It was mentioned in the question that it would be good to explore procedural languages. My knowledge of these things is limited, but it seems that Scala is very much functional. This doesn't mean that this isn't a good answer, but I think it's important to note how this does and does not satisfy the question. – Jonathan Shock May 23 '13 at 3:42 I'm pretty sad that no one has mentioned Perl! Since more than 20 years Perl is the fastest and most efficient dynamic language. A lot of people say that Perl's syntax is unreadable or crude. I say it is readable indeed. Syntax follows semantics ;) With Perl you're back in time where men were men and wrote their own primality test: sub is_prime { my ($number) = @_;
return (1 x $number) !~ m/\A (?: 1? | (11+?) (?> \1+ ) ) \Z/xms; }  or: sub is_prime { print "Prime!\n" if (1 x shift) !~ /^1?$|^(11+?)\1+$/ }  EDIT 3 Just to turn my post into a popular one (sigh), here is the Mma equivalent of the regex prime checker: PrimeRxQ[number_Integer] := Not @ StringMatchQ[ConstantArray["1",number]//StringJoin, RegularExpression["^1?$|^(11+?)\\1+$"]]  !!TMTOWTDI and DWIM!! EDIT 1 Just because some mentioned the capabilities of other languages to support imperative and functional style of coding, I'd like to show how easy it is to achieve something similar with Perl. Functional programming Currying currying is a technique which transforms an ordinary function into a function factory for manufacturing more functions. Perl's built in functions map / grep are higher-order functions because each of them takes an argument that is itself another function. map {$_ * 2 } (1..5)           # returns 2, 4, 6, 8
grep { $_ % 2 == 0 } (1..10) # returns 2, 4, 6, 8  A curried function of these functions is often more convenient: sub cmap(&) { my$f = shift;
my $r = sub { my @result; for(@_) { push @result,$f->($_); } @result; }; return$r;
}

sub cgrep(&) {
my $f = shift; my$r = sub {
my @result;
for(@_) {
push @result, $_ if$f->($_); } @result; }; return$r;
}


these functions can be called like this:

$double = cmap {$_ * 2 };
$evens = cgrep {$_ % 2 == 0 };


after which:

$double->(1..5) returns (2, 4, 6, 8, 10)  and $evens->(1..10) returns (2, 4, 6, 8, 10)


If we talk about other functional idioms (memoizing, automatic currying, foldl, foldr etc.) these can be easily achieved as well with the

P athologically E clectic R ubbish L ister :)

And last but not least! Perl runs nearly everywhere. Perl is one of the most portable programming environments available today. (just to toot in another superlative horn)

Edit 2

As others did, I leave you as well with a classic picture from xkcd:

Edit end

• I guess your primality tests are based on the regular expression primality checker. Cute, but I'm not sure that's the right code to convince the uninitiated that perl is readable. :) – Mark McClure May 23 '13 at 12:06
• well the second one is the regex-checker made famous by Abigail: perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/' [number] the first is based on the same principle, but cleaned and hardened up. – Stefan May 23 '13 at 12:15
• The numbers are self explanatory. 0 upvotes for perl, 6 upvotes for python. I am sure perl is efficient, but this post is about learning curves - and perl is one of the worst candidates here. – Kobor42 May 23 '13 at 12:45
• To be clear, I rather like Perl for some of the same reasons that I like Mathematica. Both of them allow you to specify a program using a very small number of symbols and figuring out the way to do so can be quite fun. I used Perl quite a bit back in the mid 90s when I was first trying to seriously interact with students over the web. At that time, CGI via Perl or C was the only way to go. However, both Perl and Mathematica are rather domain specific and I don't know that I'd use either too much outside of their originally intended domain. – Mark McClure May 23 '13 at 13:58
• Mathematica has tried to capture some Perl mojo with its regular expression capabilities, and one can write pretty opaque code in Mathematica too, so I can see the overlap... – Jens May 23 '13 at 18:14

I myself want to compare the weak and strong points of Mathematica with another programming language. I found that the report of Mathematica analysis team is really helpful.

I cite some of them

KEY ADVANTAGES OF MATHEMATICA AS A PROGRAMMING LANGUAGE: ( vs C, C++, Java, C#, Fortran, Pascal, ...)

1. Immediate built-in access to the world's latest math and other algorithms
2. Automatic algorithm selection, typically vastly outperforming custom-written code
3. Consistent symbolic syntax and semantics across all data, functions and interfaces
4. Stable language on all platforms with consistent development since 1988 »
5. Symbolic paradigm maximizing code modularity, analyzability and testability
6. Fully integrated visualization, interface building, document generation and data interchange Unified environment for model generation, analysis, execution and deployment
7. Symbolic structure allowing derivation and representation of code as well as data
8. Formulas entered in traditional math notation, for enhanced readability and verifiability Built-in complex numbers, arbitrary-precision and automatic-precision tracking »
9. Immediate vector, matrix, and arbitrary-array programming »
10. Wide range of optimized data structures (e.g. sparse arrays and interpolating functions) »

....

I'm using Mathematica as a Research Language. And I'm happy with Mathematica due to it's ability to quickly build a small, fast application in my research. It really saves my time and effort !

KEY ADVANTAGES OF MATHEMATICA AS A RESEARCH LANGUAGE: (vs Lisp, Scheme, ML, Caml, Haskell, Prolog, Smalltalk, FP, ...)

1. World's most advanced practical symbolic pattern matcher
2. Functional reactive programming extended using the Dynamic construct
3. Support for rule-based programming with easy extensibility »
4. Immediate support for reflective programming
5. Symbolic encapsulation mechanism »
6. Arbitrary user-definable textual and graphical syntax

As a scripting language

KEY ADVANTAGES OF MATHEMATICA AS A SCRIPTING LANGUAGE: (Perl, Python, Ruby, PHP, JavaScript, ...)

1. Functional, rule-based, procedural and other programming styles all integrated
2. Uniform representation of all data, programs, interfaces, etc. as symbolic expressions
3. Typeless language designed for manipulation of arbitrarily nested and complex data
4. Unique structural pattern matcher, allowing flexible case-based programming
5. Highly readable code with consistent, easy-to-understand, function names ....