Subject: Re: phoenix lambda-lambda for_each example
From: Joel de Guzman <[email-masked]>
To: Noah Stein <[email-masked]>
Cc: Aleksey Gurtovoy <[email-masked]>, David Abrahams <[email-masked]>, Jaakko Jarvi <[email-masked]>
Date: Wed, 03 Mar 2004 20:44:38 +0800

Noah Stein wrote:

>>From: Joel de Guzman [mailto:[email-masked]]
> 
>>Remember that we do not have control over the invocation
>>(function call) of the lambda. The rightmost parens are
>>not part of the lambda.
> 
> 
> I figured we didn't have that capability currently.  My suggestion was to
> add the functionality to support having the invocation parameters optionally
> support certain the proposed construct.  The need to discriminate between
> "regular" and "scope-bound" parameters is the "convoluted method" I was
> trying to communicate.  I think it's possible functionality.  I'm not
> certain its worth the effort and convolution of the library code.
> 
> I like the thought that the user code could be much cleaner.  The scoping
> mechanism is much less intrusive on user code visually than the lambda
> example.  It is only apparent when used.  I also like that no matter how the
> "topology" of the nested scopes changes, the references never change (unlike
> outer<2> that might need to change to an outer<3>).  And if properly
> implemented, I think it can be done with little to no runtime overhead (in
> release mode).
> 
> Unfortunately, I think it would most likely require a large-scale change
> inside the guts of the system.  I think the change will greatly complicate
> the codebase and be nearly incomprehensible to the average user.  If that
> issue is of great concern (and I know it can be), I support the idea of
> outer<n>.

I guess I didn't communicate my message well. What I am saying is that
we do not have the liberty to impose any syntax tricks outside the
lambda expression. That's simply outside the jurisdiction of the anonymous
function. Consider:

     std::for_each(c.begin(), c.end(),
         phoenix::for_each(arg1, cout << arg1 << ' ')
     );

std::for_each supplies the arguments to our lambda-function. We do not
have control over that. Inside std::for_each, our lambda-function
is invoked:

     f(*i++)

In short, with

     for_each(arg1, push_back(outer(arg2), arg1))(v1, v2);

the (v1, v2) portion is *not* part of the user code.

... Unless, of course, if what you meant was adding another level of
wrapping over the lambda-expression. If that's what you meant, then
it will still have the same problems of the FC++ style scoping
mechanism.

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