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 09:16:11 +0800

Noah Stein wrote:
>>From: Joel de Guzman [mailto:[email-masked]]
> 
> 
>>Sent: Wednesday, March 03, 2004 7:43 AM
>>To: David Abrahams
>>Cc: Aleksey Gurtovoy; Noah Stein; Jaakko Jarvi
>>Subject: Re: phoenix lambda-lambda for_each example
> 
> 
>>How about a compromise:
>>
>>     for_each[seq](seq, push_back(seq, arg1))
>>
>>But hey! We can probably have absolute place-holders
>>and scope-relative place-holders at the same time:
>>
>>     for_each(seq, push_back(seq, arg1))
>>
>>where seq is an absolute place-holder referring to the
>>outermost scope where it is first seen and arg1 is a
>>scope-relative place-holder (as usual).
>>
>><<< Perhaps that's what Noah meant. Hmmm... Now,
>>I wonder how difficult it would be to implement that. >>>
> 
> 
> This is essentially what I was talking about.  Your scheme would be much,
> much easier to implement than my suggestion.  I would like to see if we're
> on the same page.  In my plan, seq would be a place holder object (similar
> to say an argument<> object) that would become an identifier for binding
> when placed in the brackets.  How would you propose handling the binding of
> only a second parameter?  I don't think that matters for the STL algorithms,
> but I could imagine it might for a general case.

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.

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