I remember once reading some research where a body of C code had been analysed, and the findings were that the vast majority of for
loops could be categorised into about five categories, corresponding to the functional equivalents of map
, filter
, fold
, etc.
I can’t seem to find this paper/article anymore. Can anyone point me to it?
2
This isn’t an exact match for what you were requesting, but I think it gets pretty close to the root of your question.
This site’s page on Loops discusses a number of looping patterns.
- counting
- filtered-count
- accumulate
- filtered-accumulate
- search
- extreme
- extreme-index
- filter
- map
- shuffle
- merge
- fossilized
- missed-condition
They also have a page on Recursion that covers many of the same patterns in a recursive manner.
1
I think I’ve heard it too. Somewhere in the SICP-videos or the book i think I heard that most (if not all) programs/algorithms can be expressed using streams and filters. Streams starts at lecture 6A.
As for all loops (for, while, do-while and so on) they all are implemented with label, compare and conditional jump so they are just syntactic sugar to make it easier to read and understand.