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

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

Thread Next
William Michels via perl6-users
October 8, 2019 07:53
Match operator: error with any() junction and user-defined $_ topicvariable
Message ID:

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 ( :

mbook:~ homedir$ perl6
To exit type 'exit' or '^D'
> $_ = 'Hamadryas';
> my @genus = < Hamadryas Sostrata Junonia >;
[Hamadryas Sostrata Junonia]
> say $_.WHAT, $/.WHAT;
> if @genus ~~ m/Hama/ { put "Matches at least one"; };
Matches at least one
> say $_.WHAT, $/.WHAT;
> say m/Hama/;
> say m/Hama/;
> say $_.WHAT, $/.WHAT;
> if any(@genus) ~~ m/Hama/ { put "Matches at least one again"; };
Matches at least one again
> say $_.WHAT, $/.WHAT;
> 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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About