>   The "implicit" alternation comes from interpolating a list (of subrules,
> see below).

I see.  And that's discussed here (had to really look for it):

https://docs.perl6.org/language/regexes#Quoted_lists_are_LTM_matches

At first I was looking further down in the "Regex interpolation"
section, where it's also touched on, though I kept missing it:

> When an array variable is interpolated into a regex, the regex engine handles 
> it like a | alternative of the regex elements (see the documentation on 
> embedded lists, above).


On 9/1/19, The Sidhekin <sidhe...@gmail.com> wrote:
> On Mon, Sep 2, 2019 at 1:12 AM Joseph Brenner <doom...@gmail.com> wrote:
>
>> I was just trying to run Simon Proctor's solution, and I see it
>> working for Yary's first case, but not his more complex one with
>> problem characters like brackets included in the list of characters.
>>
>> I don't really see how to fix it, in part because I'm not that
>> clear on what it's actually doing... there's some sort of
>> implicit alternation going on?
>>
>>
>> sub contains( Str $chars, Str $_ ) {
>>   m:g/<{$chars.comb}>+/
>> };
>>
>
>   The "implicit" alternation comes from interpolating a list (of subrules,
> see below).
>
> That works for this case:
>>
>>   say contains('24680', '19584203');
>>   # (「8420」)
>>
>> But on something like this it errors out:
>>
>>   say contains('+\/\]\[', 'Apple ][+//e'); # says ][+//
>>
>
>   … because it's trying to compile each (1-character) string as a subrule …
>
>   To have the (1-character) strings used a literals, rather than compiled
> as subrules, put them in an array instead of a block wrapped in angle
> brackets:
>
> sub contains( Str $chars, Str $_ ) {
>   my @arr = $chars.comb;
>   m:g/@arr+/
> }
>
>
>   (… hey, is there a word for "block wrapped in angle brackets"?)
>
>
> Eirik
>

Reply via email to