Boost logo

Boost :

Subject: Re: [boost] Rave for proposed Boost.Local (functions)
From: Joel de Guzman (joel_at_[hidden])
Date: 2011-02-05 15:35:25

On 2/6/11 1:03 AM, Lorenzo Caminiti wrote:
> On Wed, Feb 2, 2011 at 2:00 AM, Thomas Heller

>> As far is a am concerned, I still find this syntax overly verbose.
>> I do realize though that this is just a toy example. For better comparison,
>> Here is how the same thing would like in Boost.Phoenix:
>> boost::function<void(double)> add
>> =(
>> ref(sum) += factor * _1,
>> std::clog<< var("Summed: ")<< sum<< std::endl
>> )
>> ;
>> add(100.0);
> Can you make factor constant within add() body using Boost.Phoenix? If


[snip irrelevant text]

> Maybe this use case is not very interesting to other people but it was
> important for me.
>> Despite the Local Blocks and Local Exits feature, I can't see much
>> difference to the already existing lambda libraries.
>> I just looked through the Boost.Local documentation and immediately
>> navigated to the "Alternatives" section and its not really correct regarding
>> the features of Boost.Lambda and Boost.Phoenix. I am specifically talking
>> about the "Bind variables in scope" and "Program body using usual C++
> The Alternatives section is based on this previous Boost discussion
> .
> I also think it is not a complete comparison. For example, I wanted to
> add the add() example -- add add() ;) -- reworked in Boost.Phoenix,
> Boost.Lambda, C++0x lambdas, and C++ local classes but I didn't have
> time yet... Thanks a lot of the above code in Boost.Phoenix, I'll add
> it to Boost.Local doc :)
>> syntax" part. The last is debatable, but how are the above examples (both of
>> Boost.Local and Boost.Phoenix) not C++ syntax?
>> Can you highlight the advantages/disadvantages again?
> Yes, this is debatable and at the end it's of course all C++. But the
> Boost.Local function body defined within `{ ... }` it's the normal C++
> syntax for function definitions. For example, Boost.Phoenix uses `,`
> where C++ and Boost.Local use `;` to terminate and instruction,
> Boost.Phoenix uses `var("Summed:")` where C++ and Boost.Local use
> `"Summed:"`, etc.
> Plus, how would local variables and local classes look in
> Boost.Pheenix? In Boost.Local it's like in normal C++:
> (void) (add)(
> (double)(num)
> (const bind)((factor))
> (bind)((&sum))
> )
> ) {
> const std::string msg = "Summed: "; // A const local var.
> struct text { std::string say; } // A local struct.
> test t; // A local var.
> t.say = msg;
> sum += factor * num;
> std::clog<< t.say<< sum<< std::endl;
> add(100.0);
> How would this look in Boost.Phoenix? I wish I knew Phoenix better :)
> so I could provide the answers myself...

Look, let us please stop this syntax nonsense. As mentioned,
phoenix can have all those above (pure c++ function syntax,
local classes, local variables, etc.) in the form of offline
phoenix::function. Why offline? I argue, and I am sure many
agree, that overly complex inlined lambdas add clutter to the
enclosing function. Local function emulation is at best a poor
rendition of what it should be anyway (e.g. like Pascal's local
function) since it doesn't have direct access to the enclosing
scope and thus have to resort to argument binding and some such
and add *A LOT* of clutter.

At any rate, I repeatedly say: I am not against Boost.Local. As I
said, in as much as we have BOOST_FOREACH and std::bind, I see no
reason why we can't have Boost.Local.


Joel de Guzman

Boost list run by bdawes at, gregod at, cpdaniel at, john at