Mathcad Prime fold function
Whilst playing around trying to write a function to remove text rows from a mixed string/numeric matrix (*), I discovered that the undocumented (but very useful) function fold doesn't just work on vectors but also works on matrices, scanning down each column in turn, in the normal Mathcad fashion.
This behaviour opens up the possibility of some straightforward implementations of useful functions, such as converting a (potentially arbitrarily nested) array into a vector and summing the elements of an array.
Here are some Mathcad Express 7 functions.



Or we could define matsum to sum just the numeric elements of an array.

Alternatively, we could shift the burden of removing non-numbers to a specialized version of vec.

We can even count the elements in nested arrays.

The full version of Mathcad Prime allows the user to write programs to create functions. This facility opens up the possibility of writing a more generic filter function using fold by creating functions containing tailored boolean predicates.
Stuart
(*) https://community.ptc.com/t5/PTC-Mathcad/READ-FILE-RANGE-OF-ROWS-AND-COLUMNS/m-p/760410#M198424

