develooper Front page | perl.perl6.users | Postings from September 2019

Re: List in regexp

Thread Previous | Thread Next
From:
The Sidhekin
Date:
September 3, 2019 12:10
Subject:
Re: List in regexp
Message ID:
CAHAeAG6UCfq98DXEZ-Fsp=KRtau6=tXq_z3PtoT5XEshGTKN+w@mail.gmail.com
On Tue, Sep 3, 2019 at 8:37 AM yary <not.com@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

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About