Skip Menu |
Report information
Id: 129945
Status: new
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: elizabeth <liz [at] dijkmat.nl>
Cc:
AdminCc:

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)



Date: Sun, 23 Oct 2016 13:22:32 +0200
Subject: Str.match(/./, :nth()) shouldn't cache
To: rakudobug [...] perl.org
From: Elizabeth Mattijsen <liz [...] dijkmat.nl>
Download (untitled) / with headers
text/plain 1.5k
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.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org