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

Match operator: error with any() junction and user-defined $_ topicvariable

Thread Next
From:
William Michels via perl6-users
Date:
October 8, 2019 07:53
Subject:
Match operator: error with any() junction and user-defined $_ topicvariable
Message ID:
CAA99HCy30sfFYj6aqHeNRnZNnz6DJhMZRhO+N+P_5xYe+c_RYw@mail.gmail.com
Greetings:

I tried the following regular expression code, working generally from
"Learning Perl 6" by brian d foy (Chapter 15). Everything works fine
including the any() junction below, as long as the topic $_ variable
isn't defined beforehand. However specifically in combination with a
user-defined $_ topic variable, an any() junction returns the error,
"Cannot modify an immutable Match." See Perl6 REPL code below (also
checked with 6Pad (https://perl6.github.io/6pad/)) :

mbook:~ homedir$ perl6
To exit type 'exit' or '^D'
> $_ = 'Hamadryas';
Hamadryas
> my @genus = < Hamadryas Sostrata Junonia >;
[Hamadryas Sostrata Junonia]
> say $_.WHAT, $/.WHAT;
(Str)Nil
> if @genus ~~ m/Hama/ { put "Matches at least one"; };
Matches at least one
> say $_.WHAT, $/.WHAT;
(Str)(Match)
> say m/Hama/;
「Hama」
> say m/Hama/;
「Hama」
> say $_.WHAT, $/.WHAT;
(Str)(Match)
> if any(@genus) ~~ m/Hama/ { put "Matches at least one again"; };
Matches at least one again
> say $_.WHAT, $/.WHAT;
(Str)(Junction)
> say m/Hama/;
Cannot modify an immutable Match (「Hama」)
  in block <unit> at <unknown file> line 1

> say $*VM
moar (2019.07.1)
>

I understood from the "Learning Perl 6" book that the two smart-match
lines of code are equivalent--the first one simply understands that
there is an 'implied' any() junction to check the array against the
match operator. But REPL reports back that in one case $/ returns a
match object type, while in the other case [with an explicit any()
junction], $/ returns a junction object type. So this feels
inconsistent, at the very least.

Any explanation appreciated. If after triaging this issue, someone
would like me to open a Github issue, please point me towards the
correct repository.

Thanks, Bill.

W. Michels, Ph.D.

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