Boost logo

Boost :

Subject: Re: [boost] phoenix::bind
From: Peter Dimov (pdimov_at_[hidden])
Date: 2008-10-02 11:50:57


Joel de Guzman:

> std::cout << "Double Square of " << 5 << " is " <<
> ffx(lambda[sqr(_1)], 5.0)()
> << std::endl;

This is not quite what I was after. As I understood your original problem,
we are looking for a construct lflx such that:

    lflx( f )

yields a function ffx such that

    ffx( x )

yields f( f( x ) ).

In other words, we want

    lflx( sqr )( 5.0 ) to give us sqr(sqr(5.0)).

(The case where f and x are given at the same time is so easy that even
boost::bind can do it.)

I was also trying to express this double lambda lflx as a Phoenix
expression:

    auto lflx = <phoenix expression here>;

My original attempt:

    lambda( _f = _1 )[ bind( _f, bind( _f, _1 ) ) ]

made sense to me, and I still don't understand why it doesn't work.

Maybe if we start from something simpler I'd be able to find my error. What
is the Phoenix way to take a binary function f( x, y ) and construct an
unary function lxly for which lxly( x ) returns a unary function ly such
that ly( y ) returns f( x, y )? (Classic curry, in other words.) I'd have
expected

    lambda( _x = _1 )[ bind( f, _x, _1 ) ]


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk