11

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?

Kilian Foth
  • 107,706
  • 45
  • 295
  • 310
stusmith
  • 161
  • 5
  • 3
    I found something similar on stack overflow: http://stackoverflow.com/a/2647704/1009414 Maybe there you will find some info about this article. – Thaven Jan 08 '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

2 Answers2

11

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.

0

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.

Sylwester
  • 529
  • 2
  • 7