Aldo Calpini wrote: > I don't think you need "is constant". arguments are readonly by default, > unless you give them the "is rw" trait. I guess that "is constant" means > that you can specify the index only using a literal, not a variable, eg: > > @test[1]; # ok, 1 is a costant > my $idx = 1; > @test[$idx]; # nok, $idx is not a constant What I was trying to do is to prevent using fractional indices in lvalue context. I.e. my role wouldn't be considered for "@x[0.5] = 2". > but I may be wrong. > >> Does the explicit indexing by an "int" typed value ensure that it'll >> be non-recursive under MMD? > > > you mean "Num" typed value? if so, I guess using an explicitly > non-integer index would make it win under MMD. on the other hand, your > method could even not be called at all with an integer index. That's what I'm hoping. Because my code does integer indexing, and I wouldn't want it to call itself. I guess could be explicit: $value = @self.Array::postcircumfix«[]»($index); >> If I later decare a sub as >> >> sub foo ( @in does LinearInterpolation ) { ... } >> >> Would I be able to pass a normal (non-interpolating) array to this >> sub, and then access it using non-integer indices (i.e. is the data in >> the array independent of the interface through wich it is accessed). > > > I don't think so. I'm afraid you have to do something like: > > sub foo (@in) { > my @_in = @in; > if(! @in.does(LinearInterpolation) ) { > @_in does LinearInterpolation; > } > # go ahead using @_in > ... > } I don't see why I need the conditional there. If I'm going to copy the array, I might as well declare up front the that darget does LinearInterpolation: sub foo (Num @raw_in) { my Num @in does LinearInterpolation = @raw_in; ... } Or perhaps even sub foo (Num @in is copy does LinearInterpolation) { ... } Dave.Thread Previous | Thread Next