# New Ticket Created by Elizabeth Mattijsen # Please include the string: [perl #129945] # in the subject line of all future correspondence about this issue. # <URL: https://rt.perl.org/Ticket/Display.html?id=129945 >
After a discussion with TimToady at: https://irclog.perlgeek.de/perl6-dev/2016-10-22#i_13448934 which follows my question/rant at: https://irclog.perlgeek.de/perl6-dev/2016-10-22#i_13447516 one can argue that the current caching behaviour of :nth in Str.match is faulty. This faulty behaviour is however tested for in roast. So what is the new behaviour in short: - :nth doesn’t cache, but is fully lazy - :nth(N) gives the Nth match, or Nil if there isn’t an Nth match - :nth(*|Inf) gives the last match, or Nil if there aren’t any matches - :nth(anything that can do .iterator) gives a list of matches on the proviso that the numeric values of the iterator are monotonically increasing: any deviance from this is an exception (as is starting from 0, which is not monotonically increasing from the 1st match). - :st, :nd, :rd, :th continue to be synonyms for :nth - :x keeps its caching behaviour, and can be used in combination with :nth. Examples: $ 6 'say "abc".match(/./,:nth(2,3,4))' (「b」 「c」) $ 6 'say "abc".match(/./,:nth(2,4,3))’ (「b」) # seeing index #4 stops iteration, as there is no 4th match $ 6 'say "abc".match(/./,:nth(3,2,1))' Attempt to fetch match #2 after #3 $ 6 'say "abcdefghi".match(/./,:nth(1,3...*))' (「a」 「c」 「e」 「g」 「i」) $ 6 'say "abcdefghi".match(/./,:nth(1,3...*), :3x)' (「a」 「c」 「e」) $ 6 'say "abcdefghi".match(/./,:nth(1,3...*), :6x)' () # don’t have 6 matches coming from the :nth specification This ticket is made to refer to when making changes to rakudo and roast.