On Tue, Sep 3, 2019 at 8:37 AM yary <not....@gmail.com> wrote:

> 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).
>
>
> Which brings up another area for improvement- maybe. A regexp interprets a
> list as alternation only when it's a literal quoted list < like this >, or
> embedded in the regexp as a @-sigilled variable.
>
> That set up an expectation for me- "oh a list in a regexp becomes an
> alternation of the list elements" - but interpolation meets that
> expectation inconsistently.
>
> The interpolation doc section states, for both forms of code interpolation
> $(code) and <{code}>, "Runs Perl 6 code inside the regex, and interpolates
> the stringified return value..."
>

  I missed this the first time (or I would have suggested a version without
the variable), but I think what you want is interpolation by way of @(code).

  eirik@greencat[14:04:06]~$ perl6
You may want to `zef install Readline` or `zef install Linenoise` or use
rlwrap for a line editor

To exit type 'exit' or '^D'
> my $comma-separated='abc,<digit>+';
abc,<digit>+
> say 'abc' ~~ / @( $comma-separated.split(',') ) /;
「abc」
> eirik@greencat[14:05:48]~$

  I'd argue it's better this way, since syntax has me expecting $(...) to
interpolate a scalar (even if produced from a list), and @(…) to
interpolate a list.


Eirik

Reply via email to