Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
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
add comment

2 Answers

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.

share|improve this answer
add comment

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.

share|improve this answer
14  
...I was hoping "extreme" loops would be more, well, extreme... ;) –  Izkata Jan 8 '13 at 20:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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