Mathematica Programming » Functional Programming
Map / Scan
Note that often we can even one-up
Do in terms of simplicity, while losing no performance.
Scan pass an argument from a list to a function, much as
Do iterate over a range or list:
Even better, though,
Map has a more compact in-line syntax:
Over time you will start thinking in this new syntax. Rather than “map prime-q over range of 10^6” you will start to think “prime-q slash at range of 10^6”.
Note that both
Table generate output, while their equivalents
Do don’t. Even though
Scan does not have in-line syntax it is worth getting to know, as it can sometimes be more efficient than
Do and is, of course, vastly more efficient than