Markus Laire wrote:
What should index("Hello", "", 999) return in perl6?

Since the first thing that needs definition is how does the empty string match, it could be e.g. any(0.."Hello".elems).

As described in A12 string positions are much more these days
than simple ints. There is a class StrPosition or Pos[Str]
or Pos of Str or some such. So one signature could be:

multi sub index( Str       $searched,
                 Str       $substr,
                 Pos[Str] ?$pos where { 0 <= $_ < $searched.elems }
               )
  returns  Undef[Pos[Str]]
         ^ Pos[Str] where { 0 <= $_ < $searched.elems }
{
  ...
}



In perl5 that returns 5, but IMHO -1 would be right result.

This is because of the usage of "". Otherwise it's -1.


Regards, -- TSa (Thomas Sandlaß)




Reply via email to