|
Boost : |
Subject: Re: [boost] phoenix::bind
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-10-02 19:52:05
AMDG
Joel de Guzman wrote:
> Yep. Phoenix can do that. A local variable may hide an outer local
> variable. Here, we just reuse the locals for arguments to the
> lambda as well. So, in current terms, this:
>
> lambda( _x, _y )[ _x + _y ]
>
> is just this:
>
> lambda( _x = _1, _y = _2 )[ _x + _y ]
Am I misunderstanding something? I thought that this would give
lambda( _x = _1, _y = _2 )[ _x + _y ] (1, 2)() == 3
instead of
lambda( _x = _1, _y = _2 )[ _x + _y ] ()(1, 2) == 3
> Very cool suggestion, Peter!
I don't think it is quite the same if you use an arbitrary expression
instead of _x + _y. For instance, what should this mean:
lambda(_x, _y) [ _x + _y + _1 ]
I'm inclined to think that _1, &c. should be reserved for the top level
placeholders.
This allows each placeholder to have a unique meaning in the full lambda
expression,
rather than having different placeholders refer to the same object and
having the
same placeholder refer to multiple objects.
lambda(_o = _1) [ let(_x = _1, _y = _2) [ _x + _y + _o ] ]
In Christ,
Steven Watanabe
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk