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 )

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 ...

-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/OIXN : raster images and RImageJ
|- http://tr.im/OcQe : Rcpp 0.7.7
`- http://tr.im/O1wO : highlight 0.1-5



_______________________________________________
Rcpp-devel mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to