Boost logo

Boost :

Subject: Re: [boost] Rave for proposed Boost.Local (functions)
From: Gregory Crosswhite (gcross_at_[hidden])
Date: 2011-02-25 14:10:00


I converted all of my code to use the Sequencing Macro Syntax, and then
after that I converted it all to the Variadic Macro Syntax. The process
was completely painless and took probably about 10-15 minutes total for
each conversion. It is always satisfying when one gets to make heavy
use of the backspace key to eliminate now-unneeded code. :-)

I think that you've got a good compromise with supporting both legacy
C++ compilers with the sequencing syntax and C99 compilers with the
variadic syntax; the variadic syntax is a little nicer, but the
sequencing syntax feels just fine to use as well. (I am impressed that
you managed to work a way so that the same macro can accept both syntaxes!)

The one part that has become slightly more verbose is where I had
multiple variables that I was binding, since now I need to retype "const
bind" for each variable rather than supplying them as a list (unless I
am misunderstanding something). I think that is a fair trade-off,
though, since the nested list inside the const bind used in the old
syntax feels a bit unnatural unless you are used to preprocessor
metaprogramming; it took me a while of peering at the documentation to
realize that my mistake was that I needed two layers of parentheses
instead of one to bind a variable (that is "(const bind)((x))" instead
of "(const bind)(x)"), and even after I got used to the syntax (and
understood why you did it that way) my most common mistake was to forget
and only use a single layer of parentheses until the compiler yelled at
me. :-)

I would recommend that when you polish up the documentation that you
make sure to include an example of the case where multiple variable are
bound, though, since it is not immediately obvious looking at the
examples how to extrapolate to that case. (Incidentally, you should
definitely update and keep around the Grammar appendix since I found it
incredibly helpful in figuring out exactly how the syntax worked when I
got confused!)

By-the-way, if you want to see how I have been using your code you can
check out my repository from

https://github.com/gcross/CodeSearch

and use grep to see where I've been using your library. I explicitly
logged in the revision history where I changed to use the new sequencing
syntax and the new variadic syntax (which at this time are the two most
recent commits) so you can see the difference in how it looks for yourself.

Cheers,
Greg

On 2/24/11 12:01 PM, Lorenzo Caminiti wrote:
> On Sun, Feb 6, 2011 at 4:02 PM, Dave Abrahams<dave_at_[hidden]> wrote:
>> At Sat, 5 Feb 2011 18:32:06 -0500,
>> Lorenzo Caminiti wrote:
>>> Agreed. I think we discussed the syntax stuff enough.
>> Well, just one thing I'd like to add: it would be a shame if your Boost library
>> doesn't provide alternate macros usable by anyone who is willing to depend on
>> the C99 preprocessor, that take advantage of variadics.
>>
>> BOOST_LOCAL_FUNCTION_(...)
>>
>> anyone?
> Hello all,
>
> I have reworked Boost.Local macro syntax to take advantage of variadics.
>
> The latest code is in the sandbox
> http://svn.boost.org/svn/boost/sandbox/local/. I still have to update
> the docs and polish the code but I would like your early feedback. I
> would also like to hear from people that have used the older syntax so
> they can compare it with the new one.
>
> For example, if variadic macros are supported by your compiler:
>
> #include<boost/local/function.hpp>
> #include<iostream>
>
> int main() {
> double sum = 0.0;
> int factor = 10;
>
> void BOOST_LOCAL_FUNCTION_PARAMS(double num, const bind factor,
> bind& sum) {
> sum += factor * num;
> std::clog<< "Summed: "<< sum<< std::endl;
> } BOOST_LOCAL_FUNCTION_NAME(add)
>
> add(100.0);
> return 0;
> }
>
> In any case, regardless of varidic macros or not, and for all
> compilers, the same macros also support this syntax:
>
> #include<boost/local/function.hpp>
> #include<iostream>
>
> int main() {
> double sum = 0.0;
> int factor = 10;
>
> void BOOST_LOCAL_FUNCTION_PARAMS( (double num) (const bind factor)
> (bind& sum) ) {
> sum += factor * num;
> std::clog<< "Summed: "<< sum<< std::endl;
> } BOOST_LOCAL_FUNCTION_NAME(add)
>
> add(100.0);
> return 0;
> }
>
> The syntax of local exits and blocks also changed accordingly:
> http://svn.boost.org/svn/boost/sandbox/local/libs/local/doc/html/index.html#boost_local.Introduction.an_example
>
> IMO, the new syntax is much simpler and it greatly reduces (and with
> variadics it completely eliminates) the number of extra parenthesis.
> This simplification comes to the cost of generality: The new syntax
> cannot be used as a general syntax to unify the syntax of all macros
> that spoil function declarations but this is not a requirement for
> Boost.Local so this lack of generality is not a problem.
>
> Many thanks for pushing me in improving Boost.Local syntax and for all
> your suggestions!
>


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