[lambda] Does Boost.Lambda support local variables?

If so, can anyone point me at the relevant bit of documentation. If not, are there some 'standard' techniques to produce a similar effect? Many Thanks, Rob.

On Jan 12, 2009, at 4:50 AM, Robert Jones wrote:
If so, can anyone point me at the relevant bit of documentation.
If not, are there some 'standard' techniques to produce a similar effect?
Phoenix has "let" http://spirit.sourceforge.net/dl_docs/phoenix-2/libs/spirit/phoenix/doc/html...

On Tue, Jan 13, 2009 at 5:11 AM, Gordon Woodhull
On Jan 12, 2009, at 4:50 AM, Robert Jones wrote:
If so, can anyone point me at the relevant bit of documentation.
If not, are there some 'standard' techniques to produce a similar effect?
Phoenix has "let"
http://spirit.sourceforge.net/dl_docs/phoenix-2/libs/spirit/phoenix/doc/html...
Thanks Gordon. I keep bumping into things for which the answer is Phoenix, which I guess is why it's replacing Lambda. It's a bit of a bind tho' (no pun intended!), having just got to a point of working familiarity with Lambda, I'll have to go through it all again with Phoenix! Regards, Rob.

Robert Jones wrote:
I keep bumping into things for which the answer is Phoenix, which I guess is why it's replacing Lambda. It's a bit of a bind tho' (no pun intended!), having just got to a point of working familiarity with Lambda, I'll have to go through it all again with Phoenix!
You do not have to go through it all again. Your investment in learning Lambda will go a long way. Phoenix is not that different from Lambda. Regards, -- Joel de Guzman http://www.boostpro.com http://spirit.sf.net

On Tue, Jan 13, 2009 at 1:08 PM, Joel de Guzman
Robert Jones wrote:
I keep bumping into things for which the answer is Phoenix, which I guess is why it's replacing Lambda. It's a bit of a bind tho' (no pun intended!), having just got to a point of working familiarity with Lambda, I'll have to go through it all again with Phoenix!
You do not have to go through it all again. Your investment in learning Lambda will go a long way. Phoenix is not that different from Lambda.
Thanks Joel, that's good to know. What is the status of Phoenix btw, will it be a top tier library in 1.38? Rob.

Robert Jones:
If not, are there some 'standard' techniques to produce a similar effect?
You can achieve something similar by using a combination of boost::bind and Lambda, but it's not 'standard' by any means. :-) Do you have a specific example?

On Tue, Jan 13, 2009 at 12:54 PM, Peter Dimov
Robert Jones:
If not, are there some 'standard' techniques to produce a similar effect?
You can achieve something similar by using a combination of boost::bind and Lambda, but it's not 'standard' by any means. :-) Do you have a specific example?
Hi Peter This is a bit trivial, but it broadly illustrates the point int a[10][10]; int min=1, max=20; boost::function< int(size_t,size_t) > element = (var)[_1][_2]; boost::function< bool(size_t, size_t) > exceeds_range = bind( element,_1, _2) > max || bind( element,_1,_2) < min; I'm not sure I've written that quite right, whether I need all those binds, but the gist of if is that without local variables I seem to have invoke element() twice. I guess I could write something like boost::function< bool( int ) > exceed_detail = _1 > max || _1 < min; boost::function< bool( size_t, size_t ) > exceeds_range = bind( exceeds_detail, bind( element, _1, _2 ) ); but it seems to introduce additional arbitrary artifacts which is not ideal, and obscures the logic to my mind. Thanks, Rob.

Robert Jones:
I guess I could write something like
boost::function< bool( int ) > exceed_detail = _1 > max || _1 < min; boost::function< bool( size_t, size_t ) > exceeds_range = bind( exceeds_detail, bind( element, _1, _2 ) );
but it seems to introduce additional arbitrary artifacts which is not ideal, and obscures the logic to my mind.
I admit that the workarounds aren't pretty. In this case you could've written exceeds_range = bind( protect( _1 > max || _1 < min ), bind( element, _1, _2 ) ); The protect is needed because lambda::bind evaluates its first argument (boost::bind does not). In general you can introduce a local _3 via: exceeds_range_impl = ( _3 = bind( element, _1, _2 ), _3 > max || _3 < min ); exceeds_range = boost::bind( exceeds_range_impl, _1, _2, 0 ); but... one'd rather write the function by hand and be done with it. :-)
participants (4)
-
Gordon Woodhull
-
Joel de Guzman
-
Peter Dimov
-
Robert Jones