Subject: Re: phoenix lambda-lambda for_each example
From: Joel de Guzman <[email-masked]>
To: Noah Stein <[email-masked]>
Cc: David Abrahams <[email-masked]>, Aleksey Gurtovoy <[email-masked]>, Jaakko Jarvi <[email-masked]>
Date: Thu, 04 Mar 2004 10:17:29 +0800

Noah Stein wrote:

>>From: Joel de Guzman [mailto:[email-masked]]
> 
> 
>>Honestly, I still prefer the "outer" approach. Upon inspection,
>>the example we are using is flawed. Let me start again with
>>a problem: I want to push_back x to all sequences in v when
>>calling a lambda-function f:
>>
>>     f(v, x);
>>
>>The lambda expression, using outer, is:
>>
>>     for_each(_1, push_back(_1, outer(_2)))
>>
>>I honestly find nothing confusing here. I actually see it as simple
>>and elegant. Compare this with the alternate scheme:
>>
>>     absolute_argument<1> v; // need to declare
>>     absolute_argument<2> x; // need to declare
>>
>>     for_each[v, x](v, push_back(_1, x))
>>
>>I really do not find this to be any better than the terse, single
>>line lambda expression. 1) You'll have to declare the place-holders.
>>2) The syntax does not look like a c++ function call.
> 
> 
> For simple examples, I agree that outer is simpler and cleaner.  For larger
> blocks of code with more complex structure the use of outer beyond the
> immediately enclosing scope can be much more difficult.  Updating outer<2>
> to outer<3> in all instances that need it when a scope changes could
> theoretically be problematic.  If, however, most code blocks are not that
> large and do not contain much nesting, this is a non-issue.  How large and
> complex do you expect lazy code blocks?  If they don't reach much beyond
> your example then I'd be fine going with outer.

Beyond a certain limit, an inlined anonymous function will tend to
obscure the code that I would prefer writing it as a regular
function/functor. I am not sure what that limit is. I'm quite confident
though that this limit is far above the point where the problems
you mentioned become real issues.

In any case, the "outer" solution is orthogonal to the absolute-argument
solution anyway. We can implement "outer" now, and, add the absolute-
argument mechanism later, once we find a better syntax.

Cheers,
-- 
Joel de Guzman
http://www.boost-consulting.com
http://spirit.sf.net