
Joel writes:
Hi Aleksey,
Hi Joel,
Currently, Phoenix has local variables, lambda and scopes. IMHO, Phoenix-2 has the best syntax yet that satisfies all requirements so far:
Here's the solution to the use-case posed in the email exchanges above:
write a lambda expression that accepts:
1. a 2-dimensional container (e.g. vector<vector<int> >) 2. a container element (e.g. int)
and pushes-back the element to each of the vector<int>.
Solution:
for_each(_1, lambda(_a = _2) [ push_back(_1, _a) ] )
Since we do not have access to the arguments of the outer scopes beyond the lambda-body, we introduce a local variable _a that captures the second outer argument: _2. Hence: _a = _2. This local variable is visible inside the lambda scope.
Any particular reason why you decided against implicit scoping along the lines of for_each( _1, push_back(_1, outer(_2)) ) ? -- Aleksey Gurtovoy MetaCommunications Engineering