romain.francois at dbmail.com
Fri Mar 19 17:05:27 CET 2010
Done. Named is no longer a class but two templated functions. The
interface is 100% preserved, and is extended to simpler vectors.
Not a single line of the unit tests has changed.
This shows that both interfaces can be used with simpler types:
fx <- cfunction( signature(), '
Named( "foo" ) = 20,
Named( "bar", 30 ) ) ;
', Rcpp = TRUE, includes = "using namespace Rcpp;" )
Le 19/03/10 15:35, Romain Francois a écrit :
> Le 19/03/10 15:03, Dirk Eddelbuettel a écrit :
>> On 19 March 2010 at 14:01, Romain Francois wrote:
>> | I've commited Vector<>::create methods to support creation of any kind
>> | of vectors with named or unnamed objects. examples:
>> | // creating an unamed integer vector
>> | IntegerVector::create( 10, 20 ) ;
>> | // creating a named character vector
>> | CharacterVector::create( _["foo"] = "bar", _["bar"] = "foo" ) ;
>> | // creating a named list
>> | List::create( _["foo"] = 10, _["bar"] = true ) ;
>> | The syntax :
>> | _[.] = .
>> | can be replaced by this for people who don't like _ :
>> | Argument( . ) = .
>> | so for example :
>> | List::create( Argument("foo") = 10, Argument("bar") = true ) ;
>> Really nice work!
> It was quite challenging ... but where is the fun otherwise ?
>> | I could not use Named as it is now because it wraps the object too early
>> | and so would only work for lists (which contains SEXP) and would not
>> | work for e.g. integer vectors.
>> | Here the rhs of Argument::operator= is kept as a reference until it is
>> | effectively stored in the object, so Argument::operator= makes an object
>> | of the template class traits::named_object which create knows how to
>> | deal with, but the key is that named_object does not wrap but only
>> | contains reference.
>> | The new question is : should "Argument" be called something else ?
>> | Should I rework all others clients of Named so that they use Argument
>> | instead (in that case I would then call it Named).
>> Tricky one. We'd be altering a published interfaces which is bad, but then
>> the paint is barely on these interfaces. I guess this can be argued either
>> way. What do you think? What do other lurkers thing?
> about this, instead of being a class, we make Named a templated
> function. With this I think we could preserve both syntax:
> Named( "x" ) = 10 ;
> Named( "x", 10 ) ;
> I don't think anyone cares that Named is a class, as it is only
> typically used inside other constructs for its side effect.
> I think this way we would just alter what Named is but keep what it is
> used for intact.
Professional R Enthusiast
+33(0) 6 28 91 30 30
|- http://tr.im/OIXN : raster images and RImageJ
|- http://tr.im/OcQe : Rcpp 0.7.7
`- http://tr.im/O1wO : highlight 0.1-5
More information about the Rcpp-devel