303 karma · joined July 19, 2013
EDIT: Found the answer (thanks, draft C11 standard.)
Section 6.3.2.1 contains the definition of lvalue, and it does not use the phrase "locator value" at all. However if you want to use it as a reminder that modifiable lvalues can be assigned to, then more power to ya :-)
I can't help it - I'm a sucker for standardese.
sort(begin(vs), end(vs),
[](auto const& l, auto const& r) {
return l.size() < r.size();
});
Even simpler. template <typename T>
T min(T a, T b)
{
if (a < b)
return a;
else
return b;
}
This code works for any type T (ints, strings, floating point numbers) that can be compared with less-than. In a language like Go that does not support generics, you would have to write a min function for ints, a different min function for strings, etc. mapM :: Monad m => (a -> m b) -> [a] -> m [b]
it returns the result of the computation. But sometimes you want to iterate over a list but discard the result (say you're printing elements.) mapM_ discards the result: mapM_ :: Monad m => (a -> m b) -> [a] -> m ()
where () denotes a kind of "null type".So if you want to store the results in a new list, you use mapM, but if you don't, and just want the "effects", you use mapM_.
Here's an example of each, using the IO monad. If I have a list of numbers, and I want to iterate through each one and prompt the user for a multiplier, I would write the code like this:
main = do
let numbers = [1.. 10]
numbers' <- forM numbers $ \n -> do
putStrLn "Enter a multiplier"
a <- getLine
return $ n * (read a :: Int)
where forM is just mapM with the arguments reversed to look more like a for-loop. Here I want the results of the computation, so I use forM. If, however I want to just print the numbers out, I'd use forM_ main = do
let numbers = [1.. 10]
forM_ numbers $ \n -> do
putStrLn (show n)C++ is one of the few (maybe the only) languages that gives you enough high-level features to be productive, but doesn't do so at the expensive of ruthless runtime efficiency. If you need to squeeze every ounce of juice out of a machine, but still require the ability to create good abstractions, C++ is for you.