>
> 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..."

What I would like it to say and do is "Runs Perl 6 code inside the regex,
and *for each returned value as an alternation* interpolates the
stringified item..."

What 6.d Rakudo 2019.03 shows me, is adherence to the docs for $(code), and
fulfilling my wishes for <{code}>

$ perl6 --version
*This is Rakudo Star version 2019.03.1 built on MoarVM version 2019.03*
*implementing Perl 6.d.*
$ perl6
To exit type 'exit' or '^D'
> my $comma-separated='abc,<digit>+';
abc,<digit>+

*# Let's see how $( code ) behaves with a list return*
> say 'abc' ~~ / $( $comma-separated.split(',') ) /;
Nil
> say 'how about "abc <digit>+"?' ~~ / $( $comma-separated.split(',') ) /;
「abc <digit>+」
> my $as-string = $comma-separated.split(',').Str
abc <digit>+
> say 'how about "abc <digit>+"?' ~~ / $as-string /
「abc <digit>+」
*# $( code ) stringifies to space-separated string, matches literally*

*# Let's see how <{ code }> behaves with a list return*
> say 'abc' ~~ / <{ $comma-separated.split(',') }> /
「abc」
> say '808' ~~ / <{ $comma-separated.split(',') }> /
「808」
> say 'how about "abc 8+"?' ~~ / <{ $comma-separated.split(',') }> /
「abc」
> say 'how about "abc 8+"?' ~~ / <$as-string> /
Nil
*# <{ code }> treats list as alternation, each item as regexp*

In other words, I want the behavior of <{ code }> with lists documented,
and then I want $( code ) to act similarly.

Git issue to follow, pending any discussion here...

-y

Reply via email to