
C++: No raw loops - luu
http://www.randomprogramming.com/2014/03/no-raw-loops-1/
======
RodgerTheGreat
APL-family languages have for a long time encouraged similar practices,
eschewing explicit loops and recursion in favor of baking iteration into
operator application and a series of operators which express specific
iteration patterns.

Recently I've been having a great deal of fun learning K, a modern APL variant
which depends only upon standard ASCII characters for its syntax. In K, the
final example:

    
    
        adobe::for_each( v_T, f_T );
    

Would be simply:

    
    
        f'v
    

Read, "f each of v", sssuming v is defined as a vector and f is defined as a
function. There are other operators for different iteration patterns, such as
"Over":

    
    
        +/3 7 18
    

Which is equivalent to distributing the left argument of / (an operator like +
or potentially a whole function) between the elements of the right vector,
just as if we'd said:

    
    
        3+7+18
    

Sometimes it's tricky to hammer an existing algorithm into the selection of
patterns which is available, but it's not nearly as limiting as you might
imagine, and recasting your code to use K's set of operators often simplifies
problems considerably. It would certainly be difficult to be more concise.

------
frozenport
I'm weary about doing this for performance reasons, I often want to gather
more data as I iterate (for example items matching two different criteria),
and wrapping a complicated lambda in `std::` sounds bad for readability.

