Hi,

I seem to be having some problems with Brad's code. The 'boolean pick'
code seems far too clever for me to have intuited it on my own, so
(to expand my Raku/Perl6 vocabulary), I played around with matching
extra 'True' or 'False' values--as well as played around with seeing
if similar 'boolean elems' code would work. However the code (even
Brad's code) returned 'Nil' with alarming frequency (all code below
tested in the Raku/Perl6 REPL):

mbook:~ homedir$ perl6
To exit type 'exit' or '^D'
> 'TrueFalse' ~~ / <{ Bool.pick }> /
「False」
> 'FalseTrueFalse' ~~ / <{ Bool.pick }> /
「False」
> 'TrueFalseTrue' ~~ / <{ Bool.pick }> /
Nil
> 'TrueFalseTrue' ~~ / <{ Bool.elems }> /
Nil
> 'TrueFalse' ~~ / <{ Bool.elems }> /
Nil
> 'TrueFalse' ~~ / <{ Bool.pick }> /
Nil
> 'TrueFalse' ~~ / <{ Bool }> /
Cannot resolve caller INTERPOLATE_ASSERTION(Match:D: Bool:U, BOOTInt,
BOOTInt, BOOTInt, BOOTInt, PseudoStash:D); none of these signatures
match:
    (Match: Associative:D, $, $, $, $, $, *%_)
    (Match: Iterable:D \var, int \im, int \monkey, int \s, $, \context, *%_)
    (Match: Mu:D \var, int \im, int \monkey, $, $, \context, *%_)
  in block <unit> at <unknown file> line 1

> 'TrueFalse' ~~ / <{ Bool.say }> /
(Bool)
> say $*VM
moar (2020.02.1)
> exit
mbook:~ homedir$ perl6 --version
This is Rakudo version 2020.02.1.0000.1 built on MoarVM version 2020.02.1
implementing Raku 6.d.
mbook:~ homedir$

Any help appreciated, Bill.


On Sat, Jun 13, 2020 at 6:42 AM Brad Gilbert <b2gi...@gmail.com> wrote:
>
> Inside of a regex `{…}` will just run some regular Raku code.
> Code inside of it will most likely have no effect on what the regex matches.
>
> What you should have written was:
>
>     $<sol> = "@W[3]"
>
> The thing you were thinking of was:
>
>     $<sol> = <{ @W[3] }>
>
> Which could have been written as:
>
>     <sol={ @W[3] }>
>
> ---
>
> To have the result of regular Raku code have an effect on the match, it has 
> to have <…> around it
>
>     'TrueFalse' ~~ / <{ Bool.pick }> /
>
> I think it is better if you use "…" if you are just interpolating a variable, 
> because that is something you might do outside of a regex as well.
>
> ---
>
> The reason your code matched is that an empty regex always matches.
>
>     'abc' ~~ / "" /
>     'abc' ~~ / {} /
>     'abc' ~~ / {'def'} / # still an empty regex as far as the regex engine is 
> concerned
>
> On Sat, Jun 13, 2020 at 5:35 AM Richard Hainsworth <rnhainswo...@gmail.com> 
> wrote:
>>
>> I was playing with a regex and array interpolation.
>>
>> From the documentation I thought the following comparisons would be the 
>> same, but they are not.
>>
>> What am I missing?
>>
>> my @W = <perl weekly challenge with some extra things>;
>> my $S = 'perlchallengeextrathingswithweeklysome' ; # randomly concatenate 
>> the words without spaces
>> say 'yes' if $S ~~ / $<sol>=( { @W[3] } ) /;
>> say $<sol>;
>> my $sol = @W[3]; # with
>> say 'yes' if $S ~~ / $<sol>=( $sol ) /;
>> say $<sol>;
>>
>> <response>
>> yes
>> 「」
>> yes
>> 「with」
>>
>>
>>

Reply via email to