Subject: RE: phoenix lambda-lambda for_each example
From: "Noah Stein" <[email-masked]>
To: "Joel de Guzman" <[email-masked]>, "Aleksey Gurtovoy" <[email-masked]>
Cc: "David Abrahams" <[email-masked]>, <[email-masked]>, "Jaakko Jarvi" <[email-masked]>
Date: Wed, 3 Mar 2004 00:23:30 -0800

> 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 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?  Is there some kind of method that can
be used to only mark those items that need to be accessed across scopes?
Something along the lines of one of the following:

    for_each(arg1, push_back(seq, arg1) )(v1,seq(v2));
    for_each(arg1, push_back(seq, arg1) )(v1,seq=v2);

It might not be possible to get the above syntax to work.  I think there
might be a convoluted method to get it to work that doesn't require run-time
overhead.  Unfortunately it would dramatically complicate the
behind-the-scenes code.

-- Noah