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