Re: interpolating the return from embedded code in a regexp

2020-06-19 Thread William Michels via perl6-users
On Fri, Jun 19, 2020 at 12:12 AM Joseph Brenner wrote: > > > Anyway, I had quite forgotten that you had updated to 2020.05.1 (I thought > > you were > still on 2019.03.1). > > I still use the 2019.03 release pretty frequently, but I've got a > newer release around I can check with. > > > FYI, I

Re: interpolating the return from embedded code in a regexp

2020-06-19 Thread Joseph Brenner
> Anyway, I had quite forgotten that you had updated to 2020.05.1 (I thought > you were still on 2019.03.1). I still use the 2019.03 release pretty frequently, but I've got a newer release around I can check with. > FYI, I had been trying to write a line of code that calls the ".words" method

Re: interpolating the return from embedded code in a regexp

2020-06-18 Thread William Michels via perl6-users
Hi Joe, Yup, your test file works perfectly: Last login: Thu Jun 18 19:38:12 on ttys000 user@mbook:~$ perl6 regexp_code_interpolation_with_capture_var.t ok 1 - case: {} $(... $0 ...) ok 2 - case: <{... $0 ... .subst(/\s/, '\s', :g)}> ok 3 - case: {} "... $0 ..." (brad gilbert rec) ok 4 - case:

Re: interpolating the return from embedded code in a regexp

2020-06-18 Thread Joseph Brenner
I don't have a 2020.02.1 around, but I see all of this working with both more recent and earlier versions: 2020.05.1 and 2019.03.1. > 1. I got your first "if" line (below) from June 14th to work, the one > you said, "it's not a complete solution": > 1> if $line ~~ / (^P\d+) \s+ <{

Re: interpolating the return from embedded code in a regexp

2020-06-18 Thread William Michels via perl6-users
Hi Joe, 1. I got your first "if" line (below) from June 14th to work, the one you said, "it's not a complete solution": 1> if $line ~~ / (^P\d+) \s+ <{ %products{$0}.subst(/\s+/, '\s', :g) }> / { 2. I got Brad's "if" line (below) from June 15th to work: 2> if $line ~~ / (^P\d+) \s+ {}

Re: interpolating the return from embedded code in a regexp

2020-06-17 Thread William Michels via perl6-users
Just wondering if the docs describe how to access an "inner" capture once saved to a variable? If not maybe the code below would be helpful (from yary's last example, REPL output): > my $capture = "1122" ~~ /(\d) {} :my $c=$0; ($c (\d) $0)/ 「1122」 0 => 「1」 1 => 「122」 0 => 「2」 > say $capture

Re: interpolating the return from embedded code in a regexp

2020-06-17 Thread Joseph Brenner
On 6/15/20, yary wrote: > The Match docs can be clearer on when to use {} and when it isn't needed, I agree, in fact I'm inclined to think this is an actual bug (design error?). It's pretty strange that the two kinds of code interpolation behave so differently: $(...) requires you to do

Re: interpolating the return from embedded code in a regexp

2020-06-17 Thread Joseph Brenner
Brad Gilbert wrote: > You don't want to use <{…}>, you want to use "" > if $line ~~ / (^P\d+) \s+ {} "%products{$0}" / { Well, as contrived examples go this one could be improved. Instead of directly dereferencing a hash, maybe I should've used a sub call. > Note that {} is there to

Re: interpolating the return from embedded code in a regexp

2020-06-15 Thread yary
Brad: "Note that {} is there to update $/ so that $0 works the way you would expect" I ran into that before & was trying to remember that detail... found it in https://docs.raku.org/language/regexes#Capture_numbers But the example is a bit on the obtuse side: These capture variables are only

Re: interpolating the return from embedded code in a regexp

2020-06-15 Thread Brad Gilbert
You don't want to use <{…}>, you want to use "" if $line ~~ / (^P\d+) \s+ {} "%products{$0}" / { Note that {} is there to update $/ so that $0 works the way you would expect Although I would do something like this instead: my ($code,$desc) = $line.split( /\s+/, 2 ); if

Re: interpolating the return from embedded code in a regexp

2020-06-14 Thread yary
True, and I am well and truly baffled by my example where the 1st bad line incorrectly is labelled good, the 2nd bad line is correctly labelled bad, and the 3rd good like is correctly labelled good. -y On Sun, Jun 14, 2020 at 6:04 PM Joseph Brenner wrote: > > Just to be be clear, my idea is

Re: interpolating the return from embedded code in a regexp

2020-06-14 Thread Joseph Brenner
> Just to be be clear, my idea is the second line is wrong, and it should flag that one as a problem Oh, but if you go literally with the code I posted, *both* the first and second lines have incorrect descriptions, and only the third line ("corn dogs") matches. (That was a mistake when I

Re: interpolating the return from embedded code in a regexp

2020-06-14 Thread Joseph Brenner
Getting correct behavior is an improvement over my try like so, which gets the same warning but fails all the lines: / (^P\d+) \s+ $(%products{$0}) / On 6/14/20, yary wrote: > I should have read the output! > > This one gives the right answers but with lots of warnings > / (^P\d+) \s+

Re: interpolating the return from embedded code in a regexp

2020-06-14 Thread yary
I should have read the output! This one gives the right answers but with lots of warnings / (^P\d+) \s+ $("%products{$0}") / checking line: P123 Viridian Green Label Saying Magenta Use of Nil in string context in regex at regex-loop.p6 line 18 Use of Nil in string context in regex at

Re: interpolating the return from embedded code in a regexp

2020-06-14 Thread Joseph Brenner
Well, with the first one it rejects all of my lines, and with the second one it passes all of them. Just to be be clear, my idea is the second line is wrong, and it should flag that one as a problem On 6/14/20, yary wrote: > https://docs.raku.org/language/regexes#Regex_interpolation gave

Re: interpolating the return from embedded code in a regexp

2020-06-14 Thread yary
https://docs.raku.org/language/regexes#Regex_interpolation gave me some ideas Try matching against / (^P\d+) \s+ %products{$0} / This one also works, in a roundabout way / (^P\d+) \s+ {"%products{$0}"} / -y On Sun, Jun 14, 2020 at 4:44 PM Joseph Brenner wrote: > In part because of the