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

Joel de Guzman writes:
> > OK, 'copy' is not very interesting then. Hopefully this one
> > demonstrates my question better:
> >
> >     for_each( v1, push_back(arg1, arg1) )( v2 ); // works?
> >     for_each( arg1, push_back(arg2, arg1) )( v1, v2 ); // doesn't,
right?
> >
> > Actually, the latter is not achievable even with explicit scoping, so
> > I guess it's not the question of explicit vs. implicit scopes, but
> > rather how to override the default behavior.
>
> 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 );

That's exactly the scheme I was thinking of, too (including the name!).

> 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 ;-)

Considering that you'd also have to declare 'seq' and 'elem', yes, IMO it's
not worth the trouble, from both user and implementor POVs. I'd rather spent
time on writing a core language proposal for anonymous functions ;).

--
Aleksey Gurtovoy
MetaCommunications Engineering