Re: Variable character class

2019-09-08 Thread Laurent Rosenfeld via perl6-users
Because sets are unordered collections of items. And the (&) operator returns a set. Le dim. 8 sept. 2019 à 00:18, Aureliano Guedes a écrit : > Why does it dont return ordered for neither of those lists? > I mean: > > my $u = "24680"; > my @s = $u.comb.unique; > say @s ; # [2 4 6 8 0] > > sub

Re: Variable character class

2019-09-07 Thread Aureliano Guedes
Why does it dont return ordered for neither of those lists? I mean: my $u = "24680"; my @s = $u.comb.unique; say @s ; # [2 4 6 8 0] sub matching_chars(Str $a, Str $b) { my @c = $a.comb.unique; my @d = $b.comb.unique; return ~[@c (&) @d]; } say matching_chars("24680", "1234567890"); # sa

Re: Variable character class

2019-09-05 Thread William Michels via perl6-users
Hi Gianni, I think we're looking at two different aspects of the same problem. I'm just concerned with learning Perl6 regexes. Presumably many people will continue to use Perl5 regexes for a long time to come (for reasons of familiarity, and/or speed). Regarding Perl6 regexes, your last two P6 ex

Re: Variable character class

2019-09-05 Thread Gianni Ceccarelli
On Wed, 4 Sep 2019 21:44:29 -0700 William Michels via perl6-users wrote: > Hi Gianni, I'm not sure of the Perl5 case, but what you're saying is, > if your target string is backslashed, be sure to "quote-interpolate > it" in Perl6? (see below): Re-reading what I wrote, I realise it was really not

Re: Variable character class

2019-09-04 Thread William Michels via perl6-users
Hi Gianni, I'm not sure of the Perl5 case, but what you're saying is, if your target string is backslashed, be sure to "quote-interpolate it" in Perl6? (see below): say matching_chars( '+/][', 'Apple ][+//e' ); # says (「][+//」) say matching_chars( '+\/\]\[', 'Apple ][+//e' ); # says (「][+//」) say

Re: Variable character class

2019-09-03 Thread William Michels via perl6-users
I'm wrong then. Nowhere on that reference page does the character construction "<{...}>" (block wrapped in angle brackets) appear. Per your reference, "pointy-blocks" seems to refer to an arrow in conjunction with a block, as mentioned three times on the 'Python-to-Perl6' page: https://docs.perl6

Re: Variable character class

2019-09-03 Thread The Sidhekin
On Tue, Sep 3, 2019 at 8:18 PM William Michels wrote: > PS Eirik, I think people might be referring to <{...}> as "pointy > blocks", but I'm really not sure... . > I'm pretty sure Perl6 pointy blocks still refer to block constructors with signatures, like: C<< my $add = -> $a, $b = 2 { $a + $b

Re: Variable character class

2019-09-03 Thread William Michels via perl6-users
Someone might get a kick out of this ;-). Clearly regexes are built on top of set theory, but as both Simon and Yary pointed out, my set-based code didn't return the matching string "8420" present in the target. Example A, Eirik's code used an array to generate a character class, and then tested t

Re: Variable character class

2019-09-03 Thread Gianni Ceccarelli
On Tue, 3 Sep 2019 09:15:54 -0700 William Michels via perl6-users wrote: > Just a short note that Eirik's array-based code seems to work fine, > with-or-without backslash-escaping the first input string (minimal > testing, below): Oh, sure. But when the target string contains backslashes, it wil

Re: Variable character class

2019-09-03 Thread William Michels via perl6-users
Hi Gianni, Thank you for demonstrating use of the "Test" module in your code. Just a short note that Eirik's array-based code seems to work fine, with-or-without backslash-escaping the first input string (minimal testing, below): sub contains( Str $chars, Str $_ ) { my @arr = $chars.comb; m:g

Re: Variable character class

2019-09-02 Thread Joseph Brenner
> The "implicit" alternation comes from interpolating a list (of subrules, > see below). I see. And that's discussed here (had to really look for it): https://docs.perl6.org/language/regexes#Quoted_lists_are_LTM_matches At first I was looking further down in the "Regex interpolation" section,

Re: Variable character class

2019-09-02 Thread Gianni Ceccarelli
On 2019-09-02 The Sidhekin wrote: > To have the (1-character) strings used a literals, rather than > compiled as subrules, put them in an array instead of a block wrapped > in angle brackets: > > sub contains( Str $chars, Str $_ ) { > my @arr = $chars.comb; > m:g/@arr+/ This looks to be th

Re: Variable character class

2019-09-02 Thread Paul Procacci
I don't know then. I've created the following ticket: https://github.com/perl6/doc/issues/2999 Feel free to place your own input there if you feel the need. On Mon, Sep 2, 2019 at 12:37 PM William Michels wrote: > Sorry Paul, I don't get the correct answer in any of the three cases I > tried.

Re: Variable character class

2019-09-02 Thread William Michels via perl6-users
Sorry Paul, I don't get the correct answer in any of the three cases I tried. Here's what 6Pad returns: https://perl6.github.io/6pad/ sub matching_chars(Str $chars_to_match, Str $str) { # warnings, treats as string not variable $str ~~ /<$_>/ given "<[$chars_to_match]>"; } say matching_c

Re: Variable character class

2019-09-02 Thread Paul Procacci
Was talking to folks over on the #perl6 IRC channel. It appears the recommended way is: sub matching_chars(Str $chars_to_match, Str $str) { # warnings, treats as string not variable $str ~~ /<$_>/ given "<[$chars_to_match]>"; } ~Paul On Sat, Aug 31, 2019 at 9:54 PM yary wrote: > I fou

Re: Variable character class

2019-09-01 Thread William Michels via perl6-users
Hi Aureliano! Others will certainly have a more informed answer, but I think it might be because: 1). Set operations in general in Perl6 (on characters, etc.) may use a unordered matching algorithm to enhance speed, and/or 2). I didn't explicitly call a "Sort" method, function or routine in match

Re: Variable character class

2019-09-01 Thread William Michels via perl6-users
Thanks Simon, good point. I ran into the same trouble as others trying to get the answer via regex, and switched over to sets as an alternative. I'll confess I completely missed that Yary's Perl5 code returned the substring "8420" present in his test "19584203" string, and that was the answer he wa

Re: Variable character class

2019-09-01 Thread The Sidhekin
On Mon, Sep 2, 2019 at 1:12 AM Joseph Brenner wrote: > I was just trying to run Simon Proctor's solution, and I see it > working for Yary's first case, but not his more complex one with > problem characters like brackets included in the list of characters. > > I don't really see how to fix it, in

Re: Variable character class

2019-09-01 Thread Joseph Brenner
I was just trying to run Simon Proctor's solution, and I see it working for Yary's first case, but not his more complex one with problem characters like brackets included in the list of characters. I don't really see how to fix it, in part because I'm not that clear on what it's actually doing...

Re: Variable character class

2019-09-01 Thread yary
Hi Paul, Neither of those match for me- adapted below #!/usr/bin/env perl6 use v6; sub matching_chars(Str $match, Str $y) { say 'eval = ', $y.match: /<{ "<[$match]>" }>/; say 'direct= ', $y.match: /<[$match]>/; my $rematch := $match; say 'bound = ', $y.match: /<[$rematch]>/; s

Re: Variable character class

2019-09-01 Thread Paul Procacci
I've actually found some weird inconsistancy while playing with this. sub matching_chars(Str $x, Str $y) { my $a := $x; my $b := $y; say $y.match: /<[$a]>/; } That results in a match of one character, yet: sub matching_chars(Str $x, Str $y) { my $a := $x; my $b := $y; say

Re: Variable character class

2019-09-01 Thread yary
Thanks for the ideas. The core issue I'm probing is runtime construction of character classes, with an eye towards opening a documentation issue, or maybe even an issue against the character class implementation. Simon's workaround m:g/<{$chars.comb}>+/ is interesting, interpolating a list which

Re: Variable character class

2019-09-01 Thread Simon Proctor
Using a set would be good but it doesn't give you the matching string from the original (which is what I thought was required) otherwise Sets would be my first thought. On Sun, 1 Sep 2019, 17:57 William Michels, wrote: > Hi Yary and Paul and Simon, > > I ran into the same difficulties as Yary wi

Re: Variable character class

2019-09-01 Thread William Michels via perl6-users
Hi Yary and Paul and Simon, I ran into the same difficulties as Yary with repeated characters, so I tried the .unique method. Then after a while, I realized that problems like this might best be treated as "Set" problems in Perl6. Note the Set Intersection operator "(&)" below: sub matching_chars

Re: Variable character class

2019-09-01 Thread Simon Proctor
sub contains ( Str $chars, Str $_ ) { m:g/<{$chars.comb}>+/ }; This will return all the sets of matching strings but it is doing runtime evaluation of your character string so it's a bit slow. On Sun, 1 Sep 2019 at 04:59, Paul Procacci wrote: > I'm not entirely sure if this is the correct ans

Re: Variable character class

2019-08-31 Thread Paul Procacci
I'm not entirely sure if this is the correct answer, but if you define your own custom character class with a 'regex' object, you can use that in the grouping. sub matching_chars(Str $chars_to_match, Str $_) { my regex x { $chars_to_match ** 1 }; m/<[]>/; } The above worked for me in the

Variable character class

2019-08-31 Thread yary
I found something easy in Perl 5 that's puzzling me in Perl 6- specifying a character class via a variable. Perl 5: sub matching_chars { (my $chars_to_match, local $_) = @_; /([$chars_to_match]+)/ } say matching_chars('24680', '19584203'); # says 8420 say matching_chars('+\/\]\[', 'Apple ][+/