Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Str.match(/./, :nth()) shouldn't cache #5767

Open
p6rt opened this issue Oct 23, 2016 · 1 comment
Open

Str.match(/./, :nth()) shouldn't cache #5767

p6rt opened this issue Oct 23, 2016 · 1 comment

Comments

@p6rt
Copy link

p6rt commented Oct 23, 2016

Migrated from rt.perl.org#129945 (status was 'new')

Searchable as RT129945$

@p6rt
Copy link
Author

p6rt commented Oct 23, 2016

From @lizmat

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant