Subject: Re: phoenix lambda-lambda for_each example
From: Joel de Guzman <[email-masked]>
To: David Abrahams <[email-masked]>
Cc: Noah Stein <[email-masked]>, Aleksey Gurtovoy <[email-masked]>, Jaakko Jarvi <[email-masked]>
Date: Fri, 05 Mar 2004 00:00:51 +0800

David Abrahams wrote:
> Joel de Guzman <[email-masked]> writes:

>>1) You'll have to declare the place-holders.
> 
> 
> Consider this, which I believe can be made to work:
> 
>        for_each[_2, _3](_2, push_back(_1, _3))
> 
> You may shriek with horror, but I think it's not so terrible.  It does
> indicate that we may not need a separate absolute_argument type.  I
> think the placement of the []s is strange, though.
> 
> 
>>2) The syntax does not look like a c++ function call.
> 
> 
> Not a problem, IMO.
> 
>     lambda(x,y)[ for_each(x, push_back(_1, y)) ]
> 
> is much better though.

MPL got me convinced that familiar syntax is an important factor.
There was a time when I was not convinced MPL should follow
the STL conventions since it is in a purely functional domain.
I thought that borrowing the look and feel of an FP language
such as Haskell was the right way to go. You guys made me a
convert.

Now, I am carrying on with that belief. The tide has turned and
I see now that FC++'s look and feel as alien and so detached from
the C++ syntax. I believe that one reason for MPL's success is it's
instant familiarity. As much as posible, I would like to use
a syntax that would give the user an almost instant "aha!".

So, here's a refinement to my proposal:

* All arguments on parameter slots expecting a function object
will be interpreted as scoped lambdas. (implicit scoping)

* Let the usual _1 ... _10 place holders retain its current
meaning. It's scope will always be the outermost scope of a
lambda expression.

* Introduce a new set of placeholders _a ... _j. The scope of
these place-holders will be the innermost lambda where it
is found.

Here again is our sample. I want to push_back argument _2 to all
sequences in argument _1:

     for_each(_a, push_back(_a, _2))

Notice that the leftmost _a can be replaced by _1 but
the second _a cannot.

I believe this is the best syntax so far. With this scheme,
there might be no need for "outer" anymore. The only drawback
is that we cannot refer to some arguments in middle scopes. I
am not sure if that's a problem. If it is, we can still re-
introduce it, after all, the presence of _N in inner scopes
will implicitly use it anyway.

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