Mathematica Programming » Functional Programming

Procedural Programming

In most programming languages (C++, Java, python) we generally use what is called "procedural programming" where we work in a very step-wise fashion. Perhaps the archetype of this is the "for-loop", the work-horse of standard programming. Mathematica, too, has a For loop. In fact we can use all the standard constructs of procedural programming:

For[ i =1, i<10,  i++,

We have a very simple set of steps, here, make a list, radii , initialize a loop variable i , then perform a task (appending a Real to radii ) and incrementing our loop variable i while some test holds ( i < 10 ). Everything is laid out very explicitly and easily to understand. Unfortunately, when writing a large program, having to go through so many steps is a hassle and impedes the development process.

Functional programming, which is almost always defined in contrast to procedural programming, deals with using functions like our usual primitives and passing them through other function accordingly. There are many facets to functional programming, of course, but its most common use is the application of functions to lists.

We can do the above process in a single line using a functional construct:


There are many useful functional constructs we can use that will solve large classes of programming issues for us.

See Also: