# New Ticket Created by  Sam S. 
# Please include the string:  [perl #132219]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=132219 >


When backtracking is disabled for an alternation (via `:` modifier or 
`:ratchet` mode), this obviously means that once the alternation has 
matched once it may no longer reconsider which branch it wants to select:

     say "ab" ~~ / [ab || a ]: b /;  # Nil

But does it also mean that once the alternation has matched, the 
selected branch *itself* may no longer do any backtracking?

I would have thought so, but Rakudo's current behavior is inconsistent:

     say "ab" ~~ / [ .+ | x ]: b /;   # Nil
     say "ab" ~~ / [ .+ || x ]: b /;  # Nil

     say "ab" ~~ / [ x | .+ ]: b /;   # Nil
     say "ab" ~~ / [ x || .+ ]: b /;  # 「ab」

I.e. in most cases, it commits to what the alternation matched the first 
time. But when

1) it is an `||` alternation,
2) and its *last* branch matched,
3) and said branch is a backtrackable atom which (unlike the alternation 
itself) is not affected by `:ratchet`,

then it looks like that backtrackable atom can reconsider what it wants 
to match even after the regex execution has moved past the alternation.

I suppose another way to phrase the @LARRY design question is this: Does 
an alternation select a particular match value (like a "function"), or 
does it select a subregex (like a "macro")?

(PS: I should note that the backtracking behaviors of || and | were even 
less consistent before my NQP commit 263257a9c¹ [see RT #130117²], which 
was supposed to bring `||` in line. But I didn't discover this edge case 
until now, and indeed am not sure how to fix it no matter which way it 
*should* be fixed.)

---
[1] https://github.com/perl6/nqp/commit/263257a9c
[2] https://rt.perl.org/Ticket/Display.html?id=130117

---
This is Rakudo version 2017.09-203-g98fae3d84 built on MoarVM version 
2017.09.1-553-ga4fef0bd
implementing Perl 6.c.

Reply via email to