It has the deceivingly simple code:
method match(Any:U: |) { self.Str; nqp::getlexcaller('$/') = Nil }
However, this is the behavior it has:
(^3).match(1) # OUTPUT: «「1」»
So far, so good.
say (1,3 ... * ).match(77); # OUTPUT: «Nil»
Ooookey. What's happenning now?
say (1,3 ... * ).match(1); # OUTPUT: «Nil»
say (1,3 ... * ).match(/\d/); # OUTPUT: «Nil»
Does not like sequences.
say (^10).match(/\d/); # OUTPUT: «「0」»
OK, makes sense again.
say <a b c>.match(/\w/); # OUTPUT: «「a」»
Back to normal. So is it that it does not like Seqs? I assume, because I've looked at the other classes' code and match is not reimplemented, all of them are calling that code. But I fail to see how returning a string and setting a variable from NPQ does that, or why it does not work on sequences.
.matchis a search for a needle in a single haystack string. An infinite sequence stringifies to'...'.How I worked this out
First, you're looking at the wrong method definition:
Any:Uis kinda likeAny $ where not .definedexcept if it matched you would get the error message "Parameter '<anon>' of routine 'match' must be a type object of type 'Any', not an object instance ...".But you're passing a defined
Seq. So your.matchcalls don't dispatch to the method definition you're looking at.To find out what a method dispatches to, use:
A defined
Seqwill thus dispatch to theCoolcode:So, next:
And the code:
So check:
Bingo.
And confirm: