If you come from Lisp, note that Mathematica's approach to list manipulation is not through deconstruction operators like CAR and CDR and construction through CONS. And this is also different from traditional functional programming, in which most lists metaphors are actually derived from our old friend Lisp. Mathematica is very different.
Everything in Mathematica is an expression and certainly lists are. So deconstruction of expressions in Mathematica is achieved by using mainly pattern matching and some built-in operators. However, you usually don't need to disassemble a list (in the traditional sense) as Mathematica offers built-ins that are similar to the functional programming counterparts.
For List manipulation, I find Fold
, FoldList
, Map
and MapThread
probably the closest to FP - although there are many others which would be probably harder to achieve in FP but are built-ins in Mathematica. For example, look at Partition
or even Transpose
. Whereas in Lisp a list of lists is just that, Mathematica can transpose it as it were a matrix if you know that all items have the same length.
So, yes, you need to leave the FP list paradigm and embrace expressions in Mathematica!
functional-programming
tag here programmers.stackexchange.com/questions/tagged/… also see wiki en.wikipedia.org/wiki/Functional_programming $\endgroup$ – Nasser Dec 17 '13 at 21:37