
Aleksey Gurtovoy wrote:
Daniel Wallin writes:
Well OK, let's do that. What are your thoughts about adding something like this?
[...]
While straightforward, a primitive like 'unlambda' won't cover many use cases that I consider important. I'd be inclined towards more systematic approach to nested scoping, something along the lines of what is discussed in the attached conversation (long, but insightful). May be even implicit scoping for the library algorithms as described in one of these emails.
Hi Aleksey, Currently, Phoenix has local variables, lambda and scopes. IMHO, Phoenix-2 has the best syntax yet that satisfies all requirements so far: http://tinyurl.com/6qyqr 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. << Daniel helped in the brainstorming too. >> Cheers, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net