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

Aleksey Gurtovoy <[email-masked]> writes:

> Noah Stein writes:
>>> From: Joel de Guzman [mailto:[email-masked]]
>>
>>> I encountered this problem with phoenix's local vars too.
>>> The solution I had was to use outer(arg1) to refer to the
>>> outer scope:
>>>
>>>      for_each(arg1, push_back(outer(arg2), arg1) )( v1, v2 );
>>>
>>> I am also contemplating on incorporating FC++ style scopes
>>> as an optional scheme:
>>>
>>>      lambda(seq)
>>>      [
>>>          for_each(seq,
>>>              lambda(elem)
>>>              [
>>>                  push_back(seq, elem)
>>>              ]
>>>          )
>>>      ]
>>>      (v1, v2);
>>>
>>> but I find it too noisy for my taste ;-) Comments?

I prefer the explicit and readable to the cryptic.

         lambda(seq)
         [
              for_each(seq, push_back(seq, arg1) )
         ]

Isn't too bad.

>> I find it a bit noisy, too; however, is there any other solution
>> that solves a 3-layer (or greater) set of scopes?  Does outer refer
>> to the immediately preceding scope or the topmost scope?
>
> FWIW, I'd expect/implement it to refer to the immediately preceding
> scope, and support the nested usage like 'outer(outer(arg#))' for the
> case of multiply-nested scopes.

Ugly :(

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com