Precedence: assignment vs smartmatch? (...was Re: where is my map typo)

Hello All,

Todd put up some interesting code yesterday using the Raku/Perl6 REPL,
which I reproduced with no problem. Additionally I tried some
variations removing and/or moving parentheses to a different location,
and have numbered the relevant REPL lines 1 through 6:

mbook:~ homedir$ perl6
To exit type 'exit' or '^D'
1> my $x =3D Q[word</b><br>] ;
word</b><br>
2> (my $y =3D $x) ~~ s/ '<' .* //; say $/; say $x; say $y;
=EF=BD=A2</b><br>=EF=BD=A3
word</b><br>
word
3> my $a =3D Q[word</b><br>] ;
word</b><br>
4> my $b =3D ($a ~~ s/ '<' .* //); say $/; say $a; say $b;
=EF=BD=A2</b><br>=EF=BD=A3
word
=EF=BD=A2</b><br>=EF=BD=A3
> my $c =3D Q[word</b><br>] ;
word</b><br>
> my $d =3D $c ~~ s/ '<' .* //; say $/; say $c; say $d;
=EF=BD=A2</b><br>=EF=BD=A3
word
=EF=BD=A2</b><br>=EF=BD=A3
7> $*VM
moar (2019.07.1)

Working in groups of 2, lines 1 and 2 replicate the code Todd put up
(parenthesis surrounding everything to the left of the smartmatch
operator). I get the same result as Todd. What interests me are lines
3 through 6. Lines 3 and 4 are the virtually the same code but with
parentheses surrounding everything to the right hand side (RHS) of the
assignment operator (" =3D "). As people will note, lines 2 and lines 4
give different results. Removing parentheses entirely in line 6 gives
the same result as in line 4. Because the results in line 4 and line 6
are the same, this says that as far as parentheses are concerned, the
smartmatch operator "~~" takes precedence over the assignment operator
"=3D".

What's not clear to me in the code above (lines 4 and 6) is why
variables $b and $d get assigned to $/. I would have expected in line
4 that $a would have been matched against the smartmatch, and the
result ("word") would have been simply copied into variable $b. Have I
misunderstood?

Anyway, I'm just hoping to start a conversation on the topic of
precedence in general, and hopefully getting some feedback as to where
to look in the docs for further instruction.

Best Regards, Bill.


On Fri, Dec 6, 2019 at 12:15 AM ToddAndMargo via perl6-users
<perl6-users@perl.org> wrote:
>
> On 2019-12-05 23:19, ToddAndMargo via perl6-users wrote:
> > On 2019-12-05 03:09, William Michels via perl6-users wrote:
> >> What happens when you type "perl6" or "raku" at the bash command promp=
t?
> >
> > Hi William,
> >
> > On my shop machine, it jumps to the next line with an
> > empty flashing cursor
> >
> > On my office machine, it told me to install
> >      zef install Readline
> >
> > After that, I get:
> >
> > $ perl6
> > To exit type 'exit' or '^D'
> >  >
> >
> > and
> >
> >  > say "hello World"
> > hello World
> >  > say "B" ~ Q[:\] ~ " drive dismounted"
> > B:\ drive dismounted
> >  >
> >
> > and sticking an obvious booboo into it
> >
> >  > if 3 % 2 =3D 1 {say "odd"};
> > Cannot modify an immutable Int (1)
> >    in block <unit> at <unknown file> line 1
> >
> > Plus I can use the arrow keys to recall previous lines too.
> >
> > Time up update my Perl6 on my shop computer!
> >
> > No more hassling with `perl6 -e` !!!
> >
> > Dude!  THANK YOU !!!!!!
> >
> > -T
>
> You've created a monster!!
>
> perl6
> To exit type 'exit' or '^D'
>  > my $x =3D Q[</b><br>]
> </b><br>
>  > say $x
> </b><br>
>  > (my $y =3D $x ) ~~ s/ Q[<] .* //;
> =3D=3D=3DSORRY!=3D=3D=3D Error while compiling:
> Unrecognized regex metacharacter < (must be quoted to match literally)
> ------> (my $y =3D $x ) ~~ s/ Q[<] .* //;
>  > my $x =3D Q[abc</b><br>]
> abc</b><br>
>  > (my $y =3D $x ) ~~ s/ '<' .* //;
> =EF=BD=A2</b><br>=EF=BD=A3
>  > (my $y =3D $x ) ~~ s/ '<' .* //; say $y
> abc
>  > (my $y =3D $x ) ~~ s/ '<' .* //; say $x; say $y
> abc</b><br>
> abc
>
>
> Thank you!
>
>
> --
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0
perl6
12/7/2019 4:33:54 AM
perl.perl6.users 1389 articles. 0 followers. Follow

12 Replies
62 Views

Similar Articles

[PageSpeed] 11

On 2019-12-06 20:33, William Michels via perl6-users wrote:
> say $/;

First I have seen of `$/`.  Is it any relation to `$_`?
0
perl6
12/7/2019 5:23:46 AM
Hi Todd, yes in a sense "$/" is related to "$_" in that they're both
variables that get filled with values behind the scenes by Raku/Perl6.
You already know that "$_" is the general default 'topic' variable
(same as in Perl 5, see Ref#1 below).

From Ref#2 below: " $/ is the match variable. It stores the result of
the last Regex match and so usually contains objects of type Match."
Apparently "$/" in Raku/Perl6 has replaced a series of variables that
were used in Perl5, including  "$`", "$&", and "$'" which "are gone
from Raku" (Ref#3 below):

1. https://docs.raku.org/language/5to6-perlvar#$ARG,_$_
2. https://docs.raku.org/syntax/$$SOLIDUS
3. https://docs.raku.org/language/5to6-perlvar#Variables_related_to_regular_expressions

HTH, Bill.


On Fri, Dec 6, 2019 at 9:28 PM ToddAndMargo via perl6-users
<perl6-users@perl.org> wrote:
>
> On 2019-12-06 20:33, William Michels via perl6-users wrote:
> > say $/;
>
> First I have seen of `$/`.  Is it any relation to `$_`?
0
perl6
12/7/2019 6:11:11 AM
>> On Fri, Dec 6, 2019 at 9:28 PM ToddAndMargo via perl6-users
>> <perl6-users@perl.org> wrote:
>>>
>>> On 2019-12-06 20:33, William Michels via perl6-users wrote:
>>>> say $/;
>>>
>>> First I have seen of `$/`.  Is it any relation to `$_`?

On 2019-12-06 22:11, William Michels via perl6-users wrote:
> Hi Todd, yes in a sense "$/" is related to "$_" in that they're both
> variables that get filled with values behind the scenes by Raku/Perl6.
> You already know that "$_" is the general default 'topic' variable
> (same as in Perl 5, see Ref#1 below).
> 
>  From Ref#2 below: " $/ is the match variable. It stores the result of
> the last Regex match and so usually contains objects of type Match."
> Apparently "$/" in Raku/Perl6 has replaced a series of variables that
> were used in Perl5, including  "$`", "$&", and "$'" which "are gone
> from Raku" (Ref#3 below):
> 
> 1. https://docs.raku.org/language/5to6-perlvar#$ARG,_$_
> 2. https://docs.raku.org/syntax/$$SOLIDUS
> 3. https://docs.raku.org/language/5to6-perlvar#Variables_related_to_regular_expressions
> 
> HTH, Bill.

Awesome!  I am going to have fun with this!  I do
A LOT of regex's.

Thank you!
0
perl6
12/7/2019 6:38:54 AM
On 2019-12-06 22:38, ToddAndMargo via perl6-users wrote:
>>> On Fri, Dec 6, 2019 at 9:28 PM ToddAndMargo via perl6-users
>>> <perl6-users@perl.org> wrote:
>>>>
>>>> On 2019-12-06 20:33, William Michels via perl6-users wrote:
>>>>> say $/;
>>>>
>>>> First I have seen of `$/`.=C2=A0 Is it any relation to `$_`?
>=20
> On 2019-12-06 22:11, William Michels via perl6-users wrote:
>> Hi Todd, yes in a sense "$/" is related to "$_" in that they're both
>> variables that get filled with values behind the scenes by Raku/Perl6.=

>> You already know that "$_" is the general default 'topic' variable
>> (same as in Perl 5, see Ref#1 below).
>>
>> =C2=A0From Ref#2 below: " $/ is the match variable. It stores the resu=
lt of
>> the last Regex match and so usually contains objects of type Match."
>> Apparently "$/" in Raku/Perl6 has replaced a series of variables that
>> were used in Perl5, including=C2=A0 "$`", "$&", and "$'" which "are go=
ne
>> from Raku" (Ref#3 below):
>>
>> 1. https://docs.raku.org/language/5to6-perlvar#$ARG,_$_
>> 2. https://docs.raku.org/syntax/$$SOLIDUS
>> 3.=20
>> https://docs.raku.org/language/5to6-perlvar#Variables_related_to_regul=
ar_expressions=20
>>
>>
>> HTH, Bill.
>=20
> Awesome!=C2=A0 I am going to have fun with this!=C2=A0 I do
> A LOT of regex's.
>=20
> Thank you!



Tells me what was matched!  Oh I am going to have a
lot of fun with this!

my $x =3D Q[\:\\::]; ( my $y =3D $x ) ~~ s/ '\\\\' /x/; say $/
=EF=BD=A2\\=EF=BD=A3

my $x =3D Q[abcdef]; ( my $y =3D $x ) ~~ s/ .*? (cd) (e) .* /x/; say $/
=EF=BD=A2abcdef=EF=BD=A3
  0 =3D> =EF=BD=A2cd=EF=BD=A3
  1 =3D> =EF=BD=A2e=EF=BD=A3

my $x =3D Q[abcdef]; ( my $y =3D $x ) ~~ m/ .*? (cd) (e).* /; say $/
=EF=BD=A2abcdef=EF=BD=A3
  0 =3D> =EF=BD=A2cd=EF=BD=A3
  1 =3D> =EF=BD=A2e=EF=BD=A3

my $x =3D Q[abcdef]; ( my $y =3D $x ) ~~ m/ .*? (cd) (e).* /; for $/ {say=
 $_};
=EF=BD=A2abcdef=EF=BD=A3
  0 =3D> =EF=BD=A2cd=EF=BD=A3
  1 =3D> =EF=BD=A2e=EF=BD=A3

my $x =3D Q[abcdef]; ( my $y =3D $x ) ~~ m/ .*? (cd) (e).* /; say $/[0]; =
say=20
$/[1]
=EF=BD=A2cd=EF=BD=A3
=EF=BD=A2e=EF=BD=A3
0
perl6
12/7/2019 6:53:50 AM
On Fri, Dec 6, 2019 at 10:54 PM ToddAndMargo via perl6-users
<perl6-users@perl.org> wrote:
>
> On 2019-12-06 22:38, ToddAndMargo via perl6-users wrote:
> >>> On Fri, Dec 6, 2019 at 9:28 PM ToddAndMargo via perl6-users
> >>> <perl6-users@perl.org> wrote:
> >>>>
> >>>> On 2019-12-06 20:33, William Michels via perl6-users wrote:
> >>>>> say $/;
> >>>>
> >>>> First I have seen of `$/`.  Is it any relation to `$_`?
> >
> > On 2019-12-06 22:11, William Michels via perl6-users wrote:
> >> Hi Todd, yes in a sense "$/" is related to "$_" in that they're both
> >> variables that get filled with values behind the scenes by Raku/Perl6.
> >> You already know that "$_" is the general default 'topic' variable
> >> (same as in Perl 5, see Ref#1 below).
> >>
> >>  From Ref#2 below: " $/ is the match variable. It stores the result of
> >> the last Regex match and so usually contains objects of type Match."
> >> Apparently "$/" in Raku/Perl6 has replaced a series of variables that
> >> were used in Perl5, including  "$`", "$&", and "$'" which "are gone
> >> from Raku" (Ref#3 below):
> >>
> >> 1. https://docs.raku.org/language/5to6-perlvar#$ARG,_$_
> >> 2. https://docs.raku.org/syntax/$$SOLIDUS
> >> 3.
> >> https://docs.raku.org/language/5to6-perlvar#Variables_related_to_regul=
ar_expressions
> >>
> >>
> >> HTH, Bill.
> >
> > Awesome!  I am going to have fun with this!  I do
> > A LOT of regex's.
> >
> > Thank you!
>
>
>
> Tells me what was matched!  Oh I am going to have a
> lot of fun with this!
>
> my $x =3D Q[\:\\::]; ( my $y =3D $x ) ~~ s/ '\\\\' /x/; say $/
> =EF=BD=A2\\=EF=BD=A3
>
> my $x =3D Q[abcdef]; ( my $y =3D $x ) ~~ s/ .*? (cd) (e) .* /x/; say $/
> =EF=BD=A2abcdef=EF=BD=A3
>   0 =3D> =EF=BD=A2cd=EF=BD=A3
>   1 =3D> =EF=BD=A2e=EF=BD=A3
>
> my $x =3D Q[abcdef]; ( my $y =3D $x ) ~~ m/ .*? (cd) (e).* /; say $/
> =EF=BD=A2abcdef=EF=BD=A3
>   0 =3D> =EF=BD=A2cd=EF=BD=A3
>   1 =3D> =EF=BD=A2e=EF=BD=A3
>
> my $x =3D Q[abcdef]; ( my $y =3D $x ) ~~ m/ .*? (cd) (e).* /; for $/ {say=
 $_};
> =EF=BD=A2abcdef=EF=BD=A3
>   0 =3D> =EF=BD=A2cd=EF=BD=A3
>   1 =3D> =EF=BD=A2e=EF=BD=A3
>
> my $x =3D Q[abcdef]; ( my $y =3D $x ) ~~ m/ .*? (cd) (e).* /; say $/[0]; =
say
> $/[1]
> =EF=BD=A2cd=EF=BD=A3
> =EF=BD=A2e=EF=BD=A3

Adding some:

mbook:~ homedir$ perl6
To exit type 'exit' or '^D'
> my $x =3D Q[\:\\::];
\:\\::
> say $/ if $x ~~ m/ '\\\\' /;
=EF=BD=A2\\=EF=BD=A3
> say $/ if $x ~~ rx/ '\\\\' /;
=EF=BD=A2\\=EF=BD=A3
> say $x
\:\\::
> $*VM
moar (2019.07.1)
>

HTH, Bill
0
perl6
12/7/2019 7:06:36 AM
On 2019-12-06 23:06, William Michels via perl6-users wrote:
> On Fri, Dec 6, 2019 at 10:54 PM ToddAndMargo via perl6-users
> <perl6-users@perl.org> wrote:
>>
>> On 2019-12-06 22:38, ToddAndMargo via perl6-users wrote:
>>>>> On Fri, Dec 6, 2019 at 9:28 PM ToddAndMargo via perl6-users
>>>>> <perl6-users@perl.org> wrote:
>>>>>>
>>>>>> On 2019-12-06 20:33, William Michels via perl6-users wrote:
>>>>>>> say $/;
>>>>>>
>>>>>> First I have seen of `$/`.  Is it any relation to `$_`?
>>>
>>> On 2019-12-06 22:11, William Michels via perl6-users wrote:
>>>> Hi Todd, yes in a sense "$/" is related to "$_" in that they're both=

>>>> variables that get filled with values behind the scenes by Raku/Perl=
6.
>>>> You already know that "$_" is the general default 'topic' variable
>>>> (same as in Perl 5, see Ref#1 below).
>>>>
>>>>   From Ref#2 below: " $/ is the match variable. It stores the result=
 of
>>>> the last Regex match and so usually contains objects of type Match."=

>>>> Apparently "$/" in Raku/Perl6 has replaced a series of variables tha=
t
>>>> were used in Perl5, including  "$`", "$&", and "$'" which "are gone
>>>> from Raku" (Ref#3 below):
>>>>
>>>> 1. https://docs.raku.org/language/5to6-perlvar#$ARG,_$_
>>>> 2. https://docs.raku.org/syntax/$$SOLIDUS
>>>> 3.
>>>> https://docs.raku.org/language/5to6-perlvar#Variables_related_to_reg=
ular_expressions
>>>>
>>>>
>>>> HTH, Bill.
>>>
>>> Awesome!  I am going to have fun with this!  I do
>>> A LOT of regex's.
>>>
>>> Thank you!
>>
>>
>>
>> Tells me what was matched!  Oh I am going to have a
>> lot of fun with this!
>>
>> my $x =3D Q[\:\\::]; ( my $y =3D $x ) ~~ s/ '\\\\' /x/; say $/
>> =EF=BD=A2\\=EF=BD=A3
>>
>> my $x =3D Q[abcdef]; ( my $y =3D $x ) ~~ s/ .*? (cd) (e) .* /x/; say $=
/
>> =EF=BD=A2abcdef=EF=BD=A3
>>    0 =3D> =EF=BD=A2cd=EF=BD=A3
>>    1 =3D> =EF=BD=A2e=EF=BD=A3
>>
>> my $x =3D Q[abcdef]; ( my $y =3D $x ) ~~ m/ .*? (cd) (e).* /; say $/
>> =EF=BD=A2abcdef=EF=BD=A3
>>    0 =3D> =EF=BD=A2cd=EF=BD=A3
>>    1 =3D> =EF=BD=A2e=EF=BD=A3
>>
>> my $x =3D Q[abcdef]; ( my $y =3D $x ) ~~ m/ .*? (cd) (e).* /; for $/ {=
say $_};
>> =EF=BD=A2abcdef=EF=BD=A3
>>    0 =3D> =EF=BD=A2cd=EF=BD=A3
>>    1 =3D> =EF=BD=A2e=EF=BD=A3
>>
>> my $x =3D Q[abcdef]; ( my $y =3D $x ) ~~ m/ .*? (cd) (e).* /; say $/[0=
]; say
>> $/[1]
>> =EF=BD=A2cd=EF=BD=A3
>> =EF=BD=A2e=EF=BD=A3
>=20
> Adding some:
>=20
> mbook:~ homedir$ perl6
> To exit type 'exit' or '^D'
>> my $x =3D Q[\:\\::];
> \:\\::
>> say $/ if $x ~~ m/ '\\\\' /;
> =EF=BD=A2\\=EF=BD=A3-T
>> say $/ if $x ~~ rx/ '\\\\' /;
> =EF=BD=A2\\=EF=BD=A3
>> say $x
> \:\\::
>> $*VM
> moar (2019.07.1)
>>
>=20
> HTH, Bill
>=20

Hi Bill,

Maybe it is just me and I am easily amused, but I find regex's
a blast to work with.

P6's are easier than P5 too.  Nice clean up.

-T
0
perl6
12/7/2019 7:18:28 AM
--000000000000255efe05991f29bd
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

The return value of s/// is the same as $/

If you want the resulting string instead you can use S/// instead.

    > $_ =3D 'abc'
    > my $r =3D S/b/./
    > say $r
    a.c

Note that it warns you try to use S/// with ~~

    > my $r =3D 'abc' ~~ S/b/./
    Potential difficulties:
        Smartmatch with S/// is not useful. You can use given instead: S///
given $foo
        ------> my $r =3D 'abc' ~~ =E2=8F=8FS/b/./
    False

Which gives you an indicator of how to fix it

    > my $r =3D S/b/./ given 'abc'
    a.c

Note that the `given` happens before the `=3D`

So it works the same as

    > my $r =3D ( S/b/./ given 'abc' )
    a.c

---

The reason ~~ doesn't work with S/// has to do with the dual pass nature of
~~.

Without getting into details, you can avoid that by delaying the S/// until
the second pass.

    > my $r =3D 'abc' ~~ { S/b/./ }
    a.c

Or you can just set $_ to the value.
(Which is basically what the previous line is doing.)

    > my $r =3D S/b/./ given 'abc'

    > given 'abc' {
    >   my $r =3D S/b/./
    >   =E2=80=A6
    > }

    > my $_ =3D 'abc'
    > my $r =3D S/b/./

    > my $r =3D 'abc' ~~ -> $_ { S/b/./ }

    > my $r =3D 'abc' ~~ sub ( $_ ) { S/b/./ }

    > my $r =3D 'abc' ~~ anon sub foo ( $_ ) { S/b/./ }
---

One of design goals of Raku is to have as few special cases as possible.
Which is why ~~ and S/// haven't been made to just work.

(It could be argued that in this case an exception could be made. But I'm
not going to argue for it.)

On Fri, Dec 6, 2019 at 10:37 PM William Michels via perl6-users <
perl6-users@perl.org> wrote:

> Hello All,
>
> Todd put up some interesting code yesterday using the Raku/Perl6 REPL,
> which I reproduced with no problem. Additionally I tried some
> variations removing and/or moving parentheses to a different location,
> and have numbered the relevant REPL lines 1 through 6:
>
> mbook:~ homedir$ perl6
> To exit type 'exit' or '^D'
> 1> my $x =3D Q[word</b><br>] ;
> word</b><br>
> 2> (my $y =3D $x) ~~ s/ '<' .* //; say $/; say $x; say $y;
> =EF=BD=A2</b><br>=EF=BD=A3
> word</b><br>
> word
> 3> my $a =3D Q[word</b><br>] ;
> word</b><br>
> 4> my $b =3D ($a ~~ s/ '<' .* //); say $/; say $a; say $b;
> =EF=BD=A2</b><br>=EF=BD=A3
> word
> =EF=BD=A2</b><br>=EF=BD=A3
> > my $c =3D Q[word</b><br>] ;
> word</b><br>
> > my $d =3D $c ~~ s/ '<' .* //; say $/; say $c; say $d;
> =EF=BD=A2</b><br>=EF=BD=A3
> word
> =EF=BD=A2</b><br>=EF=BD=A3
> 7> $*VM
> moar (2019.07.1)
>
> Working in groups of 2, lines 1 and 2 replicate the code Todd put up
> (parenthesis surrounding everything to the left of the smartmatch
> operator). I get the same result as Todd. What interests me are lines
> 3 through 6. Lines 3 and 4 are the virtually the same code but with
> parentheses surrounding everything to the right hand side (RHS) of the
> assignment operator (" =3D "). As people will note, lines 2 and lines 4
> give different results. Removing parentheses entirely in line 6 gives
> the same result as in line 4. Because the results in line 4 and line 6
> are the same, this says that as far as parentheses are concerned, the
> smartmatch operator "~~" takes precedence over the assignment operator
> "=3D".
>
> What's not clear to me in the code above (lines 4 and 6) is why
> variables $b and $d get assigned to $/. I would have expected in line
> 4 that $a would have been matched against the smartmatch, and the
> result ("word") would have been simply copied into variable $b. Have I
> misunderstood?
>
> Anyway, I'm just hoping to start a conversation on the topic of
> precedence in general, and hopefully getting some feedback as to where
> to look in the docs for further instruction.
>
> Best Regards, Bill.
>
>
> On Fri, Dec 6, 2019 at 12:15 AM ToddAndMargo via perl6-users
> <perl6-users@perl.org> wrote:
> >
> > On 2019-12-05 23:19, ToddAndMargo via perl6-users wrote:
> > > On 2019-12-05 03:09, William Michels via perl6-users wrote:
> > >> What happens when you type "perl6" or "raku" at the bash command
> prompt?
> > >
> > > Hi William,
> > >
> > > On my shop machine, it jumps to the next line with an
> > > empty flashing cursor
> > >
> > > On my office machine, it told me to install
> > >      zef install Readline
> > >
> > > After that, I get:
> > >
> > > $ perl6
> > > To exit type 'exit' or '^D'
> > >  >
> > >
> > > and
> > >
> > >  > say "hello World"
> > > hello World
> > >  > say "B" ~ Q[:\] ~ " drive dismounted"
> > > B:\ drive dismounted
> > >  >
> > >
> > > and sticking an obvious booboo into it
> > >
> > >  > if 3 % 2 =3D 1 {say "odd"};
> > > Cannot modify an immutable Int (1)
> > >    in block <unit> at <unknown file> line 1
> > >
> > > Plus I can use the arrow keys to recall previous lines too.
> > >
> > > Time up update my Perl6 on my shop computer!
> > >
> > > No more hassling with `perl6 -e` !!!
> > >
> > > Dude!  THANK YOU !!!!!!
> > >
> > > -T
> >
> > You've created a monster!!
> >
> > perl6
> > To exit type 'exit' or '^D'
> >  > my $x =3D Q[</b><br>]
> > </b><br>
> >  > say $x
> > </b><br>
> >  > (my $y =3D $x ) ~~ s/ Q[<] .* //;
> > =3D=3D=3DSORRY!=3D=3D=3D Error while compiling:
> > Unrecognized regex metacharacter < (must be quoted to match literally)
> > ------> (my $y =3D $x ) ~~ s/ Q[<] .* //;
> >  > my $x =3D Q[abc</b><br>]
> > abc</b><br>
> >  > (my $y =3D $x ) ~~ s/ '<' .* //;
> > =EF=BD=A2</b><br>=EF=BD=A3
> >  > (my $y =3D $x ) ~~ s/ '<' .* //; say $y
> > abc
> >  > (my $y =3D $x ) ~~ s/ '<' .* //; say $x; say $y
> > abc</b><br>
> > abc
> >
> >
> > Thank you!
> >
> >
> > --
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > Computers are like air conditioners.
> > They malfunction when you open windows
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>

--000000000000255efe05991f29bd
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">The return value of s/// is the same as $/<div><br><div>If=
 you want the resulting string instead you can use S/// instead.</div></div=
><div><br></div><div>=C2=A0 =C2=A0 &gt; $_ =3D &#39;abc&#39;</div><div>=C2=
=A0 =C2=A0 &gt; my $r =3D S/b/./</div><div>=C2=A0 =C2=A0 &gt; say $r</div><=
div>=C2=A0 =C2=A0 a.c</div><div><br></div><div>Note that it warns you try t=
o use S/// with ~~</div><div><br></div><div>=C2=A0 =C2=A0 &gt; my $r =3D &#=
39;abc&#39; ~~ S/b/./</div><div>=C2=A0 =C2=A0 Potential difficulties:<br>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 Smartmatch with S/// is not useful. You can use=
 given instead: S/// given $foo<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 ------&gt; m=
y $r =3D &#39;abc&#39; ~~ =E2=8F=8FS/b/./<br>=C2=A0 =C2=A0 False<br></div><=
div><br></div><div>Which gives you an indicator=C2=A0of how to fix it</div>=
<div><br></div><div>=C2=A0 =C2=A0 &gt; my $r =3D S/b/./ given &#39;abc&#39;=
</div><div>=C2=A0 =C2=A0 a.c</div><div><br></div><div>Note that the `given`=
 happens before the `=3D`</div><div><br></div><div>So it works the same as<=
/div><div><br></div><div>=C2=A0 =C2=A0 &gt; my $r =3D ( S/b/./ given &#39;a=
bc&#39; )</div><div>=C2=A0 =C2=A0 a.c</div><div><br></div><div>---</div><di=
v><br></div><div>The reason ~~ doesn&#39;t work with S/// has to do with th=
e dual pass nature of ~~.</div><div><br></div><div>Without getting into det=
ails, you can avoid that by delaying the S/// until the second pass.</div><=
div><br></div><div>=C2=A0 =C2=A0 &gt; my $r =3D &#39;abc&#39; ~~ { S/b/./ }=
</div><div>=C2=A0 =C2=A0 a.c</div><div><br></div><div>Or you can just set $=
_ to the value.</div><div>(Which is basically what the previous line is doi=
ng.)</div><div><br></div><div>=C2=A0 =C2=A0 &gt; my $r =3D S/b/./ given &#3=
9;abc&#39;</div><div><br></div><div>=C2=A0 =C2=A0 &gt; given &#39;abc&#39; =
{</div><div>=C2=A0 =C2=A0 &gt;=C2=A0 =C2=A0my $r =3D S/b/./</div><div>=C2=
=A0 =C2=A0 &gt;=C2=A0 =C2=A0=E2=80=A6</div><div>=C2=A0 =C2=A0 &gt; }</div><=
div><br></div><div>=C2=A0 =C2=A0 &gt; my $_ =3D &#39;abc&#39;</div><div>=C2=
=A0 =C2=A0 &gt; my $r =3D S/b/./</div><div><br></div><div>=C2=A0 =C2=A0 &gt=
; my $r =3D &#39;abc&#39; ~~ -&gt; $_ { S/b/./ }</div><div><br></div><div>=
=C2=A0 =C2=A0 &gt; my $r =3D &#39;abc&#39; ~~ sub ( $_ ) { S/b/./ }</div><d=
iv><br></div><div>=C2=A0 =C2=A0 &gt; my $r =3D &#39;abc&#39; ~~ anon sub fo=
o ( $_ ) { S/b/./ }</div><div>---</div><div><br></div><div>One of design go=
als of Raku is to have as few special cases as possible.</div><div>Which is=
 why ~~ and S/// haven&#39;t been made to just work.</div><div><br></div><d=
iv>(It could be argued that in this case an exception could be made. But I&=
#39;m not going to argue for it.)</div></div><br><div class=3D"gmail_quote"=
><div dir=3D"ltr" class=3D"gmail_attr">On Fri, Dec 6, 2019 at 10:37 PM Will=
iam Michels via perl6-users &lt;<a href=3D"mailto:perl6-users@perl.org">per=
l6-users@perl.org</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote"=
 style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);p=
adding-left:1ex">Hello All,<br>
<br>
Todd put up some interesting code yesterday using the Raku/Perl6 REPL,<br>
which I reproduced with no problem. Additionally I tried some<br>
variations removing and/or moving parentheses to a different location,<br>
and have numbered the relevant REPL lines 1 through 6:<br>
<br>
mbook:~ homedir$ perl6<br>
To exit type &#39;exit&#39; or &#39;^D&#39;<br>
1&gt; my $x =3D Q[word&lt;/b&gt;&lt;br&gt;] ;<br>
word&lt;/b&gt;&lt;br&gt;<br>
2&gt; (my $y =3D $x) ~~ s/ &#39;&lt;&#39; .* //; say $/; say $x; say $y;<br=
>
=EF=BD=A2&lt;/b&gt;&lt;br&gt;=EF=BD=A3<br>
word&lt;/b&gt;&lt;br&gt;<br>
word<br>
3&gt; my $a =3D Q[word&lt;/b&gt;&lt;br&gt;] ;<br>
word&lt;/b&gt;&lt;br&gt;<br>
4&gt; my $b =3D ($a ~~ s/ &#39;&lt;&#39; .* //); say $/; say $a; say $b;<br=
>
=EF=BD=A2&lt;/b&gt;&lt;br&gt;=EF=BD=A3<br>
word<br>
=EF=BD=A2&lt;/b&gt;&lt;br&gt;=EF=BD=A3<br>
&gt; my $c =3D Q[word&lt;/b&gt;&lt;br&gt;] ;<br>
word&lt;/b&gt;&lt;br&gt;<br>
&gt; my $d =3D $c ~~ s/ &#39;&lt;&#39; .* //; say $/; say $c; say $d;<br>
=EF=BD=A2&lt;/b&gt;&lt;br&gt;=EF=BD=A3<br>
word<br>
=EF=BD=A2&lt;/b&gt;&lt;br&gt;=EF=BD=A3<br>
7&gt; $*VM<br>
moar (2019.07.1)<br>
<br>
Working in groups of 2, lines 1 and 2 replicate the code Todd put up<br>
(parenthesis surrounding everything to the left of the smartmatch<br>
operator). I get the same result as Todd. What interests me are lines<br>
3 through 6. Lines 3 and 4 are the virtually the same code but with<br>
parentheses surrounding everything to the right hand side (RHS) of the<br>
assignment operator (&quot; =3D &quot;). As people will note, lines 2 and l=
ines 4<br>
give different results. Removing parentheses entirely in line 6 gives<br>
the same result as in line 4. Because the results in line 4 and line 6<br>
are the same, this says that as far as parentheses are concerned, the<br>
smartmatch operator &quot;~~&quot; takes precedence over the assignment ope=
rator<br>
&quot;=3D&quot;.<br>
<br>
What&#39;s not clear to me in the code above (lines 4 and 6) is why<br>
variables $b and $d get assigned to $/. I would have expected in line<br>
4 that $a would have been matched against the smartmatch, and the<br>
result (&quot;word&quot;) would have been simply copied into variable $b. H=
ave I<br>
misunderstood?<br>
<br>
Anyway, I&#39;m just hoping to start a conversation on the topic of<br>
precedence in general, and hopefully getting some feedback as to where<br>
to look in the docs for further instruction.<br>
<br>
Best Regards, Bill.<br>
<br>
<br>
On Fri, Dec 6, 2019 at 12:15 AM ToddAndMargo via perl6-users<br>
&lt;<a href=3D"mailto:perl6-users@perl.org" target=3D"_blank">perl6-users@p=
erl.org</a>&gt; wrote:<br>
&gt;<br>
&gt; On 2019-12-05 23:19, ToddAndMargo via perl6-users wrote:<br>
&gt; &gt; On 2019-12-05 03:09, William Michels via perl6-users wrote:<br>
&gt; &gt;&gt; What happens when you type &quot;perl6&quot; or &quot;raku&qu=
ot; at the bash command prompt?<br>
&gt; &gt;<br>
&gt; &gt; Hi William,<br>
&gt; &gt;<br>
&gt; &gt; On my shop machine, it jumps to the next line with an<br>
&gt; &gt; empty flashing cursor<br>
&gt; &gt;<br>
&gt; &gt; On my office machine, it told me to install<br>
&gt; &gt;=C2=A0 =C2=A0 =C2=A0 zef install Readline<br>
&gt; &gt;<br>
&gt; &gt; After that, I get:<br>
&gt; &gt;<br>
&gt; &gt; $ perl6<br>
&gt; &gt; To exit type &#39;exit&#39; or &#39;^D&#39;<br>
&gt; &gt;=C2=A0 &gt;<br>
&gt; &gt;<br>
&gt; &gt; and<br>
&gt; &gt;<br>
&gt; &gt;=C2=A0 &gt; say &quot;hello World&quot;<br>
&gt; &gt; hello World<br>
&gt; &gt;=C2=A0 &gt; say &quot;B&quot; ~ Q[:\] ~ &quot; drive dismounted&qu=
ot;<br>
&gt; &gt; B:\ drive dismounted<br>
&gt; &gt;=C2=A0 &gt;<br>
&gt; &gt;<br>
&gt; &gt; and sticking an obvious booboo into it<br>
&gt; &gt;<br>
&gt; &gt;=C2=A0 &gt; if 3 % 2 =3D 1 {say &quot;odd&quot;};<br>
&gt; &gt; Cannot modify an immutable Int (1)<br>
&gt; &gt;=C2=A0 =C2=A0 in block &lt;unit&gt; at &lt;unknown file&gt; line 1=
<br>
&gt; &gt;<br>
&gt; &gt; Plus I can use the arrow keys to recall previous lines too.<br>
&gt; &gt;<br>
&gt; &gt; Time up update my Perl6 on my shop computer!<br>
&gt; &gt;<br>
&gt; &gt; No more hassling with `perl6 -e` !!!<br>
&gt; &gt;<br>
&gt; &gt; Dude!=C2=A0 THANK YOU !!!!!!<br>
&gt; &gt;<br>
&gt; &gt; -T<br>
&gt;<br>
&gt; You&#39;ve created a monster!!<br>
&gt;<br>
&gt; perl6<br>
&gt; To exit type &#39;exit&#39; or &#39;^D&#39;<br>
&gt;=C2=A0 &gt; my $x =3D Q[&lt;/b&gt;&lt;br&gt;]<br>
&gt; &lt;/b&gt;&lt;br&gt;<br>
&gt;=C2=A0 &gt; say $x<br>
&gt; &lt;/b&gt;&lt;br&gt;<br>
&gt;=C2=A0 &gt; (my $y =3D $x ) ~~ s/ Q[&lt;] .* //;<br>
&gt; =3D=3D=3DSORRY!=3D=3D=3D Error while compiling:<br>
&gt; Unrecognized regex metacharacter &lt; (must be quoted to match literal=
ly)<br>
&gt; ------&gt; (my $y =3D $x ) ~~ s/ Q[&lt;] .* //;<br>
&gt;=C2=A0 &gt; my $x =3D Q[abc&lt;/b&gt;&lt;br&gt;]<br>
&gt; abc&lt;/b&gt;&lt;br&gt;<br>
&gt;=C2=A0 &gt; (my $y =3D $x ) ~~ s/ &#39;&lt;&#39; .* //;<br>
&gt; =EF=BD=A2&lt;/b&gt;&lt;br&gt;=EF=BD=A3<br>
&gt;=C2=A0 &gt; (my $y =3D $x ) ~~ s/ &#39;&lt;&#39; .* //; say $y<br>
&gt; abc<br>
&gt;=C2=A0 &gt; (my $y =3D $x ) ~~ s/ &#39;&lt;&#39; .* //; say $x; say $y<=
br>
&gt; abc&lt;/b&gt;&lt;br&gt;<br>
&gt; abc<br>
&gt;<br>
&gt;<br>
&gt; Thank you!<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
&gt; Computers are like air conditioners.<br>
&gt; They malfunction when you open windows<br>
&gt; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
</blockquote></div>

--000000000000255efe05991f29bd--
0
b2gills
12/7/2019 3:53:05 PM
Wow Brad, that's interesting and informative.

I haven't seen the S/// operator before, so I had to look it up. On
the first page I found the docs say (quite informatively): "S/// uses
the same semantics as the s/// operator, except it leaves the original
string intact and returns the resultant string instead of $/ ($/ still
being set to the same values as with s///)."

https://docs.raku.org/syntax/S$SOLIDUS$SOLIDUS$SOLIDUS

I was then able to find an overview on regexes, which more explicitly
names the "S///" operator as "Non-disruptive substitution". I suppose
I could quibble and request that the phrase "Non-disruptive
substitution" be added to the operator page (above), but no
matter--it's easy enough to find:

https://docs.raku.org/language/regexes#S///_non-destructive_substitution

So I think I understand that (as Brad has said): "smartmatch with S///
(or TR///) is not useful." Conversely, I've also found another
smartmatch construct that is useless (i.e. disallowed):

> my $r =3D 'abc' ~~ { S/b/./ }
a.c
> my $s =3D 'abc' ~~ { s/b/./ }
Cannot modify an immutable Str (abc)
  in block <unit> at <unknown file> line 1
>

No matter how "discouraged' a particular syntax is, people are going
to run into these disallowed syntaxes and wonder why. Could it be due
to precedence? These two prohibited operations beg the question: can a
definitive statement be made regarding the precedence of the
smartmatch operator relative to either lowercase-triple-solidus
operators such as s/// and tr/// , or relative to
uppercase-triple-solidus operators such as S/// and TR/// ?

This really makes me wonder if anyone has plans to add "~~" (the
smartmatch operator) to the precedence table that can be found
below--and where in the table the smartmatch operator would precisely
sit:

https://docs.raku.org/language/operators#Operator_precedence

Best Regards, Bill.




On Sat, Dec 7, 2019 at 7:53 AM Brad Gilbert <b2gills@gmail.com> wrote:
>
> The return value of s/// is the same as $/
>
> If you want the resulting string instead you can use S/// instead.
>
>     > $_ =3D 'abc'
>     > my $r =3D S/b/./
>     > say $r
>     a.c
>
> Note that it warns you try to use S/// with ~~
>
>     > my $r =3D 'abc' ~~ S/b/./
>     Potential difficulties:
>         Smartmatch with S/// is not useful. You can use given instead: S/=
// given $foo
>         ------> my $r =3D 'abc' ~~ S/b/./
>     False
>
> Which gives you an indicator of how to fix it
>
>     > my $r =3D S/b/./ given 'abc'
>     a.c
>
> Note that the `given` happens before the `=3D`
>
> So it works the same as
>
>     > my $r =3D ( S/b/./ given 'abc' )
>     a.c
>
> ---
>
> The reason ~~ doesn't work with S/// has to do with the dual pass nature =
of ~~.
>
> Without getting into details, you can avoid that by delaying the S/// unt=
il the second pass.
>
>     > my $r =3D 'abc' ~~ { S/b/./ }
>     a.c
>
> Or you can just set $_ to the value.
> (Which is basically what the previous line is doing.)
>
>     > my $r =3D S/b/./ given 'abc'
>
>     > given 'abc' {
>     >   my $r =3D S/b/./
>     >   =E2=80=A6
>     > }
>
>     > my $_ =3D 'abc'
>     > my $r =3D S/b/./
>
>     > my $r =3D 'abc' ~~ -> $_ { S/b/./ }
>
>     > my $r =3D 'abc' ~~ sub ( $_ ) { S/b/./ }
>
>     > my $r =3D 'abc' ~~ anon sub foo ( $_ ) { S/b/./ }
> ---
>
> One of design goals of Raku is to have as few special cases as possible.
> Which is why ~~ and S/// haven't been made to just work.
>
> (It could be argued that in this case an exception could be made. But I'm=
 not going to argue for it.)
>
> On Fri, Dec 6, 2019 at 10:37 PM William Michels via perl6-users <perl6-us=
ers@perl.org> wrote:
>>
>> Hello All,
>>
>> Todd put up some interesting code yesterday using the Raku/Perl6 REPL,
>> which I reproduced with no problem. Additionally I tried some
>> variations removing and/or moving parentheses to a different location,
>> and have numbered the relevant REPL lines 1 through 6:
>>
>> mbook:~ homedir$ perl6
>> To exit type 'exit' or '^D'
>> 1> my $x =3D Q[word</b><br>] ;
>> word</b><br>
>> 2> (my $y =3D $x) ~~ s/ '<' .* //; say $/; say $x; say $y;
>> =EF=BD=A2</b><br>=EF=BD=A3
>> word</b><br>
>> word
>> 3> my $a =3D Q[word</b><br>] ;
>> word</b><br>
>> 4> my $b =3D ($a ~~ s/ '<' .* //); say $/; say $a; say $b;
>> =EF=BD=A2</b><br>=EF=BD=A3
>> word
>> =EF=BD=A2</b><br>=EF=BD=A3
>> > my $c =3D Q[word</b><br>] ;
>> word</b><br>
>> > my $d =3D $c ~~ s/ '<' .* //; say $/; say $c; say $d;
>> =EF=BD=A2</b><br>=EF=BD=A3
>> word
>> =EF=BD=A2</b><br>=EF=BD=A3
>> 7> $*VM
>> moar (2019.07.1)
>>
>> Working in groups of 2, lines 1 and 2 replicate the code Todd put up
>> (parenthesis surrounding everything to the left of the smartmatch
>> operator). I get the same result as Todd. What interests me are lines
>> 3 through 6. Lines 3 and 4 are the virtually the same code but with
>> parentheses surrounding everything to the right hand side (RHS) of the
>> assignment operator (" =3D "). As people will note, lines 2 and lines 4
>> give different results. Removing parentheses entirely in line 6 gives
>> the same result as in line 4. Because the results in line 4 and line 6
>> are the same, this says that as far as parentheses are concerned, the
>> smartmatch operator "~~" takes precedence over the assignment operator
>> "=3D".
>>
>> What's not clear to me in the code above (lines 4 and 6) is why
>> variables $b and $d get assigned to $/. I would have expected in line
>> 4 that $a would have been matched against the smartmatch, and the
>> result ("word") would have been simply copied into variable $b. Have I
>> misunderstood?
>>
>> Anyway, I'm just hoping to start a conversation on the topic of
>> precedence in general, and hopefully getting some feedback as to where
>> to look in the docs for further instruction.
>>
>> Best Regards, Bill.
>>
>>
>> On Fri, Dec 6, 2019 at 12:15 AM ToddAndMargo via perl6-users
>> <perl6-users@perl.org> wrote:
>> >
>> > On 2019-12-05 23:19, ToddAndMargo via perl6-users wrote:
>> > > On 2019-12-05 03:09, William Michels via perl6-users wrote:
>> > >> What happens when you type "perl6" or "raku" at the bash command pr=
ompt?
>> > >
>> > > Hi William,
>> > >
>> > > On my shop machine, it jumps to the next line with an
>> > > empty flashing cursor
>> > >
>> > > On my office machine, it told me to install
>> > >      zef install Readline
>> > >
>> > > After that, I get:
>> > >
>> > > $ perl6
>> > > To exit type 'exit' or '^D'
>> > >  >
>> > >
>> > > and
>> > >
>> > >  > say "hello World"
>> > > hello World
>> > >  > say "B" ~ Q[:\] ~ " drive dismounted"
>> > > B:\ drive dismounted
>> > >  >
>> > >
>> > > and sticking an obvious booboo into it
>> > >
>> > >  > if 3 % 2 =3D 1 {say "odd"};
>> > > Cannot modify an immutable Int (1)
>> > >    in block <unit> at <unknown file> line 1
>> > >
>> > > Plus I can use the arrow keys to recall previous lines too.
>> > >
>> > > Time up update my Perl6 on my shop computer!
>> > >
>> > > No more hassling with `perl6 -e` !!!
>> > >
>> > > Dude!  THANK YOU !!!!!!
>> > >
>> > > -T
>> >
>> > You've created a monster!!
>> >
>> > perl6
>> > To exit type 'exit' or '^D'
>> >  > my $x =3D Q[</b><br>]
>> > </b><br>
>> >  > say $x
>> > </b><br>
>> >  > (my $y =3D $x ) ~~ s/ Q[<] .* //;
>> > =3D=3D=3DSORRY!=3D=3D=3D Error while compiling:
>> > Unrecognized regex metacharacter < (must be quoted to match literally)
>> > ------> (my $y =3D $x ) ~~ s/ Q[<] .* //;
>> >  > my $x =3D Q[abc</b><br>]
>> > abc</b><br>
>> >  > (my $y =3D $x ) ~~ s/ '<' .* //;
>> > =EF=BD=A2</b><br>=EF=BD=A3
>> >  > (my $y =3D $x ) ~~ s/ '<' .* //; say $y
>> > abc
>> >  > (my $y =3D $x ) ~~ s/ '<' .* //; say $x; say $y
>> > abc</b><br>
>> > abc
>> >
>> >
>> > Thank you!
>> >
>> >
>> > --
>> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> > Computers are like air conditioners.
>> > They malfunction when you open windows
>> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0
perl6
12/8/2019 6:27:47 AM
Apologies, looks like the smartmatch operator is listed in the
Operator Precedence table (15th row: under "Chaining infix"):

https://docs.raku.org/language/operators#Assignment_operators

However, am I correct in stating that the assignment operator ("=3D") is
on the 19th row ("Item assignment")? Therefore in the absence of
parentheses, etc., all smartmatch operations take precedence over
assignment operations?

Best Regards, Bill.


On Sat, Dec 7, 2019 at 10:27 PM William Michels <wjm1@caa.columbia.edu> wro=
te:
>
> Wow Brad, that's interesting and informative.
>
> I haven't seen the S/// operator before, so I had to look it up. On
> the first page I found the docs say (quite informatively): "S/// uses
> the same semantics as the s/// operator, except it leaves the original
> string intact and returns the resultant string instead of $/ ($/ still
> being set to the same values as with s///)."
>
> https://docs.raku.org/syntax/S$SOLIDUS$SOLIDUS$SOLIDUS
>
> I was then able to find an overview on regexes, which more explicitly
> names the "S///" operator as "Non-disruptive substitution". I suppose
> I could quibble and request that the phrase "Non-disruptive
> substitution" be added to the operator page (above), but no
> matter--it's easy enough to find:
>
> https://docs.raku.org/language/regexes#S///_non-destructive_substitution
>
> So I think I understand that (as Brad has said): "smartmatch with S///
> (or TR///) is not useful." Conversely, I've also found another
> smartmatch construct that is useless (i.e. disallowed):
>
> > my $r =3D 'abc' ~~ { S/b/./ }
> a.c
> > my $s =3D 'abc' ~~ { s/b/./ }
> Cannot modify an immutable Str (abc)
>   in block <unit> at <unknown file> line 1
> >
>
> No matter how "discouraged' a particular syntax is, people are going
> to run into these disallowed syntaxes and wonder why. Could it be due
> to precedence? These two prohibited operations beg the question: can a
> definitive statement be made regarding the precedence of the
> smartmatch operator relative to either lowercase-triple-solidus
> operators such as s/// and tr/// , or relative to
> uppercase-triple-solidus operators such as S/// and TR/// ?
>
> This really makes me wonder if anyone has plans to add "~~" (the
> smartmatch operator) to the precedence table that can be found
> below--and where in the table the smartmatch operator would precisely
> sit:
>
> https://docs.raku.org/language/operators#Operator_precedence
>
> Best Regards, Bill.
>
>
>
>
> On Sat, Dec 7, 2019 at 7:53 AM Brad Gilbert <b2gills@gmail.com> wrote:
> >
> > The return value of s/// is the same as $/
> >
> > If you want the resulting string instead you can use S/// instead.
> >
> >     > $_ =3D 'abc'
> >     > my $r =3D S/b/./
> >     > say $r
> >     a.c
> >
> > Note that it warns you try to use S/// with ~~
> >
> >     > my $r =3D 'abc' ~~ S/b/./
> >     Potential difficulties:
> >         Smartmatch with S/// is not useful. You can use given instead: =
S/// given $foo
> >         ------> my $r =3D 'abc' ~~ S/b/./
> >     False
> >
> > Which gives you an indicator of how to fix it
> >
> >     > my $r =3D S/b/./ given 'abc'
> >     a.c
> >
> > Note that the `given` happens before the `=3D`
> >
> > So it works the same as
> >
> >     > my $r =3D ( S/b/./ given 'abc' )
> >     a.c
> >
> > ---
> >
> > The reason ~~ doesn't work with S/// has to do with the dual pass natur=
e of ~~.
> >
> > Without getting into details, you can avoid that by delaying the S/// u=
ntil the second pass.
> >
> >     > my $r =3D 'abc' ~~ { S/b/./ }
> >     a.c
> >
> > Or you can just set $_ to the value.
> > (Which is basically what the previous line is doing.)
> >
> >     > my $r =3D S/b/./ given 'abc'
> >
> >     > given 'abc' {
> >     >   my $r =3D S/b/./
> >     >   =E2=80=A6
> >     > }
> >
> >     > my $_ =3D 'abc'
> >     > my $r =3D S/b/./
> >
> >     > my $r =3D 'abc' ~~ -> $_ { S/b/./ }
> >
> >     > my $r =3D 'abc' ~~ sub ( $_ ) { S/b/./ }
> >
> >     > my $r =3D 'abc' ~~ anon sub foo ( $_ ) { S/b/./ }
> > ---
> >
> > One of design goals of Raku is to have as few special cases as possible=
..
> > Which is why ~~ and S/// haven't been made to just work.
> >
> > (It could be argued that in this case an exception could be made. But I=
'm not going to argue for it.)
> >
> > On Fri, Dec 6, 2019 at 10:37 PM William Michels via perl6-users <perl6-=
users@perl.org> wrote:
> >>
> >> Hello All,
> >>
> >> Todd put up some interesting code yesterday using the Raku/Perl6 REPL,
> >> which I reproduced with no problem. Additionally I tried some
> >> variations removing and/or moving parentheses to a different location,
> >> and have numbered the relevant REPL lines 1 through 6:
> >>
> >> mbook:~ homedir$ perl6
> >> To exit type 'exit' or '^D'
> >> 1> my $x =3D Q[word</b><br>] ;
> >> word</b><br>
> >> 2> (my $y =3D $x) ~~ s/ '<' .* //; say $/; say $x; say $y;
> >> =EF=BD=A2</b><br>=EF=BD=A3
> >> word</b><br>
> >> word
> >> 3> my $a =3D Q[word</b><br>] ;
> >> word</b><br>
> >> 4> my $b =3D ($a ~~ s/ '<' .* //); say $/; say $a; say $b;
> >> =EF=BD=A2</b><br>=EF=BD=A3
> >> word
> >> =EF=BD=A2</b><br>=EF=BD=A3
> >> > my $c =3D Q[word</b><br>] ;
> >> word</b><br>
> >> > my $d =3D $c ~~ s/ '<' .* //; say $/; say $c; say $d;
> >> =EF=BD=A2</b><br>=EF=BD=A3
> >> word
> >> =EF=BD=A2</b><br>=EF=BD=A3
> >> 7> $*VM
> >> moar (2019.07.1)
> >>
> >> Working in groups of 2, lines 1 and 2 replicate the code Todd put up
> >> (parenthesis surrounding everything to the left of the smartmatch
> >> operator). I get the same result as Todd. What interests me are lines
> >> 3 through 6. Lines 3 and 4 are the virtually the same code but with
> >> parentheses surrounding everything to the right hand side (RHS) of the
> >> assignment operator (" =3D "). As people will note, lines 2 and lines =
4
> >> give different results. Removing parentheses entirely in line 6 gives
> >> the same result as in line 4. Because the results in line 4 and line 6
> >> are the same, this says that as far as parentheses are concerned, the
> >> smartmatch operator "~~" takes precedence over the assignment operator
> >> "=3D".
> >>
> >> What's not clear to me in the code above (lines 4 and 6) is why
> >> variables $b and $d get assigned to $/. I would have expected in line
> >> 4 that $a would have been matched against the smartmatch, and the
> >> result ("word") would have been simply copied into variable $b. Have I
> >> misunderstood?
> >>
> >> Anyway, I'm just hoping to start a conversation on the topic of
> >> precedence in general, and hopefully getting some feedback as to where
> >> to look in the docs for further instruction.
> >>
> >> Best Regards, Bill.
> >>
> >>
> >> On Fri, Dec 6, 2019 at 12:15 AM ToddAndMargo via perl6-users
> >> <perl6-users@perl.org> wrote:
> >> >
> >> > On 2019-12-05 23:19, ToddAndMargo via perl6-users wrote:
> >> > > On 2019-12-05 03:09, William Michels via perl6-users wrote:
> >> > >> What happens when you type "perl6" or "raku" at the bash command =
prompt?
> >> > >
> >> > > Hi William,
> >> > >
> >> > > On my shop machine, it jumps to the next line with an
> >> > > empty flashing cursor
> >> > >
> >> > > On my office machine, it told me to install
> >> > >      zef install Readline
> >> > >
> >> > > After that, I get:
> >> > >
> >> > > $ perl6
> >> > > To exit type 'exit' or '^D'
> >> > >  >
> >> > >
> >> > > and
> >> > >
> >> > >  > say "hello World"
> >> > > hello World
> >> > >  > say "B" ~ Q[:\] ~ " drive dismounted"
> >> > > B:\ drive dismounted
> >> > >  >
> >> > >
> >> > > and sticking an obvious booboo into it
> >> > >
> >> > >  > if 3 % 2 =3D 1 {say "odd"};
> >> > > Cannot modify an immutable Int (1)
> >> > >    in block <unit> at <unknown file> line 1
> >> > >
> >> > > Plus I can use the arrow keys to recall previous lines too.
> >> > >
> >> > > Time up update my Perl6 on my shop computer!
> >> > >
> >> > > No more hassling with `perl6 -e` !!!
> >> > >
> >> > > Dude!  THANK YOU !!!!!!
> >> > >
> >> > > -T
> >> >
> >> > You've created a monster!!
> >> >
> >> > perl6
> >> > To exit type 'exit' or '^D'
> >> >  > my $x =3D Q[</b><br>]
> >> > </b><br>
> >> >  > say $x
> >> > </b><br>
> >> >  > (my $y =3D $x ) ~~ s/ Q[<] .* //;
> >> > =3D=3D=3DSORRY!=3D=3D=3D Error while compiling:
> >> > Unrecognized regex metacharacter < (must be quoted to match literall=
y)
> >> > ------> (my $y =3D $x ) ~~ s/ Q[<] .* //;
> >> >  > my $x =3D Q[abc</b><br>]
> >> > abc</b><br>
> >> >  > (my $y =3D $x ) ~~ s/ '<' .* //;
> >> > =EF=BD=A2</b><br>=EF=BD=A3
> >> >  > (my $y =3D $x ) ~~ s/ '<' .* //; say $y
> >> > abc
> >> >  > (my $y =3D $x ) ~~ s/ '<' .* //; say $x; say $y
> >> > abc</b><br>
> >> > abc
> >> >
> >> >
> >> > Thank you!
> >> >
> >> >
> >> > --
> >> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >> > Computers are like air conditioners.
> >> > They malfunction when you open windows
> >> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0
perl6
12/8/2019 7:31:48 AM
--000000000000286d5d059937501f
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

smartmatch is among the most complex parts of the language.

That complexity has to managed or it will be too complex to use effectively=
..

To that end, the rules and order of operations are never altered.

1. The left side is evaluated first, and the resulting value captured

        > say('left') ~~ say('right')
        left
        right

2. $_ is temporarily set to that value, and the right side is executed

        > 'ab' ~ 'c'   ~~ say($_)
        abc

3. The result of that execution is matched against the left value

        > 'abc' ~~ 'abb'.succ()
        True

    Specifically `.ACCEPTS` is called with the left value.
    So the following two lines are roughly equivalent.

        > 'abc'   ~~   'abb'.succ()
        > 'abb'.succ().ACCEPTS('abc')

So in the case of S/// and ~~ this is the order that things happen:

1. The left side is executed

        =C2=AB a b c =C2=BB.join()  ~~  S/b/./

        'abc' ~~ S/b/./

2. $_ is temporarily set to that value, and the right side is executed

        'abc' ~~ S/b/./

        'abc' ~~ 'a.c'

3. the result of the right side is matched against the left value

        'abc' ~~ 'a.c'

        'a.c'.ACCEPTS('abc') # False

So basically if S/// changes the value, the result is False.
If S/// doesn't change it, the result is True.

Which means the following two lines are functionally identical.

    'abc'   ~~  S/b/./
    'abc'  !~~   /b/

So the resulting value will never be the string you wanted!
It will be True or False.

---

The reason for the two stage execution is for the following.

    'abc' ~~   .contains('b')
    'abc' ~~ { .contains('b') }
    'abc' ~~ m / b /
    'abc' ~~ rx / b /

Those four lines work basically the same, but for two different reasons.

The first one works because $_ is set to the left value, and True.ACCEPTS()
always returns True

The second one works because CODE.ACCEPTS() always runs the code with the
same parameter list.

The third one works for the same reason as the first one

The fourth one works for the same reason as the second one

1. Left side executed

    'abc' ~~   .contains('b')
    'abc' ~~ { .contains('b') }
    'abc' ~~ m  / b /
    'abc' ~~ rx / b /

2. Right side executed

    'abc' ~~  True
    'abc' ~~ { .contains('b') }
    'abc' ~~ True
    'abc' ~~ rx / b /

3. R-VALUE  .ACCEPTS( L-VALUE )

    True.ACCEPTS('abc')
    { .contains('b') }.ACCEPTS('abc')
    True.ACCEPTS('abc')
    rx / b /.ACCEPTS('abc')

Note again that CODE.ACCEPTS(VALUE) is the same as CODE.(VALUE).
(Note also that a regex is a code object.)

    True.ACCEPTS('abc')
    { .contains('b') }.('abc')
    True.ACCEPTS('abc')
    rx / b /.('abc')

---

So then why does this work?

    'abc' ~~ { S/b/./ }

As I said CODE.ACCEPTS() always runs CODE with the same parameter list.

    { S/b/./ }  .ACCEPTS( 'abc' )

    { S/b/./ }  .( 'abc' )

---

So why does the warning tell you to use `given` instead of what I just
wrote?

The ~~ is intended mostly for resolving some sort of truthiness.
So I just misused the feature for something it was not intended for.

`given` is intended for temporarily setting $_, so it is the appropriate
tool for the job.

    S/b/./ given 'abc'

If you don't like `given`, then just use `.subst()`

    'abc'.subst( 'b', '.' )

On Sun, Dec 8, 2019 at 1:32 AM William Michels <wjm1@caa.columbia.edu>
wrote:

> Apologies, looks like the smartmatch operator is listed in the
> Operator Precedence table (15th row: under "Chaining infix"):
>
> https://docs.raku.org/language/operators#Assignment_operators
>
> However, am I correct in stating that the assignment operator ("=3D") is
> on the 19th row ("Item assignment")? Therefore in the absence of
> parentheses, etc., all smartmatch operations take precedence over
> assignment operations?
>
> Best Regards, Bill.
>
>
> On Sat, Dec 7, 2019 at 10:27 PM William Michels <wjm1@caa.columbia.edu>
> wrote:
> >
> > Wow Brad, that's interesting and informative.
> >
> > I haven't seen the S/// operator before, so I had to look it up. On
> > the first page I found the docs say (quite informatively): "S/// uses
> > the same semantics as the s/// operator, except it leaves the original
> > string intact and returns the resultant string instead of $/ ($/ still
> > being set to the same values as with s///)."
> >
> > https://docs.raku.org/syntax/S$SOLIDUS$SOLIDUS$SOLIDUS
> >
> > I was then able to find an overview on regexes, which more explicitly
> > names the "S///" operator as "Non-disruptive substitution". I suppose
> > I could quibble and request that the phrase "Non-disruptive
> > substitution" be added to the operator page (above), but no
> > matter--it's easy enough to find:
> >
> > https://docs.raku.org/language/regexes#S///_non-destructive_substitutio=
n
> >
> > So I think I understand that (as Brad has said): "smartmatch with S///
> > (or TR///) is not useful." Conversely, I've also found another
> > smartmatch construct that is useless (i.e. disallowed):
> >
> > > my $r =3D 'abc' ~~ { S/b/./ }
> > a.c
> > > my $s =3D 'abc' ~~ { s/b/./ }
> > Cannot modify an immutable Str (abc)
> >   in block <unit> at <unknown file> line 1
> > >
> >
> > No matter how "discouraged' a particular syntax is, people are going
> > to run into these disallowed syntaxes and wonder why. Could it be due
> > to precedence? These two prohibited operations beg the question: can a
> > definitive statement be made regarding the precedence of the
> > smartmatch operator relative to either lowercase-triple-solidus
> > operators such as s/// and tr/// , or relative to
> > uppercase-triple-solidus operators such as S/// and TR/// ?
> >
> > This really makes me wonder if anyone has plans to add "~~" (the
> > smartmatch operator) to the precedence table that can be found
> > below--and where in the table the smartmatch operator would precisely
> > sit:
> >
> > https://docs.raku.org/language/operators#Operator_precedence
> >
> > Best Regards, Bill.
> >
> >
> >
> >
> > On Sat, Dec 7, 2019 at 7:53 AM Brad Gilbert <b2gills@gmail.com> wrote:
> > >
> > > The return value of s/// is the same as $/
> > >
> > > If you want the resulting string instead you can use S/// instead.
> > >
> > >     > $_ =3D 'abc'
> > >     > my $r =3D S/b/./
> > >     > say $r
> > >     a.c
> > >
> > > Note that it warns you try to use S/// with ~~
> > >
> > >     > my $r =3D 'abc' ~~ S/b/./
> > >     Potential difficulties:
> > >         Smartmatch with S/// is not useful. You can use given instead=
:
> S/// given $foo
> > >         ------> my $r =3D 'abc' ~~ S/b/./
> > >     False
> > >
> > > Which gives you an indicator of how to fix it
> > >
> > >     > my $r =3D S/b/./ given 'abc'
> > >     a.c
> > >
> > > Note that the `given` happens before the `=3D`
> > >
> > > So it works the same as
> > >
> > >     > my $r =3D ( S/b/./ given 'abc' )
> > >     a.c
> > >
> > > ---
> > >
> > > The reason ~~ doesn't work with S/// has to do with the dual pass
> nature of ~~.
> > >
> > > Without getting into details, you can avoid that by delaying the S///
> until the second pass.
> > >
> > >     > my $r =3D 'abc' ~~ { S/b/./ }
> > >     a.c
> > >
> > > Or you can just set $_ to the value.
> > > (Which is basically what the previous line is doing.)
> > >
> > >     > my $r =3D S/b/./ given 'abc'
> > >
> > >     > given 'abc' {
> > >     >   my $r =3D S/b/./
> > >     >   =E2=80=A6
> > >     > }
> > >
> > >     > my $_ =3D 'abc'
> > >     > my $r =3D S/b/./
> > >
> > >     > my $r =3D 'abc' ~~ -> $_ { S/b/./ }
> > >
> > >     > my $r =3D 'abc' ~~ sub ( $_ ) { S/b/./ }
> > >
> > >     > my $r =3D 'abc' ~~ anon sub foo ( $_ ) { S/b/./ }
> > > ---
> > >
> > > One of design goals of Raku is to have as few special cases as
> possible.
> > > Which is why ~~ and S/// haven't been made to just work.
> > >
> > > (It could be argued that in this case an exception could be made. But
> I'm not going to argue for it.)
> > >
> > > On Fri, Dec 6, 2019 at 10:37 PM William Michels via perl6-users <
> perl6-users@perl.org> wrote:
> > >>
> > >> Hello All,
> > >>
> > >> Todd put up some interesting code yesterday using the Raku/Perl6 REP=
L,
> > >> which I reproduced with no problem. Additionally I tried some
> > >> variations removing and/or moving parentheses to a different locatio=
n,
> > >> and have numbered the relevant REPL lines 1 through 6:
> > >>
> > >> mbook:~ homedir$ perl6
> > >> To exit type 'exit' or '^D'
> > >> 1> my $x =3D Q[word</b><br>] ;
> > >> word</b><br>
> > >> 2> (my $y =3D $x) ~~ s/ '<' .* //; say $/; say $x; say $y;
> > >> =EF=BD=A2</b><br>=EF=BD=A3
> > >> word</b><br>
> > >> word
> > >> 3> my $a =3D Q[word</b><br>] ;
> > >> word</b><br>
> > >> 4> my $b =3D ($a ~~ s/ '<' .* //); say $/; say $a; say $b;
> > >> =EF=BD=A2</b><br>=EF=BD=A3
> > >> word
> > >> =EF=BD=A2</b><br>=EF=BD=A3
> > >> > my $c =3D Q[word</b><br>] ;
> > >> word</b><br>
> > >> > my $d =3D $c ~~ s/ '<' .* //; say $/; say $c; say $d;
> > >> =EF=BD=A2</b><br>=EF=BD=A3
> > >> word
> > >> =EF=BD=A2</b><br>=EF=BD=A3
> > >> 7> $*VM
> > >> moar (2019.07.1)
> > >>
> > >> Working in groups of 2, lines 1 and 2 replicate the code Todd put up
> > >> (parenthesis surrounding everything to the left of the smartmatch
> > >> operator). I get the same result as Todd. What interests me are line=
s
> > >> 3 through 6. Lines 3 and 4 are the virtually the same code but with
> > >> parentheses surrounding everything to the right hand side (RHS) of t=
he
> > >> assignment operator (" =3D "). As people will note, lines 2 and line=
s 4
> > >> give different results. Removing parentheses entirely in line 6 give=
s
> > >> the same result as in line 4. Because the results in line 4 and line=
 6
> > >> are the same, this says that as far as parentheses are concerned, th=
e
> > >> smartmatch operator "~~" takes precedence over the assignment operat=
or
> > >> "=3D".
> > >>
> > >> What's not clear to me in the code above (lines 4 and 6) is why
> > >> variables $b and $d get assigned to $/. I would have expected in lin=
e
> > >> 4 that $a would have been matched against the smartmatch, and the
> > >> result ("word") would have been simply copied into variable $b. Have=
 I
> > >> misunderstood?
> > >>
> > >> Anyway, I'm just hoping to start a conversation on the topic of
> > >> precedence in general, and hopefully getting some feedback as to whe=
re
> > >> to look in the docs for further instruction.
> > >>
> > >> Best Regards, Bill.
> > >>
> > >>
> > >> On Fri, Dec 6, 2019 at 12:15 AM ToddAndMargo via perl6-users
> > >> <perl6-users@perl.org> wrote:
> > >> >
> > >> > On 2019-12-05 23:19, ToddAndMargo via perl6-users wrote:
> > >> > > On 2019-12-05 03:09, William Michels via perl6-users wrote:
> > >> > >> What happens when you type "perl6" or "raku" at the bash comman=
d
> prompt?
> > >> > >
> > >> > > Hi William,
> > >> > >
> > >> > > On my shop machine, it jumps to the next line with an
> > >> > > empty flashing cursor
> > >> > >
> > >> > > On my office machine, it told me to install
> > >> > >      zef install Readline
> > >> > >
> > >> > > After that, I get:
> > >> > >
> > >> > > $ perl6
> > >> > > To exit type 'exit' or '^D'
> > >> > >  >
> > >> > >
> > >> > > and
> > >> > >
> > >> > >  > say "hello World"
> > >> > > hello World
> > >> > >  > say "B" ~ Q[:\] ~ " drive dismounted"
> > >> > > B:\ drive dismounted
> > >> > >  >
> > >> > >
> > >> > > and sticking an obvious booboo into it
> > >> > >
> > >> > >  > if 3 % 2 =3D 1 {say "odd"};
> > >> > > Cannot modify an immutable Int (1)
> > >> > >    in block <unit> at <unknown file> line 1
> > >> > >
> > >> > > Plus I can use the arrow keys to recall previous lines too.
> > >> > >
> > >> > > Time up update my Perl6 on my shop computer!
> > >> > >
> > >> > > No more hassling with `perl6 -e` !!!
> > >> > >
> > >> > > Dude!  THANK YOU !!!!!!
> > >> > >
> > >> > > -T
> > >> >
> > >> > You've created a monster!!
> > >> >
> > >> > perl6
> > >> > To exit type 'exit' or '^D'
> > >> >  > my $x =3D Q[</b><br>]
> > >> > </b><br>
> > >> >  > say $x
> > >> > </b><br>
> > >> >  > (my $y =3D $x ) ~~ s/ Q[<] .* //;
> > >> > =3D=3D=3DSORRY!=3D=3D=3D Error while compiling:
> > >> > Unrecognized regex metacharacter < (must be quoted to match
> literally)
> > >> > ------> (my $y =3D $x ) ~~ s/ Q[<] .* //;
> > >> >  > my $x =3D Q[abc</b><br>]
> > >> > abc</b><br>
> > >> >  > (my $y =3D $x ) ~~ s/ '<' .* //;
> > >> > =EF=BD=A2</b><br>=EF=BD=A3
> > >> >  > (my $y =3D $x ) ~~ s/ '<' .* //; say $y
> > >> > abc
> > >> >  > (my $y =3D $x ) ~~ s/ '<' .* //; say $x; say $y
> > >> > abc</b><br>
> > >> > abc
> > >> >
> > >> >
> > >> > Thank you!
> > >> >
> > >> >
> > >> > --
> > >> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > >> > Computers are like air conditioners.
> > >> > They malfunction when you open windows
> > >> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>

--000000000000286d5d059937501f
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">smartmatch is among the most complex parts of the language=
..<div><br></div><div>That complexity has to managed or it will be too compl=
ex to use effectively.</div><div><br></div><div>To that end, the rules and =
order of operations are never altered.</div><div><br></div><div>1. The left=
 side is evaluated first, and the resulting value captured</div><div><br></=
div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 &gt; say(&#39;left&#39;) ~~ say(&#39;r=
ight&#39;)</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 left</div><div>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 right</div><div><br></div><div>2. $_ is temporarily set t=
o that value, and the right side is executed</div><div><br></div><div>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 &gt; &#39;ab&#39; ~ &#39;c&#39;=C2=A0 =C2=A0~~ say=
($_)</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 abc</div><div><br></div><div>3. =
The result of that execution is matched against the left value</div><div><b=
r></div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 &gt; &#39;abc&#39; ~~ &#39;abb&#39=
;.succ()</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 True</div><div><br></div><di=
v>=C2=A0 =C2=A0 Specifically `.ACCEPTS` is called with the left value.</div=
><div>=C2=A0 =C2=A0 So the following two lines are roughly equivalent.</div=
><div><br></div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 &gt; &#39;abc&#39;=C2=A0 =
=C2=A0~~=C2=A0 =C2=A0&#39;abb&#39;.succ()</div><div>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 &gt; &#39;abb&#39;.succ().ACCEPTS(&#39;abc&#39;)</div><div><br></div=
><div>So in the case of S/// and ~~ this is the order that things happen:</=
div><div><br></div><div>1. The left side is executed</div><div><br></div><d=
iv>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=AB a b c =C2=BB.join()=C2=A0 ~~=C2=A0 S/=
b/./</div><div><br></div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 &#39;abc&#39; ~~ =
S/b/./</div><div><br></div><div>2. $_ is temporarily set to that value, and=
 the right side is executed</div><div><br></div><div>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 &#39;abc&#39; ~~ S/b/./</div><div><br></div><div>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 &#39;abc&#39; ~~ &#39;a.c&#39;</div><div><br></div><div>3. the r=
esult of the right side is matched against the left value</div><div><br></d=
iv><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 &#39;abc&#39; ~~ &#39;a.c&#39;</div><di=
v><br></div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 &#39;a.c&#39;.ACCEPTS(&#39;abc=
&#39;) # False</div><div><br></div><div>So basically if S/// changes the va=
lue, the result is False.</div><div>If S/// doesn&#39;t change it, the resu=
lt is True.</div><div><br></div><div>Which means the following two lines ar=
e functionally identical.</div><div><br></div><div>=C2=A0 =C2=A0 &#39;abc&#=
39;=C2=A0 =C2=A0~~=C2=A0 S/b/./</div><div>=C2=A0 =C2=A0 &#39;abc&#39;=C2=A0=
 !~~=C2=A0 =C2=A0/b/</div><div><div><br></div><div>So the resulting value w=
ill never be the string you wanted!</div><div>It will be True or False.</di=
v></div><div><br></div><div>---</div><div><br></div><div>The reason for the=
 two stage execution is for the following.</div><div><br></div><div>=C2=A0 =
=C2=A0 &#39;abc&#39; ~~=C2=A0 =C2=A0.contains(&#39;b&#39;)</div><div>=C2=A0=
 =C2=A0 &#39;abc&#39; ~~ { .contains(&#39;b&#39;) }</div><div>=C2=A0 =C2=A0=
 &#39;abc&#39; ~~ m / b /</div><div>=C2=A0 =C2=A0 &#39;abc&#39; ~~ rx / b /=
</div><div><br></div><div>Those four lines work basically the same, but for=
 two different reasons.</div><div><br></div><div>The first one works becaus=
e $_ is set to the left value, and True.ACCEPTS() always returns True</div>=
<div><br></div><div>The second one works because CODE.ACCEPTS() always runs=
 the code with the same parameter list.</div><div><br></div><div>The third =
one works for the same reason as the first one</div><div><br></div><div>The=
 fourth one works for the same reason as the second one</div><div><br></div=
><div>1. Left side executed</div><div><br></div><div>=C2=A0 =C2=A0 &#39;abc=
&#39; ~~=C2=A0 =C2=A0.contains(&#39;b&#39;)</div><div>=C2=A0 =C2=A0 &#39;ab=
c&#39; ~~ { .contains(&#39;b&#39;) }</div>=C2=A0 =C2=A0 &#39;abc&#39; ~~ m=
=C2=A0 / b /<br>=C2=A0 =C2=A0 &#39;abc&#39; ~~ rx / b /<div></div><div><br>=
</div><div>2. Right side executed</div><div><div><br></div><div>=C2=A0 =C2=
=A0 &#39;abc&#39; ~~=C2=A0 True</div><div>=C2=A0 =C2=A0 &#39;abc&#39; ~~ { =
..contains(&#39;b&#39;) }</div>=C2=A0 =C2=A0 &#39;abc&#39; ~~ True<br>=C2=A0=
 =C2=A0 &#39;abc&#39; ~~ rx / b /<div><br></div><div>3. R-VALUE=C2=A0 .ACCE=
PTS( L-VALUE )</div><div><br></div><div>=C2=A0 =C2=A0 True.ACCEPTS(&#39;abc=
&#39;)</div><div>=C2=A0 =C2=A0 { .contains(&#39;b&#39;) }.ACCEPTS(&#39;abc&=
#39;)</div><div>=C2=A0 =C2=A0 True.ACCEPTS(&#39;abc&#39;)</div><div>=C2=A0 =
=C2=A0 rx / b /.ACCEPTS(&#39;abc&#39;)</div><div><br></div><div>Note again =
that CODE.ACCEPTS(VALUE) is the same as CODE.(VALUE).</div><div>(Note also =
that a regex is a code object.)</div><div><br>=C2=A0 =C2=A0 True.ACCEPTS(&#=
39;abc&#39;)<br>=C2=A0 =C2=A0 { .contains(&#39;b&#39;) }.(&#39;abc&#39;)<br=
>=C2=A0 =C2=A0 True.ACCEPTS(&#39;abc&#39;)<br>=C2=A0 =C2=A0 rx / b /.(&#39;=
abc&#39;)</div><div><br></div><div>---</div><div><br></div><div>So then why=
 does this work?</div><div><br></div><div>=C2=A0 =C2=A0 &#39;abc&#39; ~~ { =
S/b/./ }</div><div><br></div><div>As I said CODE.ACCEPTS() always runs CODE=
 with the same parameter list.</div><br><div></div></div><div>=C2=A0 =C2=A0=
 {=C2=A0S/b/./ }=C2=A0 .ACCEPTS( &#39;abc&#39; )</div><div><br></div><div>=
=C2=A0 =C2=A0=C2=A0{=C2=A0S/b/./ }=C2=A0 .( &#39;abc&#39; )</div><div><br><=
/div><div>---</div><div><br></div><div>So why does the warning tell you to =
use `given` instead of what I just wrote?</div><div><br></div><div>The ~~ i=
s intended mostly for resolving some sort of truthiness.</div><div>So I jus=
t misused the feature for something it was not intended for.</div><div><br>=
</div><div>`given` is intended for temporarily setting $_, so it is the app=
ropriate tool for the job.</div><div><br></div><div>=C2=A0 =C2=A0 S/b/./ gi=
ven &#39;abc&#39;</div><div><br></div><div>If you don&#39;t like `given`, t=
hen just use `.subst()`</div><div><br></div><div>=C2=A0 =C2=A0 &#39;abc&#39=
;.subst( &#39;b&#39;, &#39;.&#39; )</div></div><br><div class=3D"gmail_quot=
e"><div dir=3D"ltr" class=3D"gmail_attr">On Sun, Dec 8, 2019 at 1:32 AM Wil=
liam Michels &lt;<a href=3D"mailto:wjm1@caa.columbia.edu">wjm1@caa.columbia=
..edu</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"mar=
gin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1=
ex">Apologies, looks like the smartmatch operator is listed in the<br>
Operator Precedence table (15th row: under &quot;Chaining infix&quot;):<br>
<br>
<a href=3D"https://docs.raku.org/language/operators#Assignment_operators" r=
el=3D"noreferrer" target=3D"_blank">https://docs.raku.org/language/operator=
s#Assignment_operators</a><br>
<br>
However, am I correct in stating that the assignment operator (&quot;=3D&qu=
ot;) is<br>
on the 19th row (&quot;Item assignment&quot;)? Therefore in the absence of<=
br>
parentheses, etc., all smartmatch operations take precedence over<br>
assignment operations?<br>
<br>
Best Regards, Bill.<br>
<br>
<br>
On Sat, Dec 7, 2019 at 10:27 PM William Michels &lt;<a href=3D"mailto:wjm1@=
caa.columbia.edu" target=3D"_blank">wjm1@caa.columbia.edu</a>&gt; wrote:<br=
>
&gt;<br>
&gt; Wow Brad, that&#39;s interesting and informative.<br>
&gt;<br>
&gt; I haven&#39;t seen the S/// operator before, so I had to look it up. O=
n<br>
&gt; the first page I found the docs say (quite informatively): &quot;S/// =
uses<br>
&gt; the same semantics as the s/// operator, except it leaves the original=
<br>
&gt; string intact and returns the resultant string instead of $/ ($/ still=
<br>
&gt; being set to the same values as with s///).&quot;<br>
&gt;<br>
&gt; <a href=3D"https://docs.raku.org/syntax/S$SOLIDUS$SOLIDUS$SOLIDUS" rel=
=3D"noreferrer" target=3D"_blank">https://docs.raku.org/syntax/S$SOLIDUS$SO=
LIDUS$SOLIDUS</a><br>
&gt;<br>
&gt; I was then able to find an overview on regexes, which more explicitly<=
br>
&gt; names the &quot;S///&quot; operator as &quot;Non-disruptive substituti=
on&quot;. I suppose<br>
&gt; I could quibble and request that the phrase &quot;Non-disruptive<br>
&gt; substitution&quot; be added to the operator page (above), but no<br>
&gt; matter--it&#39;s easy enough to find:<br>
&gt;<br>
&gt; <a href=3D"https://docs.raku.org/language/regexes#S///_non-destructive=
_substitution" rel=3D"noreferrer" target=3D"_blank">https://docs.raku.org/l=
anguage/regexes#S///_non-destructive_substitution</a><br>
&gt;<br>
&gt; So I think I understand that (as Brad has said): &quot;smartmatch with=
 S///<br>
&gt; (or TR///) is not useful.&quot; Conversely, I&#39;ve also found anothe=
r<br>
&gt; smartmatch construct that is useless (i.e. disallowed):<br>
&gt;<br>
&gt; &gt; my $r =3D &#39;abc&#39; ~~ { S/b/./ }<br>
&gt; a.c<br>
&gt; &gt; my $s =3D &#39;abc&#39; ~~ { s/b/./ }<br>
&gt; Cannot modify an immutable Str (abc)<br>
&gt;=C2=A0 =C2=A0in block &lt;unit&gt; at &lt;unknown file&gt; line 1<br>
&gt; &gt;<br>
&gt;<br>
&gt; No matter how &quot;discouraged&#39; a particular syntax is, people ar=
e going<br>
&gt; to run into these disallowed syntaxes and wonder why. Could it be due<=
br>
&gt; to precedence? These two prohibited operations beg the question: can a=
<br>
&gt; definitive statement be made regarding the precedence of the<br>
&gt; smartmatch operator relative to either lowercase-triple-solidus<br>
&gt; operators such as s/// and tr/// , or relative to<br>
&gt; uppercase-triple-solidus operators such as S/// and TR/// ?<br>
&gt;<br>
&gt; This really makes me wonder if anyone has plans to add &quot;~~&quot; =
(the<br>
&gt; smartmatch operator) to the precedence table that can be found<br>
&gt; below--and where in the table the smartmatch operator would precisely<=
br>
&gt; sit:<br>
&gt;<br>
&gt; <a href=3D"https://docs.raku.org/language/operators#Operator_precedenc=
e" rel=3D"noreferrer" target=3D"_blank">https://docs.raku.org/language/oper=
ators#Operator_precedence</a><br>
&gt;<br>
&gt; Best Regards, Bill.<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On Sat, Dec 7, 2019 at 7:53 AM Brad Gilbert &lt;<a href=3D"mailto:b2gi=
lls@gmail.com" target=3D"_blank">b2gills@gmail.com</a>&gt; wrote:<br>
&gt; &gt;<br>
&gt; &gt; The return value of s/// is the same as $/<br>
&gt; &gt;<br>
&gt; &gt; If you want the resulting string instead you can use S/// instead=
..<br>
&gt; &gt;<br>
&gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt; $_ =3D &#39;abc&#39;<br>
&gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt; my $r =3D S/b/./<br>
&gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt; say $r<br>
&gt; &gt;=C2=A0 =C2=A0 =C2=A0a.c<br>
&gt; &gt;<br>
&gt; &gt; Note that it warns you try to use S/// with ~~<br>
&gt; &gt;<br>
&gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt; my $r =3D &#39;abc&#39; ~~ S/b/./<br>
&gt; &gt;=C2=A0 =C2=A0 =C2=A0Potential difficulties:<br>
&gt; &gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Smartmatch with S/// is not usef=
ul. You can use given instead: S/// given $foo<br>
&gt; &gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0------&gt; my $r =3D &#39;abc&#3=
9; ~~ S/b/./<br>
&gt; &gt;=C2=A0 =C2=A0 =C2=A0False<br>
&gt; &gt;<br>
&gt; &gt; Which gives you an indicator of how to fix it<br>
&gt; &gt;<br>
&gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt; my $r =3D S/b/./ given &#39;abc&#39;<br>
&gt; &gt;=C2=A0 =C2=A0 =C2=A0a.c<br>
&gt; &gt;<br>
&gt; &gt; Note that the `given` happens before the `=3D`<br>
&gt; &gt;<br>
&gt; &gt; So it works the same as<br>
&gt; &gt;<br>
&gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt; my $r =3D ( S/b/./ given &#39;abc&#39; )<=
br>
&gt; &gt;=C2=A0 =C2=A0 =C2=A0a.c<br>
&gt; &gt;<br>
&gt; &gt; ---<br>
&gt; &gt;<br>
&gt; &gt; The reason ~~ doesn&#39;t work with S/// has to do with the dual =
pass nature of ~~.<br>
&gt; &gt;<br>
&gt; &gt; Without getting into details, you can avoid that by delaying the =
S/// until the second pass.<br>
&gt; &gt;<br>
&gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt; my $r =3D &#39;abc&#39; ~~ { S/b/./ }<br>
&gt; &gt;=C2=A0 =C2=A0 =C2=A0a.c<br>
&gt; &gt;<br>
&gt; &gt; Or you can just set $_ to the value.<br>
&gt; &gt; (Which is basically what the previous line is doing.)<br>
&gt; &gt;<br>
&gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt; my $r =3D S/b/./ given &#39;abc&#39;<br>
&gt; &gt;<br>
&gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt; given &#39;abc&#39; {<br>
&gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt;=C2=A0 =C2=A0my $r =3D S/b/./<br>
&gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt;=C2=A0 =C2=A0=E2=80=A6<br>
&gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt; }<br>
&gt; &gt;<br>
&gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt; my $_ =3D &#39;abc&#39;<br>
&gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt; my $r =3D S/b/./<br>
&gt; &gt;<br>
&gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt; my $r =3D &#39;abc&#39; ~~ -&gt; $_ { S/b=
/./ }<br>
&gt; &gt;<br>
&gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt; my $r =3D &#39;abc&#39; ~~ sub ( $_ ) { S=
/b/./ }<br>
&gt; &gt;<br>
&gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt; my $r =3D &#39;abc&#39; ~~ anon sub foo (=
 $_ ) { S/b/./ }<br>
&gt; &gt; ---<br>
&gt; &gt;<br>
&gt; &gt; One of design goals of Raku is to have as few special cases as po=
ssible.<br>
&gt; &gt; Which is why ~~ and S/// haven&#39;t been made to just work.<br>
&gt; &gt;<br>
&gt; &gt; (It could be argued that in this case an exception could be made.=
 But I&#39;m not going to argue for it.)<br>
&gt; &gt;<br>
&gt; &gt; On Fri, Dec 6, 2019 at 10:37 PM William Michels via perl6-users &=
lt;<a href=3D"mailto:perl6-users@perl.org" target=3D"_blank">perl6-users@pe=
rl.org</a>&gt; wrote:<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; Hello All,<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; Todd put up some interesting code yesterday using the Raku/Pe=
rl6 REPL,<br>
&gt; &gt;&gt; which I reproduced with no problem. Additionally I tried some=
<br>
&gt; &gt;&gt; variations removing and/or moving parentheses to a different =
location,<br>
&gt; &gt;&gt; and have numbered the relevant REPL lines 1 through 6:<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; mbook:~ homedir$ perl6<br>
&gt; &gt;&gt; To exit type &#39;exit&#39; or &#39;^D&#39;<br>
&gt; &gt;&gt; 1&gt; my $x =3D Q[word&lt;/b&gt;&lt;br&gt;] ;<br>
&gt; &gt;&gt; word&lt;/b&gt;&lt;br&gt;<br>
&gt; &gt;&gt; 2&gt; (my $y =3D $x) ~~ s/ &#39;&lt;&#39; .* //; say $/; say =
$x; say $y;<br>
&gt; &gt;&gt; =EF=BD=A2&lt;/b&gt;&lt;br&gt;=EF=BD=A3<br>
&gt; &gt;&gt; word&lt;/b&gt;&lt;br&gt;<br>
&gt; &gt;&gt; word<br>
&gt; &gt;&gt; 3&gt; my $a =3D Q[word&lt;/b&gt;&lt;br&gt;] ;<br>
&gt; &gt;&gt; word&lt;/b&gt;&lt;br&gt;<br>
&gt; &gt;&gt; 4&gt; my $b =3D ($a ~~ s/ &#39;&lt;&#39; .* //); say $/; say =
$a; say $b;<br>
&gt; &gt;&gt; =EF=BD=A2&lt;/b&gt;&lt;br&gt;=EF=BD=A3<br>
&gt; &gt;&gt; word<br>
&gt; &gt;&gt; =EF=BD=A2&lt;/b&gt;&lt;br&gt;=EF=BD=A3<br>
&gt; &gt;&gt; &gt; my $c =3D Q[word&lt;/b&gt;&lt;br&gt;] ;<br>
&gt; &gt;&gt; word&lt;/b&gt;&lt;br&gt;<br>
&gt; &gt;&gt; &gt; my $d =3D $c ~~ s/ &#39;&lt;&#39; .* //; say $/; say $c;=
 say $d;<br>
&gt; &gt;&gt; =EF=BD=A2&lt;/b&gt;&lt;br&gt;=EF=BD=A3<br>
&gt; &gt;&gt; word<br>
&gt; &gt;&gt; =EF=BD=A2&lt;/b&gt;&lt;br&gt;=EF=BD=A3<br>
&gt; &gt;&gt; 7&gt; $*VM<br>
&gt; &gt;&gt; moar (2019.07.1)<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; Working in groups of 2, lines 1 and 2 replicate the code Todd=
 put up<br>
&gt; &gt;&gt; (parenthesis surrounding everything to the left of the smartm=
atch<br>
&gt; &gt;&gt; operator). I get the same result as Todd. What interests me a=
re lines<br>
&gt; &gt;&gt; 3 through 6. Lines 3 and 4 are the virtually the same code bu=
t with<br>
&gt; &gt;&gt; parentheses surrounding everything to the right hand side (RH=
S) of the<br>
&gt; &gt;&gt; assignment operator (&quot; =3D &quot;). As people will note,=
 lines 2 and lines 4<br>
&gt; &gt;&gt; give different results. Removing parentheses entirely in line=
 6 gives<br>
&gt; &gt;&gt; the same result as in line 4. Because the results in line 4 a=
nd line 6<br>
&gt; &gt;&gt; are the same, this says that as far as parentheses are concer=
ned, the<br>
&gt; &gt;&gt; smartmatch operator &quot;~~&quot; takes precedence over the =
assignment operator<br>
&gt; &gt;&gt; &quot;=3D&quot;.<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; What&#39;s not clear to me in the code above (lines 4 and 6) =
is why<br>
&gt; &gt;&gt; variables $b and $d get assigned to $/. I would have expected=
 in line<br>
&gt; &gt;&gt; 4 that $a would have been matched against the smartmatch, and=
 the<br>
&gt; &gt;&gt; result (&quot;word&quot;) would have been simply copied into =
variable $b. Have I<br>
&gt; &gt;&gt; misunderstood?<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; Anyway, I&#39;m just hoping to start a conversation on the to=
pic of<br>
&gt; &gt;&gt; precedence in general, and hopefully getting some feedback as=
 to where<br>
&gt; &gt;&gt; to look in the docs for further instruction.<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; Best Regards, Bill.<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; On Fri, Dec 6, 2019 at 12:15 AM ToddAndMargo via perl6-users<=
br>
&gt; &gt;&gt; &lt;<a href=3D"mailto:perl6-users@perl.org" target=3D"_blank"=
>perl6-users@perl.org</a>&gt; wrote:<br>
&gt; &gt;&gt; &gt;<br>
&gt; &gt;&gt; &gt; On 2019-12-05 23:19, ToddAndMargo via perl6-users wrote:=
<br>
&gt; &gt;&gt; &gt; &gt; On 2019-12-05 03:09, William Michels via perl6-user=
s wrote:<br>
&gt; &gt;&gt; &gt; &gt;&gt; What happens when you type &quot;perl6&quot; or=
 &quot;raku&quot; at the bash command prompt?<br>
&gt; &gt;&gt; &gt; &gt;<br>
&gt; &gt;&gt; &gt; &gt; Hi William,<br>
&gt; &gt;&gt; &gt; &gt;<br>
&gt; &gt;&gt; &gt; &gt; On my shop machine, it jumps to the next line with =
an<br>
&gt; &gt;&gt; &gt; &gt; empty flashing cursor<br>
&gt; &gt;&gt; &gt; &gt;<br>
&gt; &gt;&gt; &gt; &gt; On my office machine, it told me to install<br>
&gt; &gt;&gt; &gt; &gt;=C2=A0 =C2=A0 =C2=A0 zef install Readline<br>
&gt; &gt;&gt; &gt; &gt;<br>
&gt; &gt;&gt; &gt; &gt; After that, I get:<br>
&gt; &gt;&gt; &gt; &gt;<br>
&gt; &gt;&gt; &gt; &gt; $ perl6<br>
&gt; &gt;&gt; &gt; &gt; To exit type &#39;exit&#39; or &#39;^D&#39;<br>
&gt; &gt;&gt; &gt; &gt;=C2=A0 &gt;<br>
&gt; &gt;&gt; &gt; &gt;<br>
&gt; &gt;&gt; &gt; &gt; and<br>
&gt; &gt;&gt; &gt; &gt;<br>
&gt; &gt;&gt; &gt; &gt;=C2=A0 &gt; say &quot;hello World&quot;<br>
&gt; &gt;&gt; &gt; &gt; hello World<br>
&gt; &gt;&gt; &gt; &gt;=C2=A0 &gt; say &quot;B&quot; ~ Q[:\] ~ &quot; drive=
 dismounted&quot;<br>
&gt; &gt;&gt; &gt; &gt; B:\ drive dismounted<br>
&gt; &gt;&gt; &gt; &gt;=C2=A0 &gt;<br>
&gt; &gt;&gt; &gt; &gt;<br>
&gt; &gt;&gt; &gt; &gt; and sticking an obvious booboo into it<br>
&gt; &gt;&gt; &gt; &gt;<br>
&gt; &gt;&gt; &gt; &gt;=C2=A0 &gt; if 3 % 2 =3D 1 {say &quot;odd&quot;};<br=
>
&gt; &gt;&gt; &gt; &gt; Cannot modify an immutable Int (1)<br>
&gt; &gt;&gt; &gt; &gt;=C2=A0 =C2=A0 in block &lt;unit&gt; at &lt;unknown f=
ile&gt; line 1<br>
&gt; &gt;&gt; &gt; &gt;<br>
&gt; &gt;&gt; &gt; &gt; Plus I can use the arrow keys to recall previous li=
nes too.<br>
&gt; &gt;&gt; &gt; &gt;<br>
&gt; &gt;&gt; &gt; &gt; Time up update my Perl6 on my shop computer!<br>
&gt; &gt;&gt; &gt; &gt;<br>
&gt; &gt;&gt; &gt; &gt; No more hassling with `perl6 -e` !!!<br>
&gt; &gt;&gt; &gt; &gt;<br>
&gt; &gt;&gt; &gt; &gt; Dude!=C2=A0 THANK YOU !!!!!!<br>
&gt; &gt;&gt; &gt; &gt;<br>
&gt; &gt;&gt; &gt; &gt; -T<br>
&gt; &gt;&gt; &gt;<br>
&gt; &gt;&gt; &gt; You&#39;ve created a monster!!<br>
&gt; &gt;&gt; &gt;<br>
&gt; &gt;&gt; &gt; perl6<br>
&gt; &gt;&gt; &gt; To exit type &#39;exit&#39; or &#39;^D&#39;<br>
&gt; &gt;&gt; &gt;=C2=A0 &gt; my $x =3D Q[&lt;/b&gt;&lt;br&gt;]<br>
&gt; &gt;&gt; &gt; &lt;/b&gt;&lt;br&gt;<br>
&gt; &gt;&gt; &gt;=C2=A0 &gt; say $x<br>
&gt; &gt;&gt; &gt; &lt;/b&gt;&lt;br&gt;<br>
&gt; &gt;&gt; &gt;=C2=A0 &gt; (my $y =3D $x ) ~~ s/ Q[&lt;] .* //;<br>
&gt; &gt;&gt; &gt; =3D=3D=3DSORRY!=3D=3D=3D Error while compiling:<br>
&gt; &gt;&gt; &gt; Unrecognized regex metacharacter &lt; (must be quoted to=
 match literally)<br>
&gt; &gt;&gt; &gt; ------&gt; (my $y =3D $x ) ~~ s/ Q[&lt;] .* //;<br>
&gt; &gt;&gt; &gt;=C2=A0 &gt; my $x =3D Q[abc&lt;/b&gt;&lt;br&gt;]<br>
&gt; &gt;&gt; &gt; abc&lt;/b&gt;&lt;br&gt;<br>
&gt; &gt;&gt; &gt;=C2=A0 &gt; (my $y =3D $x ) ~~ s/ &#39;&lt;&#39; .* //;<b=
r>
&gt; &gt;&gt; &gt; =EF=BD=A2&lt;/b&gt;&lt;br&gt;=EF=BD=A3<br>
&gt; &gt;&gt; &gt;=C2=A0 &gt; (my $y =3D $x ) ~~ s/ &#39;&lt;&#39; .* //; s=
ay $y<br>
&gt; &gt;&gt; &gt; abc<br>
&gt; &gt;&gt; &gt;=C2=A0 &gt; (my $y =3D $x ) ~~ s/ &#39;&lt;&#39; .* //; s=
ay $x; say $y<br>
&gt; &gt;&gt; &gt; abc&lt;/b&gt;&lt;br&gt;<br>
&gt; &gt;&gt; &gt; abc<br>
&gt; &gt;&gt; &gt;<br>
&gt; &gt;&gt; &gt;<br>
&gt; &gt;&gt; &gt; Thank you!<br>
&gt; &gt;&gt; &gt;<br>
&gt; &gt;&gt; &gt;<br>
&gt; &gt;&gt; &gt; --<br>
&gt; &gt;&gt; &gt; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
&gt; &gt;&gt; &gt; Computers are like air conditioners.<br>
&gt; &gt;&gt; &gt; They malfunction when you open windows<br>
&gt; &gt;&gt; &gt; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
</blockquote></div>

--000000000000286d5d059937501f--
0
b2gills
12/8/2019 8:41:59 PM
Thank you Brad, for your in-depth reply.

There are parts of your reply that make perfect sense to me, and also
parts where I am still confused. I feel I understand your first three
examples (1,2,3) explaining how the smartmatch operator relates to
ACCEPTS(). However in the second three examples explaining "S///"
(also numbered 1,2,3), I'm confused on Your Step 2. I've tried
numerous examples, a few of which are reproduced below:

mbook:~ homedir$ perl6
To exit type 'exit' or '^D'
1> my $a =3D =C2=AB a b c =C2=BB.join()
abc
2> say $a ~~ s/b/y/
=EF=BD=A2b=EF=BD=A3
3> say $a
ayc
4> my $probe =3D "AGCT"
AGCT
5 > say $/ if $probe ~~ /"TCGA"/ ;
()
6> say $/ if $probe ~~ /"AGCT"/ ;
=EF=BD=A2AGCT=EF=BD=A3
7> say $/ if $probe ~~ s/"AGCT"/"TCGA"/ ;
=EF=BD=A2AGCT=EF=BD=A3
8> say $probe
"TCGA"
9> say $/ if $probe ~~ S/"TCGA"/"AGCT"/ ;
Potential difficulties:
    Smartmatch with S/// is not useful. You can use given instead:
S/// given $foo
    ------> say $/ if $probe ~~ S/"TCGA"/"AGCT"/ ;
()
10> say $probe
"TCGA"
11> say $_
abc
12> $*VM
moar (2019.07.1)
>

For "S///" in your Step 1 the LHS is evaluated first (your Join
example) and the LHS is temporarily set to $_. Then (your Step 2) the
RHS is evaluated. Do you mean the RHS is evaluated in the context of
$_ from the LHS?? Using your "abc" example I don't understand--if you
**solely** look at the "S/b/./" operation--how  the letters "a" and
"c" show up in your Step 2 intermediate result. Of course, Raku/Perl6
may be far cleverer than I imagined--clever enough based on position
and regex-rules (maybe) to simplify the two sides of the "S///"
operator into a simple formula that can then be applied to the LHS.

So in pseudocode, are you saying the following regarding "s///"
(destructive-substitution) operation?

1. LHS:
eval( "probe" ) --> $_ ;

2. RHS regex "target" between first two solidi of s/// or S/// :
eval( "target".ACCEPTS( $_) );

3. for s///, if above evaluates to TRUE match from above gets assigned
to $/ and LHS "probe" gets overwritten with appropriate "substitution"
characters between second two solidi of s/// or S/// :
( "match" --> $/ ) ; ( RHS_"substitution" --> "probe" ) ;

[ 4. for S///, there is no possibility that Step 2 will evaluate to
TRUE, so $/ is Nil and LHS "probe" remains as unchanged ].

If I'm close, please let me know. Meanwhile I will: 1) read over what
you wrote again, and 2) play around with a little more example code,
to gain a better understanding of what Raku/Perl6 is doing
under-the-hood.

Best Regards, Bill.



On Sun, Dec 8, 2019 at 12:42 PM Brad Gilbert <b2gills@gmail.com> wrote:
>
> smartmatch is among the most complex parts of the language.
>
> That complexity has to managed or it will be too complex to use effective=
ly.
>
> To that end, the rules and order of operations are never altered.
>
> 1. The left side is evaluated first, and the resulting value captured
>
>         > say('left') ~~ say('right')
>         left
>         right
>
> 2. $_ is temporarily set to that value, and the right side is executed
>
>         > 'ab' ~ 'c'   ~~ say($_)
>         abc
>
> 3. The result of that execution is matched against the left value
>
>         > 'abc' ~~ 'abb'.succ()
>         True
>
>     Specifically `.ACCEPTS` is called with the left value.
>     So the following two lines are roughly equivalent.
>
>         > 'abc'   ~~   'abb'.succ()
>         > 'abb'.succ().ACCEPTS('abc')
>
> So in the case of S/// and ~~ this is the order that things happen:
>
> 1. The left side is executed
>
>         =C2=AB a b c =C2=BB.join()  ~~  S/b/./
>
>         'abc' ~~ S/b/./
>
> 2. $_ is temporarily set to that value, and the right side is executed
>
>         'abc' ~~ S/b/./
>
>         'abc' ~~ 'a.c'
>
> 3. the result of the right side is matched against the left value
>
>         'abc' ~~ 'a.c'
>
>         'a.c'.ACCEPTS('abc') # False
>
> So basically if S/// changes the value, the result is False.
> If S/// doesn't change it, the result is True.
>
> Which means the following two lines are functionally identical.
>
>     'abc'   ~~  S/b/./
>     'abc'  !~~   /b/
>
> So the resulting value will never be the string you wanted!
> It will be True or False.
>
> ---
>
> The reason for the two stage execution is for the following.
>
>     'abc' ~~   .contains('b')
>     'abc' ~~ { .contains('b') }
>     'abc' ~~ m / b /
>     'abc' ~~ rx / b /
>
> Those four lines work basically the same, but for two different reasons.
>
> The first one works because $_ is set to the left value, and True.ACCEPTS=
() always returns True
>
> The second one works because CODE.ACCEPTS() always runs the code with the=
 same parameter list.
>
> The third one works for the same reason as the first one
>
> The fourth one works for the same reason as the second one
>
> 1. Left side executed
>
>     'abc' ~~   .contains('b')
>     'abc' ~~ { .contains('b') }
>     'abc' ~~ m  / b /
>     'abc' ~~ rx / b /
>
> 2. Right side executed
>
>     'abc' ~~  True
>     'abc' ~~ { .contains('b') }
>     'abc' ~~ True
>     'abc' ~~ rx / b /
>
> 3. R-VALUE  .ACCEPTS( L-VALUE )
>
>     True.ACCEPTS('abc')
>     { .contains('b') }.ACCEPTS('abc')
>     True.ACCEPTS('abc')
>     rx / b /.ACCEPTS('abc')
>
> Note again that CODE.ACCEPTS(VALUE) is the same as CODE.(VALUE).
> (Note also that a regex is a code object.)
>
>     True.ACCEPTS('abc')
>     { .contains('b') }.('abc')
>     True.ACCEPTS('abc')
>     rx / b /.('abc')
>
> ---
>
> So then why does this work?
>
>     'abc' ~~ { S/b/./ }
>
> As I said CODE.ACCEPTS() always runs CODE with the same parameter list.
>
>     { S/b/./ }  .ACCEPTS( 'abc' )
>
>     { S/b/./ }  .( 'abc' )
>
> ---
>
> So why does the warning tell you to use `given` instead of what I just wr=
ote?
>
> The ~~ is intended mostly for resolving some sort of truthiness.
> So I just misused the feature for something it was not intended for.
>
> `given` is intended for temporarily setting $_, so it is the appropriate =
tool for the job.
>
>     S/b/./ given 'abc'
>
> If you don't like `given`, then just use `.subst()`
>
>     'abc'.subst( 'b', '.' )
>
> On Sun, Dec 8, 2019 at 1:32 AM William Michels <wjm1@caa.columbia.edu> wr=
ote:
>>
>> Apologies, looks like the smartmatch operator is listed in the
>> Operator Precedence table (15th row: under "Chaining infix"):
>>
>> https://docs.raku.org/language/operators#Assignment_operators
>>
>> However, am I correct in stating that the assignment operator ("=3D") is
>> on the 19th row ("Item assignment")? Therefore in the absence of
>> parentheses, etc., all smartmatch operations take precedence over
>> assignment operations?
>>
>> Best Regards, Bill.
>>
>>
>> On Sat, Dec 7, 2019 at 10:27 PM William Michels <wjm1@caa.columbia.edu> =
wrote:
>> >
>> > Wow Brad, that's interesting and informative.
>> >
>> > I haven't seen the S/// operator before, so I had to look it up. On
>> > the first page I found the docs say (quite informatively): "S/// uses
>> > the same semantics as the s/// operator, except it leaves the original
>> > string intact and returns the resultant string instead of $/ ($/ still
>> > being set to the same values as with s///)."
>> >
>> > https://docs.raku.org/syntax/S$SOLIDUS$SOLIDUS$SOLIDUS
>> >
>> > I was then able to find an overview on regexes, which more explicitly
>> > names the "S///" operator as "Non-disruptive substitution". I suppose
>> > I could quibble and request that the phrase "Non-disruptive
>> > substitution" be added to the operator page (above), but no
>> > matter--it's easy enough to find:
>> >
>> > https://docs.raku.org/language/regexes#S///_non-destructive_substituti=
on
>> >
>> > So I think I understand that (as Brad has said): "smartmatch with S///
>> > (or TR///) is not useful." Conversely, I've also found another
>> > smartmatch construct that is useless (i.e. disallowed):
>> >
>> > > my $r =3D 'abc' ~~ { S/b/./ }
>> > a.c
>> > > my $s =3D 'abc' ~~ { s/b/./ }
>> > Cannot modify an immutable Str (abc)
>> >   in block <unit> at <unknown file> line 1
>> > >
>> >
>> > No matter how "discouraged' a particular syntax is, people are going
>> > to run into these disallowed syntaxes and wonder why. Could it be due
>> > to precedence? These two prohibited operations beg the question: can a
>> > definitive statement be made regarding the precedence of the
>> > smartmatch operator relative to either lowercase-triple-solidus
>> > operators such as s/// and tr/// , or relative to
>> > uppercase-triple-solidus operators such as S/// and TR/// ?
>> >
>> > This really makes me wonder if anyone has plans to add "~~" (the
>> > smartmatch operator) to the precedence table that can be found
>> > below--and where in the table the smartmatch operator would precisely
>> > sit:
>> >
>> > https://docs.raku.org/language/operators#Operator_precedence
>> >
>> > Best Regards, Bill.
>> >
>> >
>> >
>> >
>> > On Sat, Dec 7, 2019 at 7:53 AM Brad Gilbert <b2gills@gmail.com> wrote:
>> > >
>> > > The return value of s/// is the same as $/
>> > >
>> > > If you want the resulting string instead you can use S/// instead.
>> > >
>> > >     > $_ =3D 'abc'
>> > >     > my $r =3D S/b/./
>> > >     > say $r
>> > >     a.c
>> > >
>> > > Note that it warns you try to use S/// with ~~
>> > >
>> > >     > my $r =3D 'abc' ~~ S/b/./
>> > >     Potential difficulties:
>> > >         Smartmatch with S/// is not useful. You can use given instea=
d: S/// given $foo
>> > >         ------> my $r =3D 'abc' ~~ S/b/./
>> > >     False
>> > >
>> > > Which gives you an indicator of how to fix it
>> > >
>> > >     > my $r =3D S/b/./ given 'abc'
>> > >     a.c
>> > >
>> > > Note that the `given` happens before the `=3D`
>> > >
>> > > So it works the same as
>> > >
>> > >     > my $r =3D ( S/b/./ given 'abc' )
>> > >     a.c
>> > >
>> > > ---
>> > >
>> > > The reason ~~ doesn't work with S/// has to do with the dual pass na=
ture of ~~.
>> > >
>> > > Without getting into details, you can avoid that by delaying the S//=
/ until the second pass.
>> > >
>> > >     > my $r =3D 'abc' ~~ { S/b/./ }
>> > >     a.c
>> > >
>> > > Or you can just set $_ to the value.
>> > > (Which is basically what the previous line is doing.)
>> > >
>> > >     > my $r =3D S/b/./ given 'abc'
>> > >
>> > >     > given 'abc' {
>> > >     >   my $r =3D S/b/./
>> > >     >   =E2=80=A6
>> > >     > }
>> > >
>> > >     > my $_ =3D 'abc'
>> > >     > my $r =3D S/b/./
>> > >
>> > >     > my $r =3D 'abc' ~~ -> $_ { S/b/./ }
>> > >
>> > >     > my $r =3D 'abc' ~~ sub ( $_ ) { S/b/./ }
>> > >
>> > >     > my $r =3D 'abc' ~~ anon sub foo ( $_ ) { S/b/./ }
>> > > ---
>> > >
>> > > One of design goals of Raku is to have as few special cases as possi=
ble.
>> > > Which is why ~~ and S/// haven't been made to just work.
>> > >
>> > > (It could be argued that in this case an exception could be made. Bu=
t I'm not going to argue for it.)
>> > >
>> > > On Fri, Dec 6, 2019 at 10:37 PM William Michels via perl6-users <per=
l6-users@perl.org> wrote:
>> > >>
>> > >> Hello All,
>> > >>
>> > >> Todd put up some interesting code yesterday using the Raku/Perl6 RE=
PL,
>> > >> which I reproduced with no problem. Additionally I tried some
>> > >> variations removing and/or moving parentheses to a different locati=
on,
>> > >> and have numbered the relevant REPL lines 1 through 6:
>> > >>
>> > >> mbook:~ homedir$ perl6
>> > >> To exit type 'exit' or '^D'
>> > >> 1> my $x =3D Q[word</b><br>] ;
>> > >> word</b><br>
>> > >> 2> (my $y =3D $x) ~~ s/ '<' .* //; say $/; say $x; say $y;
>> > >> =EF=BD=A2</b><br>=EF=BD=A3
>> > >> word</b><br>
>> > >> word
>> > >> 3> my $a =3D Q[word</b><br>] ;
>> > >> word</b><br>
>> > >> 4> my $b =3D ($a ~~ s/ '<' .* //); say $/; say $a; say $b;
>> > >> =EF=BD=A2</b><br>=EF=BD=A3
>> > >> word
>> > >> =EF=BD=A2</b><br>=EF=BD=A3
>> > >> > my $c =3D Q[word</b><br>] ;
>> > >> word</b><br>
>> > >> > my $d =3D $c ~~ s/ '<' .* //; say $/; say $c; say $d;
>> > >> =EF=BD=A2</b><br>=EF=BD=A3
>> > >> word
>> > >> =EF=BD=A2</b><br>=EF=BD=A3
>> > >> 7> $*VM
>> > >> moar (2019.07.1)
>> > >>
>> > >> Working in groups of 2, lines 1 and 2 replicate the code Todd put u=
p
>> > >> (parenthesis surrounding everything to the left of the smartmatch
>> > >> operator). I get the same result as Todd. What interests me are lin=
es
>> > >> 3 through 6. Lines 3 and 4 are the virtually the same code but with
>> > >> parentheses surrounding everything to the right hand side (RHS) of =
the
>> > >> assignment operator (" =3D "). As people will note, lines 2 and lin=
es 4
>> > >> give different results. Removing parentheses entirely in line 6 giv=
es
>> > >> the same result as in line 4. Because the results in line 4 and lin=
e 6
>> > >> are the same, this says that as far as parentheses are concerned, t=
he
>> > >> smartmatch operator "~~" takes precedence over the assignment opera=
tor
>> > >> "=3D".
>> > >>
>> > >> What's not clear to me in the code above (lines 4 and 6) is why
>> > >> variables $b and $d get assigned to $/. I would have expected in li=
ne
>> > >> 4 that $a would have been matched against the smartmatch, and the
>> > >> result ("word") would have been simply copied into variable $b. Hav=
e I
>> > >> misunderstood?
>> > >>
>> > >> Anyway, I'm just hoping to start a conversation on the topic of
>> > >> precedence in general, and hopefully getting some feedback as to wh=
ere
>> > >> to look in the docs for further instruction.
>> > >>
>> > >> Best Regards, Bill.
>> > >>
>> > >>
>> > >> On Fri, Dec 6, 2019 at 12:15 AM ToddAndMargo via perl6-users
>> > >> <perl6-users@perl.org> wrote:
>> > >> >
>> > >> > On 2019-12-05 23:19, ToddAndMargo via perl6-users wrote:
>> > >> > > On 2019-12-05 03:09, William Michels via perl6-users wrote:
>> > >> > >> What happens when you type "perl6" or "raku" at the bash comma=
nd prompt?
>> > >> > >
>> > >> > > Hi William,
>> > >> > >
>> > >> > > On my shop machine, it jumps to the next line with an
>> > >> > > empty flashing cursor
>> > >> > >
>> > >> > > On my office machine, it told me to install
>> > >> > >      zef install Readline
>> > >> > >
>> > >> > > After that, I get:
>> > >> > >
>> > >> > > $ perl6
>> > >> > > To exit type 'exit' or '^D'
>> > >> > >  >
>> > >> > >
>> > >> > > and
>> > >> > >
>> > >> > >  > say "hello World"
>> > >> > > hello World
>> > >> > >  > say "B" ~ Q[:\] ~ " drive dismounted"
>> > >> > > B:\ drive dismounted
>> > >> > >  >
>> > >> > >
>> > >> > > and sticking an obvious booboo into it
>> > >> > >
>> > >> > >  > if 3 % 2 =3D 1 {say "odd"};
>> > >> > > Cannot modify an immutable Int (1)
>> > >> > >    in block <unit> at <unknown file> line 1
>> > >> > >
>> > >> > > Plus I can use the arrow keys to recall previous lines too.
>> > >> > >
>> > >> > > Time up update my Perl6 on my shop computer!
>> > >> > >
>> > >> > > No more hassling with `perl6 -e` !!!
>> > >> > >
>> > >> > > Dude!  THANK YOU !!!!!!
>> > >> > >
>> > >> > > -T
>> > >> >
>> > >> > You've created a monster!!
>> > >> >
>> > >> > perl6
>> > >> > To exit type 'exit' or '^D'
>> > >> >  > my $x =3D Q[</b><br>]
>> > >> > </b><br>
>> > >> >  > say $x
>> > >> > </b><br>
>> > >> >  > (my $y =3D $x ) ~~ s/ Q[<] .* //;
>> > >> > =3D=3D=3DSORRY!=3D=3D=3D Error while compiling:
>> > >> > Unrecognized regex metacharacter < (must be quoted to match liter=
ally)
>> > >> > ------> (my $y =3D $x ) ~~ s/ Q[<] .* //;
>> > >> >  > my $x =3D Q[abc</b><br>]
>> > >> > abc</b><br>
>> > >> >  > (my $y =3D $x ) ~~ s/ '<' .* //;
>> > >> > =EF=BD=A2</b><br>=EF=BD=A3
>> > >> >  > (my $y =3D $x ) ~~ s/ '<' .* //; say $y
>> > >> > abc
>> > >> >  > (my $y =3D $x ) ~~ s/ '<' .* //; say $x; say $y
>> > >> > abc</b><br>
>> > >> > abc
>> > >> >
>> > >> >
>> > >> > Thank you!
>> > >> >
>> > >> >
>> > >> > --
>> > >> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> > >> > Computers are like air conditioners.
>> > >> > They malfunction when you open windows
>> > >> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0
perl6
12/10/2019 1:33:58 AM
--0000000000000db6c805994feea0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

I meant that $_ is set to the left value while the right value is being
evaluated, and also while .ACCEPTS is called.

    LEFT ~~ RIGHT

(Where LEFT and RIGHT represent some expression to be executed during
runtime.)

Imagine that underneath the hood, something like this is happening:

    my $L-value =3D LEFT.evaluate();

    given $L-value {
        # $_ is temporarily the result of the LEFT expression

        my $R-value =3D RIGHT.evaluate();
        return $R-value.ACCEPTS($L-value);
    }

So this:

    =C2=AB a b c =C2=BB.join()   ~~   S/b/y/

is functionally the same as:

    do given =C2=AB a b c =C2=BB.join() {
        my $R-value =3D S/b/y/;
        $R-value.ACCEPTS($_)
    }

Note that $R-value will be "ayc"

    "ayc".ACCEPTS("abc") =3D=3D False

---

    > $_.say
    (Any)

    > =C2=AB a b c =C2=BB.join()   ~~   -> $a { say "\$a =3D $a\n\$_ =3D $_=
" }
    $a =3D abc
    $_ =3D abc


    > =C2=AB a b c =C2=BB.join()   ~~   ($_.say, -> $a { say "\$a =3D $a\n\=
$_ =3D $_"
}).tail
    abc
    $a =3D abc
    $_ =3D abc

    > $_.say
    (Any)


On Mon, Dec 9, 2019 at 7:34 PM William Michels <wjm1@caa.columbia.edu>
wrote:

> Thank you Brad, for your in-depth reply.
>
> There are parts of your reply that make perfect sense to me, and also
> parts where I am still confused. I feel I understand your first three
> examples (1,2,3) explaining how the smartmatch operator relates to
> ACCEPTS(). However in the second three examples explaining "S///"
> (also numbered 1,2,3), I'm confused on Your Step 2. I've tried
> numerous examples, a few of which are reproduced below:
>
> mbook:~ homedir$ perl6
> To exit type 'exit' or '^D'
> 1> my $a =3D =C2=AB a b c =C2=BB.join()
> abc
> 2> say $a ~~ s/b/y/
> =EF=BD=A2b=EF=BD=A3
> 3> say $a
> ayc
> 4> my $probe =3D "AGCT"
> AGCT
> 5 > say $/ if $probe ~~ /"TCGA"/ ;
> ()
> 6> say $/ if $probe ~~ /"AGCT"/ ;
> =EF=BD=A2AGCT=EF=BD=A3
> 7> say $/ if $probe ~~ s/"AGCT"/"TCGA"/ ;
> =EF=BD=A2AGCT=EF=BD=A3
> 8> say $probe
> "TCGA"
> 9> say $/ if $probe ~~ S/"TCGA"/"AGCT"/ ;
> Potential difficulties:
>     Smartmatch with S/// is not useful. You can use given instead:
> S/// given $foo
>     ------> say $/ if $probe ~~ S/"TCGA"/"AGCT"/ ;
> ()
> 10> say $probe
> "TCGA"
> 11> say $_
> abc
> 12> $*VM
> moar (2019.07.1)
> >
>
> For "S///" in your Step 1 the LHS is evaluated first (your Join
> example) and the LHS is temporarily set to $_. Then (your Step 2) the
> RHS is evaluated. Do you mean the RHS is evaluated in the context of
> $_ from the LHS?? Using your "abc" example I don't understand--if you
> **solely** look at the "S/b/./" operation--how  the letters "a" and
> "c" show up in your Step 2 intermediate result. Of course, Raku/Perl6
> may be far cleverer than I imagined--clever enough based on position
> and regex-rules (maybe) to simplify the two sides of the "S///"
> operator into a simple formula that can then be applied to the LHS.
>
> So in pseudocode, are you saying the following regarding "s///"
> (destructive-substitution) operation?
>
> 1. LHS:
> eval( "probe" ) --> $_ ;
>
> 2. RHS regex "target" between first two solidi of s/// or S/// :
> eval( "target".ACCEPTS( $_) );
>
> 3. for s///, if above evaluates to TRUE match from above gets assigned
> to $/ and LHS "probe" gets overwritten with appropriate "substitution"
> characters between second two solidi of s/// or S/// :
> ( "match" --> $/ ) ; ( RHS_"substitution" --> "probe" ) ;
>
> [ 4. for S///, there is no possibility that Step 2 will evaluate to
> TRUE, so $/ is Nil and LHS "probe" remains as unchanged ].
>
> If I'm close, please let me know. Meanwhile I will: 1) read over what
> you wrote again, and 2) play around with a little more example code,
> to gain a better understanding of what Raku/Perl6 is doing
> under-the-hood.
>
> Best Regards, Bill.
>
>
>
> On Sun, Dec 8, 2019 at 12:42 PM Brad Gilbert <b2gills@gmail.com> wrote:
> >
> > smartmatch is among the most complex parts of the language.
> >
> > That complexity has to managed or it will be too complex to use
> effectively.
> >
> > To that end, the rules and order of operations are never altered.
> >
> > 1. The left side is evaluated first, and the resulting value captured
> >
> >         > say('left') ~~ say('right')
> >         left
> >         right
> >
> > 2. $_ is temporarily set to that value, and the right side is executed
> >
> >         > 'ab' ~ 'c'   ~~ say($_)
> >         abc
> >
> > 3. The result of that execution is matched against the left value
> >
> >         > 'abc' ~~ 'abb'.succ()
> >         True
> >
> >     Specifically `.ACCEPTS` is called with the left value.
> >     So the following two lines are roughly equivalent.
> >
> >         > 'abc'   ~~   'abb'.succ()
> >         > 'abb'.succ().ACCEPTS('abc')
> >
> > So in the case of S/// and ~~ this is the order that things happen:
> >
> > 1. The left side is executed
> >
> >         =C2=AB a b c =C2=BB.join()  ~~  S/b/./
> >
> >         'abc' ~~ S/b/./
> >
> > 2. $_ is temporarily set to that value, and the right side is executed
> >
> >         'abc' ~~ S/b/./
> >
> >         'abc' ~~ 'a.c'
> >
> > 3. the result of the right side is matched against the left value
> >
> >         'abc' ~~ 'a.c'
> >
> >         'a.c'.ACCEPTS('abc') # False
> >
> > So basically if S/// changes the value, the result is False.
> > If S/// doesn't change it, the result is True.
> >
> > Which means the following two lines are functionally identical.
> >
> >     'abc'   ~~  S/b/./
> >     'abc'  !~~   /b/
> >
> > So the resulting value will never be the string you wanted!
> > It will be True or False.
> >
> > ---
> >
> > The reason for the two stage execution is for the following.
> >
> >     'abc' ~~   .contains('b')
> >     'abc' ~~ { .contains('b') }
> >     'abc' ~~ m / b /
> >     'abc' ~~ rx / b /
> >
> > Those four lines work basically the same, but for two different reasons=
..
> >
> > The first one works because $_ is set to the left value, and
> True.ACCEPTS() always returns True
> >
> > The second one works because CODE.ACCEPTS() always runs the code with
> the same parameter list.
> >
> > The third one works for the same reason as the first one
> >
> > The fourth one works for the same reason as the second one
> >
> > 1. Left side executed
> >
> >     'abc' ~~   .contains('b')
> >     'abc' ~~ { .contains('b') }
> >     'abc' ~~ m  / b /
> >     'abc' ~~ rx / b /
> >
> > 2. Right side executed
> >
> >     'abc' ~~  True
> >     'abc' ~~ { .contains('b') }
> >     'abc' ~~ True
> >     'abc' ~~ rx / b /
> >
> > 3. R-VALUE  .ACCEPTS( L-VALUE )
> >
> >     True.ACCEPTS('abc')
> >     { .contains('b') }.ACCEPTS('abc')
> >     True.ACCEPTS('abc')
> >     rx / b /.ACCEPTS('abc')
> >
> > Note again that CODE.ACCEPTS(VALUE) is the same as CODE.(VALUE).
> > (Note also that a regex is a code object.)
> >
> >     True.ACCEPTS('abc')
> >     { .contains('b') }.('abc')
> >     True.ACCEPTS('abc')
> >     rx / b /.('abc')
> >
> > ---
> >
> > So then why does this work?
> >
> >     'abc' ~~ { S/b/./ }
> >
> > As I said CODE.ACCEPTS() always runs CODE with the same parameter list.
> >
> >     { S/b/./ }  .ACCEPTS( 'abc' )
> >
> >     { S/b/./ }  .( 'abc' )
> >
> > ---
> >
> > So why does the warning tell you to use `given` instead of what I just
> wrote?
> >
> > The ~~ is intended mostly for resolving some sort of truthiness.
> > So I just misused the feature for something it was not intended for.
> >
> > `given` is intended for temporarily setting $_, so it is the appropriat=
e
> tool for the job.
> >
> >     S/b/./ given 'abc'
> >
> > If you don't like `given`, then just use `.subst()`
> >
> >     'abc'.subst( 'b', '.' )
> >
> > On Sun, Dec 8, 2019 at 1:32 AM William Michels <wjm1@caa.columbia.edu>
> wrote:
> >>
> >> Apologies, looks like the smartmatch operator is listed in the
> >> Operator Precedence table (15th row: under "Chaining infix"):
> >>
> >> https://docs.raku.org/language/operators#Assignment_operators
> >>
> >> However, am I correct in stating that the assignment operator ("=3D") =
is
> >> on the 19th row ("Item assignment")? Therefore in the absence of
> >> parentheses, etc., all smartmatch operations take precedence over
> >> assignment operations?
> >>
> >> Best Regards, Bill.
> >>
> >>
> >> On Sat, Dec 7, 2019 at 10:27 PM William Michels <wjm1@caa.columbia.edu=
>
> wrote:
> >> >
> >> > Wow Brad, that's interesting and informative.
> >> >
> >> > I haven't seen the S/// operator before, so I had to look it up. On
> >> > the first page I found the docs say (quite informatively): "S/// use=
s
> >> > the same semantics as the s/// operator, except it leaves the origin=
al
> >> > string intact and returns the resultant string instead of $/ ($/ sti=
ll
> >> > being set to the same values as with s///)."
> >> >
> >> > https://docs.raku.org/syntax/S$SOLIDUS$SOLIDUS$SOLIDUS
> >> >
> >> > I was then able to find an overview on regexes, which more explicitl=
y
> >> > names the "S///" operator as "Non-disruptive substitution". I suppos=
e
> >> > I could quibble and request that the phrase "Non-disruptive
> >> > substitution" be added to the operator page (above), but no
> >> > matter--it's easy enough to find:
> >> >
> >> >
> https://docs.raku.org/language/regexes#S///_non-destructive_substitution
> >> >
> >> > So I think I understand that (as Brad has said): "smartmatch with S/=
//
> >> > (or TR///) is not useful." Conversely, I've also found another
> >> > smartmatch construct that is useless (i.e. disallowed):
> >> >
> >> > > my $r =3D 'abc' ~~ { S/b/./ }
> >> > a.c
> >> > > my $s =3D 'abc' ~~ { s/b/./ }
> >> > Cannot modify an immutable Str (abc)
> >> >   in block <unit> at <unknown file> line 1
> >> > >
> >> >
> >> > No matter how "discouraged' a particular syntax is, people are going
> >> > to run into these disallowed syntaxes and wonder why. Could it be du=
e
> >> > to precedence? These two prohibited operations beg the question: can=
 a
> >> > definitive statement be made regarding the precedence of the
> >> > smartmatch operator relative to either lowercase-triple-solidus
> >> > operators such as s/// and tr/// , or relative to
> >> > uppercase-triple-solidus operators such as S/// and TR/// ?
> >> >
> >> > This really makes me wonder if anyone has plans to add "~~" (the
> >> > smartmatch operator) to the precedence table that can be found
> >> > below--and where in the table the smartmatch operator would precisel=
y
> >> > sit:
> >> >
> >> > https://docs.raku.org/language/operators#Operator_precedence
> >> >
> >> > Best Regards, Bill.
> >> >
> >> >
> >> >
> >> >
> >> > On Sat, Dec 7, 2019 at 7:53 AM Brad Gilbert <b2gills@gmail.com>
> wrote:
> >> > >
> >> > > The return value of s/// is the same as $/
> >> > >
> >> > > If you want the resulting string instead you can use S/// instead.
> >> > >
> >> > >     > $_ =3D 'abc'
> >> > >     > my $r =3D S/b/./
> >> > >     > say $r
> >> > >     a.c
> >> > >
> >> > > Note that it warns you try to use S/// with ~~
> >> > >
> >> > >     > my $r =3D 'abc' ~~ S/b/./
> >> > >     Potential difficulties:
> >> > >         Smartmatch with S/// is not useful. You can use given
> instead: S/// given $foo
> >> > >         ------> my $r =3D 'abc' ~~ S/b/./
> >> > >     False
> >> > >
> >> > > Which gives you an indicator of how to fix it
> >> > >
> >> > >     > my $r =3D S/b/./ given 'abc'
> >> > >     a.c
> >> > >
> >> > > Note that the `given` happens before the `=3D`
> >> > >
> >> > > So it works the same as
> >> > >
> >> > >     > my $r =3D ( S/b/./ given 'abc' )
> >> > >     a.c
> >> > >
> >> > > ---
> >> > >
> >> > > The reason ~~ doesn't work with S/// has to do with the dual pass
> nature of ~~.
> >> > >
> >> > > Without getting into details, you can avoid that by delaying the
> S/// until the second pass.
> >> > >
> >> > >     > my $r =3D 'abc' ~~ { S/b/./ }
> >> > >     a.c
> >> > >
> >> > > Or you can just set $_ to the value.
> >> > > (Which is basically what the previous line is doing.)
> >> > >
> >> > >     > my $r =3D S/b/./ given 'abc'
> >> > >
> >> > >     > given 'abc' {
> >> > >     >   my $r =3D S/b/./
> >> > >     >   =E2=80=A6
> >> > >     > }
> >> > >
> >> > >     > my $_ =3D 'abc'
> >> > >     > my $r =3D S/b/./
> >> > >
> >> > >     > my $r =3D 'abc' ~~ -> $_ { S/b/./ }
> >> > >
> >> > >     > my $r =3D 'abc' ~~ sub ( $_ ) { S/b/./ }
> >> > >
> >> > >     > my $r =3D 'abc' ~~ anon sub foo ( $_ ) { S/b/./ }
> >> > > ---
> >> > >
> >> > > One of design goals of Raku is to have as few special cases as
> possible.
> >> > > Which is why ~~ and S/// haven't been made to just work.
> >> > >
> >> > > (It could be argued that in this case an exception could be made.
> But I'm not going to argue for it.)
> >> > >
> >> > > On Fri, Dec 6, 2019 at 10:37 PM William Michels via perl6-users <
> perl6-users@perl.org> wrote:
> >> > >>
> >> > >> Hello All,
> >> > >>
> >> > >> Todd put up some interesting code yesterday using the Raku/Perl6
> REPL,
> >> > >> which I reproduced with no problem. Additionally I tried some
> >> > >> variations removing and/or moving parentheses to a different
> location,
> >> > >> and have numbered the relevant REPL lines 1 through 6:
> >> > >>
> >> > >> mbook:~ homedir$ perl6
> >> > >> To exit type 'exit' or '^D'
> >> > >> 1> my $x =3D Q[word</b><br>] ;
> >> > >> word</b><br>
> >> > >> 2> (my $y =3D $x) ~~ s/ '<' .* //; say $/; say $x; say $y;
> >> > >> =EF=BD=A2</b><br>=EF=BD=A3
> >> > >> word</b><br>
> >> > >> word
> >> > >> 3> my $a =3D Q[word</b><br>] ;
> >> > >> word</b><br>
> >> > >> 4> my $b =3D ($a ~~ s/ '<' .* //); say $/; say $a; say $b;
> >> > >> =EF=BD=A2</b><br>=EF=BD=A3
> >> > >> word
> >> > >> =EF=BD=A2</b><br>=EF=BD=A3
> >> > >> > my $c =3D Q[word</b><br>] ;
> >> > >> word</b><br>
> >> > >> > my $d =3D $c ~~ s/ '<' .* //; say $/; say $c; say $d;
> >> > >> =EF=BD=A2</b><br>=EF=BD=A3
> >> > >> word
> >> > >> =EF=BD=A2</b><br>=EF=BD=A3
> >> > >> 7> $*VM
> >> > >> moar (2019.07.1)
> >> > >>
> >> > >> Working in groups of 2, lines 1 and 2 replicate the code Todd put
> up
> >> > >> (parenthesis surrounding everything to the left of the smartmatch
> >> > >> operator). I get the same result as Todd. What interests me are
> lines
> >> > >> 3 through 6. Lines 3 and 4 are the virtually the same code but wi=
th
> >> > >> parentheses surrounding everything to the right hand side (RHS) o=
f
> the
> >> > >> assignment operator (" =3D "). As people will note, lines 2 and
> lines 4
> >> > >> give different results. Removing parentheses entirely in line 6
> gives
> >> > >> the same result as in line 4. Because the results in line 4 and
> line 6
> >> > >> are the same, this says that as far as parentheses are concerned,
> the
> >> > >> smartmatch operator "~~" takes precedence over the assignment
> operator
> >> > >> "=3D".
> >> > >>
> >> > >> What's not clear to me in the code above (lines 4 and 6) is why
> >> > >> variables $b and $d get assigned to $/. I would have expected in
> line
> >> > >> 4 that $a would have been matched against the smartmatch, and the
> >> > >> result ("word") would have been simply copied into variable $b.
> Have I
> >> > >> misunderstood?
> >> > >>
> >> > >> Anyway, I'm just hoping to start a conversation on the topic of
> >> > >> precedence in general, and hopefully getting some feedback as to
> where
> >> > >> to look in the docs for further instruction.
> >> > >>
> >> > >> Best Regards, Bill.
> >> > >>
> >> > >>
> >> > >> On Fri, Dec 6, 2019 at 12:15 AM ToddAndMargo via perl6-users
> >> > >> <perl6-users@perl.org> wrote:
> >> > >> >
> >> > >> > On 2019-12-05 23:19, ToddAndMargo via perl6-users wrote:
> >> > >> > > On 2019-12-05 03:09, William Michels via perl6-users wrote:
> >> > >> > >> What happens when you type "perl6" or "raku" at the bash
> command prompt?
> >> > >> > >
> >> > >> > > Hi William,
> >> > >> > >
> >> > >> > > On my shop machine, it jumps to the next line with an
> >> > >> > > empty flashing cursor
> >> > >> > >
> >> > >> > > On my office machine, it told me to install
> >> > >> > >      zef install Readline
> >> > >> > >
> >> > >> > > After that, I get:
> >> > >> > >
> >> > >> > > $ perl6
> >> > >> > > To exit type 'exit' or '^D'
> >> > >> > >  >
> >> > >> > >
> >> > >> > > and
> >> > >> > >
> >> > >> > >  > say "hello World"
> >> > >> > > hello World
> >> > >> > >  > say "B" ~ Q[:\] ~ " drive dismounted"
> >> > >> > > B:\ drive dismounted
> >> > >> > >  >
> >> > >> > >
> >> > >> > > and sticking an obvious booboo into it
> >> > >> > >
> >> > >> > >  > if 3 % 2 =3D 1 {say "odd"};
> >> > >> > > Cannot modify an immutable Int (1)
> >> > >> > >    in block <unit> at <unknown file> line 1
> >> > >> > >
> >> > >> > > Plus I can use the arrow keys to recall previous lines too.
> >> > >> > >
> >> > >> > > Time up update my Perl6 on my shop computer!
> >> > >> > >
> >> > >> > > No more hassling with `perl6 -e` !!!
> >> > >> > >
> >> > >> > > Dude!  THANK YOU !!!!!!
> >> > >> > >
> >> > >> > > -T
> >> > >> >
> >> > >> > You've created a monster!!
> >> > >> >
> >> > >> > perl6
> >> > >> > To exit type 'exit' or '^D'
> >> > >> >  > my $x =3D Q[</b><br>]
> >> > >> > </b><br>
> >> > >> >  > say $x
> >> > >> > </b><br>
> >> > >> >  > (my $y =3D $x ) ~~ s/ Q[<] .* //;
> >> > >> > =3D=3D=3DSORRY!=3D=3D=3D Error while compiling:
> >> > >> > Unrecognized regex metacharacter < (must be quoted to match
> literally)
> >> > >> > ------> (my $y =3D $x ) ~~ s/ Q[<] .* //;
> >> > >> >  > my $x =3D Q[abc</b><br>]
> >> > >> > abc</b><br>
> >> > >> >  > (my $y =3D $x ) ~~ s/ '<' .* //;
> >> > >> > =EF=BD=A2</b><br>=EF=BD=A3
> >> > >> >  > (my $y =3D $x ) ~~ s/ '<' .* //; say $y
> >> > >> > abc
> >> > >> >  > (my $y =3D $x ) ~~ s/ '<' .* //; say $x; say $y
> >> > >> > abc</b><br>
> >> > >> > abc
> >> > >> >
> >> > >> >
> >> > >> > Thank you!
> >> > >> >
> >> > >> >
> >> > >> > --
> >> > >> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >> > >> > Computers are like air conditioners.
> >> > >> > They malfunction when you open windows
> >> > >> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>

--0000000000000db6c805994feea0
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>I meant that $_ is set to the left value while the ri=
ght value is being evaluated, and also while .ACCEPTS is called.</div><div>=
<br></div><div>=C2=A0 =C2=A0 LEFT ~~ RIGHT</div><div><br></div><div>(Where =
LEFT and RIGHT represent some expression to be executed during runtime.)</d=
iv><div><br></div><div>Imagine that underneath the hood, something like thi=
s is happening:</div><div><br></div><div>=C2=A0 =C2=A0 my $L-value =3D LEFT=
..evaluate();</div><div><br></div><div>=C2=A0 =C2=A0 given $L-value {</div><=
div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 # $_ is temporarily the result of the LEFT =
expression</div><div><br></div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 my $R-value=
 =3D RIGHT.evaluate();</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return $R-valu=
e.ACCEPTS($L-value);</div><div>=C2=A0 =C2=A0 }</div><div><br></div><div>So =
this:</div><div><br></div><div>=C2=A0 =C2=A0 =C2=AB a b c =C2=BB.join()=C2=
=A0 =C2=A0~~=C2=A0 =C2=A0S/b/y/</div><div><br></div><div>is functionally th=
e same as:</div><div><br></div><div>=C2=A0 =C2=A0 do given=C2=A0=C2=AB a b =
c =C2=BB.join() {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 my $R-value =3D=C2=
=A0S/b/y/;</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 $R-value.ACCEPTS($_)</div>=
<div>=C2=A0 =C2=A0 }</div><div><br></div><div>Note that $R-value will be &q=
uot;ayc&quot;</div><div><br></div><div>=C2=A0 =C2=A0 &quot;ayc&quot;.ACCEPT=
S(&quot;abc&quot;) =3D=3D False</div><div><br></div><div>---</div><div><br>=
</div><div>=C2=A0 =C2=A0 &gt; $_.say</div><div>=C2=A0 =C2=A0 (Any)</div><di=
v><br></div><div>=C2=A0 =C2=A0 &gt; =C2=AB a b c =C2=BB.join()=C2=A0 =C2=A0=
~~=C2=A0 =C2=A0-&gt; $a { say &quot;\$a =3D $a\n\$_ =3D $_&quot; }</div><di=
v>=C2=A0 =C2=A0 $a =3D abc</div>=C2=A0 =C2=A0 $_ =3D abc<div><br></div><div=
><br></div><div>=C2=A0 =C2=A0 &gt;=C2=A0=C2=AB a b c =C2=BB.join()=C2=A0 =
=C2=A0~~=C2=A0 =C2=A0($_.say, -&gt; $a { say &quot;\$a =3D $a\n\$_ =3D $_&q=
uot; }).tail</div>=C2=A0 =C2=A0 abc<br>=C2=A0 =C2=A0 $a =3D abc<br>=C2=A0 =
=C2=A0 $_ =3D abc<div><br>=C2=A0 =C2=A0 &gt; $_.say<br>=C2=A0 =C2=A0 (Any)<=
br></div><div><br></div></div><br><div class=3D"gmail_quote"><div dir=3D"lt=
r" class=3D"gmail_attr">On Mon, Dec 9, 2019 at 7:34 PM William Michels &lt;=
<a href=3D"mailto:wjm1@caa.columbia.edu">wjm1@caa.columbia.edu</a>&gt; wrot=
e:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0=
..8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Thank you Bra=
d, for your in-depth reply.<br>
<br>
There are parts of your reply that make perfect sense to me, and also<br>
parts where I am still confused. I feel I understand your first three<br>
examples (1,2,3) explaining how the smartmatch operator relates to<br>
ACCEPTS(). However in the second three examples explaining &quot;S///&quot;=
<br>
(also numbered 1,2,3), I&#39;m confused on Your Step 2. I&#39;ve tried<br>
numerous examples, a few of which are reproduced below:<br>
<br>
mbook:~ homedir$ perl6<br>
To exit type &#39;exit&#39; or &#39;^D&#39;<br>
1&gt; my $a =3D =C2=AB a b c =C2=BB.join()<br>
abc<br>
2&gt; say $a ~~ s/b/y/<br>
=EF=BD=A2b=EF=BD=A3<br>
3&gt; say $a<br>
ayc<br>
4&gt; my $probe =3D &quot;AGCT&quot;<br>
AGCT<br>
5 &gt; say $/ if $probe ~~ /&quot;TCGA&quot;/ ;<br>
()<br>
6&gt; say $/ if $probe ~~ /&quot;AGCT&quot;/ ;<br>
=EF=BD=A2AGCT=EF=BD=A3<br>
7&gt; say $/ if $probe ~~ s/&quot;AGCT&quot;/&quot;TCGA&quot;/ ;<br>
=EF=BD=A2AGCT=EF=BD=A3<br>
8&gt; say $probe<br>
&quot;TCGA&quot;<br>
9&gt; say $/ if $probe ~~ S/&quot;TCGA&quot;/&quot;AGCT&quot;/ ;<br>
Potential difficulties:<br>
=C2=A0 =C2=A0 Smartmatch with S/// is not useful. You can use given instead=
:<br>
S/// given $foo<br>
=C2=A0 =C2=A0 ------&gt; say $/ if $probe ~~ S/&quot;TCGA&quot;/&quot;AGCT&=
quot;/ ;<br>
()<br>
10&gt; say $probe<br>
&quot;TCGA&quot;<br>
11&gt; say $_<br>
abc<br>
12&gt; $*VM<br>
moar (2019.07.1)<br>
&gt;<br>
<br>
For &quot;S///&quot; in your Step 1 the LHS is evaluated first (your Join<b=
r>
example) and the LHS is temporarily set to $_. Then (your Step 2) the<br>
RHS is evaluated. Do you mean the RHS is evaluated in the context of<br>
$_ from the LHS?? Using your &quot;abc&quot; example I don&#39;t understand=
--if you<br>
**solely** look at the &quot;S/b/./&quot; operation--how=C2=A0 the letters =
&quot;a&quot; and<br>
&quot;c&quot; show up in your Step 2 intermediate result. Of course, Raku/P=
erl6<br>
may be far cleverer than I imagined--clever enough based on position<br>
and regex-rules (maybe) to simplify the two sides of the &quot;S///&quot;<b=
r>
operator into a simple formula that can then be applied to the LHS.<br>
<br>
So in pseudocode, are you saying the following regarding &quot;s///&quot;<b=
r>
(destructive-substitution) operation?<br>
<br>
1. LHS:<br>
eval( &quot;probe&quot; ) --&gt; $_ ;<br>
<br>
2. RHS regex &quot;target&quot; between first two solidi of s/// or S/// :<=
br>
eval( &quot;target&quot;.ACCEPTS( $_) );<br>
<br>
3. for s///, if above evaluates to TRUE match from above gets assigned<br>
to $/ and LHS &quot;probe&quot; gets overwritten with appropriate &quot;sub=
stitution&quot;<br>
characters between second two solidi of s/// or S/// :<br>
( &quot;match&quot; --&gt; $/ ) ; ( RHS_&quot;substitution&quot; --&gt; &qu=
ot;probe&quot; ) ;<br>
<br>
[ 4. for S///, there is no possibility that Step 2 will evaluate to<br>
TRUE, so $/ is Nil and LHS &quot;probe&quot; remains as unchanged ].<br>
<br>
If I&#39;m close, please let me know. Meanwhile I will: 1) read over what<b=
r>
you wrote again, and 2) play around with a little more example code,<br>
to gain a better understanding of what Raku/Perl6 is doing<br>
under-the-hood.<br>
<br>
Best Regards, Bill.<br>
<br>
<br>
<br>
On Sun, Dec 8, 2019 at 12:42 PM Brad Gilbert &lt;<a href=3D"mailto:b2gills@=
gmail.com" target=3D"_blank">b2gills@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt; smartmatch is among the most complex parts of the language.<br>
&gt;<br>
&gt; That complexity has to managed or it will be too complex to use effect=
ively.<br>
&gt;<br>
&gt; To that end, the rules and order of operations are never altered.<br>
&gt;<br>
&gt; 1. The left side is evaluated first, and the resulting value captured<=
br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0&gt; say(&#39;left&#39;) ~~ say(&#39;=
right&#39;)<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0left<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0right<br>
&gt;<br>
&gt; 2. $_ is temporarily set to that value, and the right side is executed=
<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0&gt; &#39;ab&#39; ~ &#39;c&#39;=C2=A0=
 =C2=A0~~ say($_)<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0abc<br>
&gt;<br>
&gt; 3. The result of that execution is matched against the left value<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0&gt; &#39;abc&#39; ~~ &#39;abb&#39;.s=
ucc()<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0True<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0Specifically `.ACCEPTS` is called with the left val=
ue.<br>
&gt;=C2=A0 =C2=A0 =C2=A0So the following two lines are roughly equivalent.<=
br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0&gt; &#39;abc&#39;=C2=A0 =C2=A0~~=C2=
=A0 =C2=A0&#39;abb&#39;.succ()<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0&gt; &#39;abb&#39;.succ().ACCEPTS(&#3=
9;abc&#39;)<br>
&gt;<br>
&gt; So in the case of S/// and ~~ this is the order that things happen:<br=
>
&gt;<br>
&gt; 1. The left side is executed<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=AB a b c =C2=BB.join()=C2=A0 ~~=
=C2=A0 S/b/./<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0&#39;abc&#39; ~~ S/b/./<br>
&gt;<br>
&gt; 2. $_ is temporarily set to that value, and the right side is executed=
<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0&#39;abc&#39; ~~ S/b/./<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0&#39;abc&#39; ~~ &#39;a.c&#39;<br>
&gt;<br>
&gt; 3. the result of the right side is matched against the left value<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0&#39;abc&#39; ~~ &#39;a.c&#39;<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0&#39;a.c&#39;.ACCEPTS(&#39;abc&#39;) =
# False<br>
&gt;<br>
&gt; So basically if S/// changes the value, the result is False.<br>
&gt; If S/// doesn&#39;t change it, the result is True.<br>
&gt;<br>
&gt; Which means the following two lines are functionally identical.<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0&#39;abc&#39;=C2=A0 =C2=A0~~=C2=A0 S/b/./<br>
&gt;=C2=A0 =C2=A0 =C2=A0&#39;abc&#39;=C2=A0 !~~=C2=A0 =C2=A0/b/<br>
&gt;<br>
&gt; So the resulting value will never be the string you wanted!<br>
&gt; It will be True or False.<br>
&gt;<br>
&gt; ---<br>
&gt;<br>
&gt; The reason for the two stage execution is for the following.<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0&#39;abc&#39; ~~=C2=A0 =C2=A0.contains(&#39;b&#39;)=
<br>
&gt;=C2=A0 =C2=A0 =C2=A0&#39;abc&#39; ~~ { .contains(&#39;b&#39;) }<br>
&gt;=C2=A0 =C2=A0 =C2=A0&#39;abc&#39; ~~ m / b /<br>
&gt;=C2=A0 =C2=A0 =C2=A0&#39;abc&#39; ~~ rx / b /<br>
&gt;<br>
&gt; Those four lines work basically the same, but for two different reason=
s.<br>
&gt;<br>
&gt; The first one works because $_ is set to the left value, and True.ACCE=
PTS() always returns True<br>
&gt;<br>
&gt; The second one works because CODE.ACCEPTS() always runs the code with =
the same parameter list.<br>
&gt;<br>
&gt; The third one works for the same reason as the first one<br>
&gt;<br>
&gt; The fourth one works for the same reason as the second one<br>
&gt;<br>
&gt; 1. Left side executed<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0&#39;abc&#39; ~~=C2=A0 =C2=A0.contains(&#39;b&#39;)=
<br>
&gt;=C2=A0 =C2=A0 =C2=A0&#39;abc&#39; ~~ { .contains(&#39;b&#39;) }<br>
&gt;=C2=A0 =C2=A0 =C2=A0&#39;abc&#39; ~~ m=C2=A0 / b /<br>
&gt;=C2=A0 =C2=A0 =C2=A0&#39;abc&#39; ~~ rx / b /<br>
&gt;<br>
&gt; 2. Right side executed<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0&#39;abc&#39; ~~=C2=A0 True<br>
&gt;=C2=A0 =C2=A0 =C2=A0&#39;abc&#39; ~~ { .contains(&#39;b&#39;) }<br>
&gt;=C2=A0 =C2=A0 =C2=A0&#39;abc&#39; ~~ True<br>
&gt;=C2=A0 =C2=A0 =C2=A0&#39;abc&#39; ~~ rx / b /<br>
&gt;<br>
&gt; 3. R-VALUE=C2=A0 .ACCEPTS( L-VALUE )<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0True.ACCEPTS(&#39;abc&#39;)<br>
&gt;=C2=A0 =C2=A0 =C2=A0{ .contains(&#39;b&#39;) }.ACCEPTS(&#39;abc&#39;)<b=
r>
&gt;=C2=A0 =C2=A0 =C2=A0True.ACCEPTS(&#39;abc&#39;)<br>
&gt;=C2=A0 =C2=A0 =C2=A0rx / b /.ACCEPTS(&#39;abc&#39;)<br>
&gt;<br>
&gt; Note again that CODE.ACCEPTS(VALUE) is the same as CODE.(VALUE).<br>
&gt; (Note also that a regex is a code object.)<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0True.ACCEPTS(&#39;abc&#39;)<br>
&gt;=C2=A0 =C2=A0 =C2=A0{ .contains(&#39;b&#39;) }.(&#39;abc&#39;)<br>
&gt;=C2=A0 =C2=A0 =C2=A0True.ACCEPTS(&#39;abc&#39;)<br>
&gt;=C2=A0 =C2=A0 =C2=A0rx / b /.(&#39;abc&#39;)<br>
&gt;<br>
&gt; ---<br>
&gt;<br>
&gt; So then why does this work?<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0&#39;abc&#39; ~~ { S/b/./ }<br>
&gt;<br>
&gt; As I said CODE.ACCEPTS() always runs CODE with the same parameter list=
..<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0{ S/b/./ }=C2=A0 .ACCEPTS( &#39;abc&#39; )<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0{ S/b/./ }=C2=A0 .( &#39;abc&#39; )<br>
&gt;<br>
&gt; ---<br>
&gt;<br>
&gt; So why does the warning tell you to use `given` instead of what I just=
 wrote?<br>
&gt;<br>
&gt; The ~~ is intended mostly for resolving some sort of truthiness.<br>
&gt; So I just misused the feature for something it was not intended for.<b=
r>
&gt;<br>
&gt; `given` is intended for temporarily setting $_, so it is the appropria=
te tool for the job.<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0S/b/./ given &#39;abc&#39;<br>
&gt;<br>
&gt; If you don&#39;t like `given`, then just use `.subst()`<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0&#39;abc&#39;.subst( &#39;b&#39;, &#39;.&#39; )<br>
&gt;<br>
&gt; On Sun, Dec 8, 2019 at 1:32 AM William Michels &lt;<a href=3D"mailto:w=
jm1@caa.columbia.edu" target=3D"_blank">wjm1@caa.columbia.edu</a>&gt; wrote=
:<br>
&gt;&gt;<br>
&gt;&gt; Apologies, looks like the smartmatch operator is listed in the<br>
&gt;&gt; Operator Precedence table (15th row: under &quot;Chaining infix&qu=
ot;):<br>
&gt;&gt;<br>
&gt;&gt; <a href=3D"https://docs.raku.org/language/operators#Assignment_ope=
rators" rel=3D"noreferrer" target=3D"_blank">https://docs.raku.org/language=
/operators#Assignment_operators</a><br>
&gt;&gt;<br>
&gt;&gt; However, am I correct in stating that the assignment operator (&qu=
ot;=3D&quot;) is<br>
&gt;&gt; on the 19th row (&quot;Item assignment&quot;)? Therefore in the ab=
sence of<br>
&gt;&gt; parentheses, etc., all smartmatch operations take precedence over<=
br>
&gt;&gt; assignment operations?<br>
&gt;&gt;<br>
&gt;&gt; Best Regards, Bill.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; On Sat, Dec 7, 2019 at 10:27 PM William Michels &lt;<a href=3D"mai=
lto:wjm1@caa.columbia.edu" target=3D"_blank">wjm1@caa.columbia.edu</a>&gt; =
wrote:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Wow Brad, that&#39;s interesting and informative.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; I haven&#39;t seen the S/// operator before, so I had to look=
 it up. On<br>
&gt;&gt; &gt; the first page I found the docs say (quite informatively): &q=
uot;S/// uses<br>
&gt;&gt; &gt; the same semantics as the s/// operator, except it leaves the=
 original<br>
&gt;&gt; &gt; string intact and returns the resultant string instead of $/ =
($/ still<br>
&gt;&gt; &gt; being set to the same values as with s///).&quot;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; <a href=3D"https://docs.raku.org/syntax/S$SOLIDUS$SOLIDUS$SOL=
IDUS" rel=3D"noreferrer" target=3D"_blank">https://docs.raku.org/syntax/S$S=
OLIDUS$SOLIDUS$SOLIDUS</a><br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; I was then able to find an overview on regexes, which more ex=
plicitly<br>
&gt;&gt; &gt; names the &quot;S///&quot; operator as &quot;Non-disruptive s=
ubstitution&quot;. I suppose<br>
&gt;&gt; &gt; I could quibble and request that the phrase &quot;Non-disrupt=
ive<br>
&gt;&gt; &gt; substitution&quot; be added to the operator page (above), but=
 no<br>
&gt;&gt; &gt; matter--it&#39;s easy enough to find:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; <a href=3D"https://docs.raku.org/language/regexes#S///_non-de=
structive_substitution" rel=3D"noreferrer" target=3D"_blank">https://docs.r=
aku.org/language/regexes#S///_non-destructive_substitution</a><br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; So I think I understand that (as Brad has said): &quot;smartm=
atch with S///<br>
&gt;&gt; &gt; (or TR///) is not useful.&quot; Conversely, I&#39;ve also fou=
nd another<br>
&gt;&gt; &gt; smartmatch construct that is useless (i.e. disallowed):<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; &gt; my $r =3D &#39;abc&#39; ~~ { S/b/./ }<br>
&gt;&gt; &gt; a.c<br>
&gt;&gt; &gt; &gt; my $s =3D &#39;abc&#39; ~~ { s/b/./ }<br>
&gt;&gt; &gt; Cannot modify an immutable Str (abc)<br>
&gt;&gt; &gt;=C2=A0 =C2=A0in block &lt;unit&gt; at &lt;unknown file&gt; lin=
e 1<br>
&gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; No matter how &quot;discouraged&#39; a particular syntax is, =
people are going<br>
&gt;&gt; &gt; to run into these disallowed syntaxes and wonder why. Could i=
t be due<br>
&gt;&gt; &gt; to precedence? These two prohibited operations beg the questi=
on: can a<br>
&gt;&gt; &gt; definitive statement be made regarding the precedence of the<=
br>
&gt;&gt; &gt; smartmatch operator relative to either lowercase-triple-solid=
us<br>
&gt;&gt; &gt; operators such as s/// and tr/// , or relative to<br>
&gt;&gt; &gt; uppercase-triple-solidus operators such as S/// and TR/// ?<b=
r>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; This really makes me wonder if anyone has plans to add &quot;=
~~&quot; (the<br>
&gt;&gt; &gt; smartmatch operator) to the precedence table that can be foun=
d<br>
&gt;&gt; &gt; below--and where in the table the smartmatch operator would p=
recisely<br>
&gt;&gt; &gt; sit:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; <a href=3D"https://docs.raku.org/language/operators#Operator_=
precedence" rel=3D"noreferrer" target=3D"_blank">https://docs.raku.org/lang=
uage/operators#Operator_precedence</a><br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Best Regards, Bill.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; On Sat, Dec 7, 2019 at 7:53 AM Brad Gilbert &lt;<a href=3D"ma=
ilto:b2gills@gmail.com" target=3D"_blank">b2gills@gmail.com</a>&gt; wrote:<=
br>
&gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt; The return value of s/// is the same as $/<br>
&gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt; If you want the resulting string instead you can use S//=
/ instead.<br>
&gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt; $_ =3D &#39;abc&#39;<br>
&gt;&gt; &gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt; my $r =3D S/b/./<br>
&gt;&gt; &gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt; say $r<br>
&gt;&gt; &gt; &gt;=C2=A0 =C2=A0 =C2=A0a.c<br>
&gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt; Note that it warns you try to use S/// with ~~<br>
&gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt; my $r =3D &#39;abc&#39; ~~ S/b/.=
/<br>
&gt;&gt; &gt; &gt;=C2=A0 =C2=A0 =C2=A0Potential difficulties:<br>
&gt;&gt; &gt; &gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Smartmatch with S/// is=
 not useful. You can use given instead: S/// given $foo<br>
&gt;&gt; &gt; &gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0------&gt; my $r =3D &#=
39;abc&#39; ~~ S/b/./<br>
&gt;&gt; &gt; &gt;=C2=A0 =C2=A0 =C2=A0False<br>
&gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt; Which gives you an indicator of how to fix it<br>
&gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt; my $r =3D S/b/./ given &#39;abc&=
#39;<br>
&gt;&gt; &gt; &gt;=C2=A0 =C2=A0 =C2=A0a.c<br>
&gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt; Note that the `given` happens before the `=3D`<br>
&gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt; So it works the same as<br>
&gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt; my $r =3D ( S/b/./ given &#39;ab=
c&#39; )<br>
&gt;&gt; &gt; &gt;=C2=A0 =C2=A0 =C2=A0a.c<br>
&gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt; ---<br>
&gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt; The reason ~~ doesn&#39;t work with S/// has to do with =
the dual pass nature of ~~.<br>
&gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt; Without getting into details, you can avoid that by dela=
ying the S/// until the second pass.<br>
&gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt; my $r =3D &#39;abc&#39; ~~ { S/b=
/./ }<br>
&gt;&gt; &gt; &gt;=C2=A0 =C2=A0 =C2=A0a.c<br>
&gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt; Or you can just set $_ to the value.<br>
&gt;&gt; &gt; &gt; (Which is basically what the previous line is doing.)<br=
>
&gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt; my $r =3D S/b/./ given &#39;abc&=
#39;<br>
&gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt; given &#39;abc&#39; {<br>
&gt;&gt; &gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt;=C2=A0 =C2=A0my $r =3D S/b/./<br>
&gt;&gt; &gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt;=C2=A0 =C2=A0=E2=80=A6<br>
&gt;&gt; &gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt; }<br>
&gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt; my $_ =3D &#39;abc&#39;<br>
&gt;&gt; &gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt; my $r =3D S/b/./<br>
&gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt; my $r =3D &#39;abc&#39; ~~ -&gt;=
 $_ { S/b/./ }<br>
&gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt; my $r =3D &#39;abc&#39; ~~ sub (=
 $_ ) { S/b/./ }<br>
&gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt;=C2=A0 =C2=A0 =C2=A0&gt; my $r =3D &#39;abc&#39; ~~ anon =
sub foo ( $_ ) { S/b/./ }<br>
&gt;&gt; &gt; &gt; ---<br>
&gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt; One of design goals of Raku is to have as few special ca=
ses as possible.<br>
&gt;&gt; &gt; &gt; Which is why ~~ and S/// haven&#39;t been made to just w=
ork.<br>
&gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt; (It could be argued that in this case an exception could=
 be made. But I&#39;m not going to argue for it.)<br>
&gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt; On Fri, Dec 6, 2019 at 10:37 PM William Michels via perl=
6-users &lt;<a href=3D"mailto:perl6-users@perl.org" target=3D"_blank">perl6=
-users@perl.org</a>&gt; wrote:<br>
&gt;&gt; &gt; &gt;&gt;<br>
&gt;&gt; &gt; &gt;&gt; Hello All,<br>
&gt;&gt; &gt; &gt;&gt;<br>
&gt;&gt; &gt; &gt;&gt; Todd put up some interesting code yesterday using th=
e Raku/Perl6 REPL,<br>
&gt;&gt; &gt; &gt;&gt; which I reproduced with no problem. Additionally I t=
ried some<br>
&gt;&gt; &gt; &gt;&gt; variations removing and/or moving parentheses to a d=
ifferent location,<br>
&gt;&gt; &gt; &gt;&gt; and have numbered the relevant REPL lines 1 through =
6:<br>
&gt;&gt; &gt; &gt;&gt;<br>
&gt;&gt; &gt; &gt;&gt; mbook:~ homedir$ perl6<br>
&gt;&gt; &gt; &gt;&gt; To exit type &#39;exit&#39; or &#39;^D&#39;<br>
&gt;&gt; &gt; &gt;&gt; 1&gt; my $x =3D Q[word&lt;/b&gt;&lt;br&gt;] ;<br>
&gt;&gt; &gt; &gt;&gt; word&lt;/b&gt;&lt;br&gt;<br>
&gt;&gt; &gt; &gt;&gt; 2&gt; (my $y =3D $x) ~~ s/ &#39;&lt;&#39; .* //; say=
 $/; say $x; say $y;<br>
&gt;&gt; &gt; &gt;&gt; =EF=BD=A2&lt;/b&gt;&lt;br&gt;=EF=BD=A3<br>
&gt;&gt; &gt; &gt;&gt; word&lt;/b&gt;&lt;br&gt;<br>
&gt;&gt; &gt; &gt;&gt; word<br>
&gt;&gt; &gt; &gt;&gt; 3&gt; my $a =3D Q[word&lt;/b&gt;&lt;br&gt;] ;<br>
&gt;&gt; &gt; &gt;&gt; word&lt;/b&gt;&lt;br&gt;<br>
&gt;&gt; &gt; &gt;&gt; 4&gt; my $b =3D ($a ~~ s/ &#39;&lt;&#39; .* //); say=
 $/; say $a; say $b;<br>
&gt;&gt; &gt; &gt;&gt; =EF=BD=A2&lt;/b&gt;&lt;br&gt;=EF=BD=A3<br>
&gt;&gt; &gt; &gt;&gt; word<br>
&gt;&gt; &gt; &gt;&gt; =EF=BD=A2&lt;/b&gt;&lt;br&gt;=EF=BD=A3<br>
&gt;&gt; &gt; &gt;&gt; &gt; my $c =3D Q[word&lt;/b&gt;&lt;br&gt;] ;<br>
&gt;&gt; &gt; &gt;&gt; word&lt;/b&gt;&lt;br&gt;<br>
&gt;&gt; &gt; &gt;&gt; &gt; my $d =3D $c ~~ s/ &#39;&lt;&#39; .* //; say $/=
; say $c; say $d;<br>
&gt;&gt; &gt; &gt;&gt; =EF=BD=A2&lt;/b&gt;&lt;br&gt;=EF=BD=A3<br>
&gt;&gt; &gt; &gt;&gt; word<br>
&gt;&gt; &gt; &gt;&gt; =EF=BD=A2&lt;/b&gt;&lt;br&gt;=EF=BD=A3<br>
&gt;&gt; &gt; &gt;&gt; 7&gt; $*VM<br>
&gt;&gt; &gt; &gt;&gt; moar (2019.07.1)<br>
&gt;&gt; &gt; &gt;&gt;<br>
&gt;&gt; &gt; &gt;&gt; Working in groups of 2, lines 1 and 2 replicate the =
code Todd put up<br>
&gt;&gt; &gt; &gt;&gt; (parenthesis surrounding everything to the left of t=
he smartmatch<br>
&gt;&gt; &gt; &gt;&gt; operator). I get the same result as Todd. What inter=
ests me are lines<br>
&gt;&gt; &gt; &gt;&gt; 3 through 6. Lines 3 and 4 are the virtually the sam=
e code but with<br>
&gt;&gt; &gt; &gt;&gt; parentheses surrounding everything to the right hand=
 side (RHS) of the<br>
&gt;&gt; &gt; &gt;&gt; assignment operator (&quot; =3D &quot;). As people w=
ill note, lines 2 and lines 4<br>
&gt;&gt; &gt; &gt;&gt; give different results. Removing parentheses entirel=
y in line 6 gives<br>
&gt;&gt; &gt; &gt;&gt; the same result as in line 4. Because the results in=
 line 4 and line 6<br>
&gt;&gt; &gt; &gt;&gt; are the same, this says that as far as parentheses a=
re concerned, the<br>
&gt;&gt; &gt; &gt;&gt; smartmatch operator &quot;~~&quot; takes precedence =
over the assignment operator<br>
&gt;&gt; &gt; &gt;&gt; &quot;=3D&quot;.<br>
&gt;&gt; &gt; &gt;&gt;<br>
&gt;&gt; &gt; &gt;&gt; What&#39;s not clear to me in the code above (lines =
4 and 6) is why<br>
&gt;&gt; &gt; &gt;&gt; variables $b and $d get assigned to $/. I would have=
 expected in line<br>
&gt;&gt; &gt; &gt;&gt; 4 that $a would have been matched against the smartm=
atch, and the<br>
&gt;&gt; &gt; &gt;&gt; result (&quot;word&quot;) would have been simply cop=
ied into variable $b. Have I<br>
&gt;&gt; &gt; &gt;&gt; misunderstood?<br>
&gt;&gt; &gt; &gt;&gt;<br>
&gt;&gt; &gt; &gt;&gt; Anyway, I&#39;m just hoping to start a conversation =
on the topic of<br>
&gt;&gt; &gt; &gt;&gt; precedence in general, and hopefully getting some fe=
edback as to where<br>
&gt;&gt; &gt; &gt;&gt; to look in the docs for further instruction.<br>
&gt;&gt; &gt; &gt;&gt;<br>
&gt;&gt; &gt; &gt;&gt; Best Regards, Bill.<br>
&gt;&gt; &gt; &gt;&gt;<br>
&gt;&gt; &gt; &gt;&gt;<br>
&gt;&gt; &gt; &gt;&gt; On Fri, Dec 6, 2019 at 12:15 AM ToddAndMargo via per=
l6-users<br>
&gt;&gt; &gt; &gt;&gt; &lt;<a href=3D"mailto:perl6-users@perl.org" target=
=3D"_blank">perl6-users@perl.org</a>&gt; wrote:<br>
&gt;&gt; &gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt; &gt;&gt; &gt; On 2019-12-05 23:19, ToddAndMargo via perl6-use=
rs wrote:<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt; On 2019-12-05 03:09, William Michels via p=
erl6-users wrote:<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt;&gt; What happens when you type &quot;perl6=
&quot; or &quot;raku&quot; at the bash command prompt?<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt; Hi William,<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt; On my shop machine, it jumps to the next l=
ine with an<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt; empty flashing cursor<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt; On my office machine, it told me to instal=
l<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt;=C2=A0 =C2=A0 =C2=A0 zef install Readline<b=
r>
&gt;&gt; &gt; &gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt; After that, I get:<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt; $ perl6<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt; To exit type &#39;exit&#39; or &#39;^D&#39=
;<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt;=C2=A0 &gt;<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt; and<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt;=C2=A0 &gt; say &quot;hello World&quot;<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt; hello World<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt;=C2=A0 &gt; say &quot;B&quot; ~ Q[:\] ~ &qu=
ot; drive dismounted&quot;<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt; B:\ drive dismounted<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt;=C2=A0 &gt;<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt; and sticking an obvious booboo into it<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt;=C2=A0 &gt; if 3 % 2 =3D 1 {say &quot;odd&q=
uot;};<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt; Cannot modify an immutable Int (1)<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt;=C2=A0 =C2=A0 in block &lt;unit&gt; at &lt;=
unknown file&gt; line 1<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt; Plus I can use the arrow keys to recall pr=
evious lines too.<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt; Time up update my Perl6 on my shop compute=
r!<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt; No more hassling with `perl6 -e` !!!<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt; Dude!=C2=A0 THANK YOU !!!!!!<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; &gt;&gt; &gt; &gt; -T<br>
&gt;&gt; &gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt; &gt;&gt; &gt; You&#39;ve created a monster!!<br>
&gt;&gt; &gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt; &gt;&gt; &gt; perl6<br>
&gt;&gt; &gt; &gt;&gt; &gt; To exit type &#39;exit&#39; or &#39;^D&#39;<br>
&gt;&gt; &gt; &gt;&gt; &gt;=C2=A0 &gt; my $x =3D Q[&lt;/b&gt;&lt;br&gt;]<br=
>
&gt;&gt; &gt; &gt;&gt; &gt; &lt;/b&gt;&lt;br&gt;<br>
&gt;&gt; &gt; &gt;&gt; &gt;=C2=A0 &gt; say $x<br>
&gt;&gt; &gt; &gt;&gt; &gt; &lt;/b&gt;&lt;br&gt;<br>
&gt;&gt; &gt; &gt;&gt; &gt;=C2=A0 &gt; (my $y =3D $x ) ~~ s/ Q[&lt;] .* //;=
<br>
&gt;&gt; &gt; &gt;&gt; &gt; =3D=3D=3DSORRY!=3D=3D=3D Error while compiling:=
<br>
&gt;&gt; &gt; &gt;&gt; &gt; Unrecognized regex metacharacter &lt; (must be =
quoted to match literally)<br>
&gt;&gt; &gt; &gt;&gt; &gt; ------&gt; (my $y =3D $x ) ~~ s/ Q[&lt;] .* //;=
<br>
&gt;&gt; &gt; &gt;&gt; &gt;=C2=A0 &gt; my $x =3D Q[abc&lt;/b&gt;&lt;br&gt;]=
<br>
&gt;&gt; &gt; &gt;&gt; &gt; abc&lt;/b&gt;&lt;br&gt;<br>
&gt;&gt; &gt; &gt;&gt; &gt;=C2=A0 &gt; (my $y =3D $x ) ~~ s/ &#39;&lt;&#39;=
 .* //;<br>
&gt;&gt; &gt; &gt;&gt; &gt; =EF=BD=A2&lt;/b&gt;&lt;br&gt;=EF=BD=A3<br>
&gt;&gt; &gt; &gt;&gt; &gt;=C2=A0 &gt; (my $y =3D $x ) ~~ s/ &#39;&lt;&#39;=
 .* //; say $y<br>
&gt;&gt; &gt; &gt;&gt; &gt; abc<br>
&gt;&gt; &gt; &gt;&gt; &gt;=C2=A0 &gt; (my $y =3D $x ) ~~ s/ &#39;&lt;&#39;=
 .* //; say $x; say $y<br>
&gt;&gt; &gt; &gt;&gt; &gt; abc&lt;/b&gt;&lt;br&gt;<br>
&gt;&gt; &gt; &gt;&gt; &gt; abc<br>
&gt;&gt; &gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt; &gt;&gt; &gt; Thank you!<br>
&gt;&gt; &gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt; &gt;&gt; &gt; --<br>
&gt;&gt; &gt; &gt;&gt; &gt; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
&gt;&gt; &gt; &gt;&gt; &gt; Computers are like air conditioners.<br>
&gt;&gt; &gt; &gt;&gt; &gt; They malfunction when you open windows<br>
&gt;&gt; &gt; &gt;&gt; &gt; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
</blockquote></div>

--0000000000000db6c805994feea0--
0
b2gills
12/10/2019 2:04:07 AM
Reply: