develooper Front page | perl.perl6.language | Postings from March 2005

Re: Adding linear interpolation to an array

Thread Previous | Thread Next
From:
Aldo Calpini
Date:
March 7, 2005 13:48
Subject:
Re: Adding linear interpolation to an array
Message ID:
422CCC0B.3070502@perl.it
Dave Whipp wrote:
> Does defining the invocant as "Num @self is constant" constrain the application 
 > of the role to read-only uses of indices?

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

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.

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


cheers,
Aldo

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About