HaloO,

David Green wrote:
Also, this would solve a problem I've been wondering about with "funny" shapes being lexically scoped. [..]
However, what if you pass the funny array along with a (funny) index?
E.g. our @flavours (1..32);
my $favourite = get_fave(@flavours); #returns index of selected flavour
     warn "Sorry, all out of @flavours[$favourite]!"
                                unless in_stock(@flavours, $favourite);

Which means that you'd be checking for the wrong thing to be in stock. (Actually, you'd also get the wrong index back from get_fave(), so in this limited example, the two errors would probably cancel each other out, but the warning message will print the wrong flavour because it's using the shifted index.)

It's interesting to get the signature for this &get_fave routine.
As stated it should be :(@a --> Int where {$_ ~~ @[EMAIL PROTECTED]).
The implementation of &get_favo has to be generic with respect to
the array shape otherwise a type error occurs when e.g. the shape
is (-5..-1) and the body of &get_favo is coded in terms of (0..4).

And I wonder how this generic index handling can be done by means
of * dwimmery along the lines of

  sub get_favo (@a --> Int where {$_ ~~ @[EMAIL PROTECTED])
  {
     my $idx = *+0; # how is this connected to @a?

     while check_favo(@a[$idx]) and $idx < *-0 # same as @a.end?
     {
         $idx++;
     }
     return $idx;
  }

BTW, is the where clause in the signature still seeing the outside
shape? Or does one have to say something like @a.OUTER::begin to
get at it because the @a of the sub always has got shape ([EMAIL PROTECTED])?


Regards, TSa.
--

Reply via email to