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?

  • 3
    I found something similar on stack overflow: stackoverflow.com/a/2647704/1009414 Maybe there you will find some info about this article. – Thaven Jan 8 '13 at 10:25
  • 1
    homomorphisms, catamorphisms and anamorphisms etc. might be worth a google, for loops that aren't on lists – jk. Jan 11 '13 at 15:13

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.

  • 14
    ...I was hoping "extreme" loops would be more, well, extreme... ;) – Izkata Jan 8 '13 at 20:43

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.