[Rcpp-devel] syntactic sugar

Dirk Eddelbuettel edd at debian.org
Mon Mar 1 13:48:11 CET 2010


On 1 March 2010 at 12:20, Romain Francois wrote:
| Hello,
| 
| I'm starting to find the Named construct somewhat too verbose and I'd 
| like to add some syntactic sugar.
| 
| I've commited something just now. I'd like to ear opinions about it.
| 
| The machinery is built around the classes 
| Rcpp::internal::NamedPlaceHolder, Rcpp::internal::NamedPlaceholderProxy 
| and the Rcpp::_ object which is a static instance of NamedPlaceHolder.
| 
| Here is an example :
| 
| require( inline )
| require( Rcpp )
| funx <- cfunction(signature(), '
| 	Language call( "rnorm", _["mean"] = 10 ) ;
| 	return call ;
| ', Rcpp = TRUE, includes = "using namespace Rcpp;"  )
| funx()
| 
| 
| The interesting thing is
| 
|   _["mean"] = 10
| 
| which is the same as Named( "mean", 10 )

On purely stylistic grounds, I dislike it.
 
| There is also the ARG macro in Rcpp.h
| 
| #define ARG(name) ::Rcpp::internal::NamedPlaceholderProxy name(#name) ;
| 
| which allows the syntax :
| 
| funx <- cfunction(signature(), '
| 	ARG(mean)
| 	Language call( "rnorm", mean = 10 ) ;
| 	return call ;
| ', Rcpp = TRUE, includes = "using namespace Rcpp;"  )
| 
| 
| There is the annoying bit of calling the macro, but I suppose an 
| application could have calls to ARG in some header.
| 
| Any ideas ? Suggestions ...

If you feel must give users this rope, the let's do it. 

I mostly try to follow the rule of 'no #defines in C++'. Ie no macros.
Typedefs, sure.  The ARG one is useful so we could make it available but I
would not use it.  There is, it seems based on a quick glance, a way to use
this as 

      typedef ::Rcpp::internal::NamedPlaceholderProxy rcppProxy;

and that would be good enough for me.

But heck, there are only two of us voting here so if it is a tie and you
really want it, go for it.  

Dirk

-- 
  Registration is open for the 2nd International conference R / Finance 2010
  See http://www.RinFinance.com for details, and see you in Chicago in April!


More information about the Rcpp-devel mailing list