Re: Subset w/ Inline::Perl5 RE as constraint

2020-11-08 Thread Paul Procacci
 Thank you Bruce,

This does indeed help.  Like I mentioned to Joseph I have yet to test it
but because it's coming out of the SF Study group I imagine it works.  ;)
I'll certainly make noise if it doesn't.

Appreciate the time given to a follow-up.

~Paul

On Sun, Nov 8, 2020 at 7:42 PM Bruce Gray 
wrote:

> > On Fri, Nov 6, 2020 at 8:23 AM Paul Procacci 
> wrote:
> > >
> > > So two example patterns are:
> > >
> > >
> [\\u0009\\u000A\\u000D\\u0020-\\u007E\\u0085\\u00A0-\\uD7FF\\uE000-\\uFFFD\\u1-\\u10]*
> > > [\\p{L}\\p{Z}\\p{N}_.:\\/=+\\-@]*
> > >
> > > To note, the RE's themselves cannot be changed as they are fed
> externally.
> > > Given that I'm stuck with these RE's which I believe are PCRE, It was
> my hopes to lean on perl to do the evaluation.
> > > Raku's perl regex engine is too old to interpret it properly, hence
> the shenanigans with Inline::Perl5.
>
> —snip—
>
> This came out of the San Francisco Raku study group, just now.
>
> # This part is the set-up to allow interpolation of the P5 regex into a
> callable sub.
> use Inline::Perl5;
> use MONKEY-SEE-NO-EVAL;
> my $regex_string = '\w'; # In reality, this comes from a file!
>
> # Returns 1e0 when True and Nil when False.
> my $is_valid_sub = Inline::Perl5.new.run("
> sub \{
> return \$_[0] =~ /$regex_string/;
> \}
> ");
> # Wrapper to allow naming the sub (instead of anonymous sub in a variable),
> # and forces the return values to be the clearer Bool::True and
> Bool::False.
> sub is-valid ( $candidate --> Bool ) {
> return ? $is_valid_sub.($candidate);
> }
>
> # Test what we have so far.
> say is-valid('abc').raku;
> say is-valid('^').raku;
>
> # You don't really need a subtype
> multi sub real-use-of-where ( $var1 where { is-valid($^var1) } ) {
> say "This is definitely valid: $var1";
> }
> multi sub real-use-of-where ( $var1 ) {
> say "Not valid: $var1";
> }
> # Test it.
> real-use-of-where('abc');
> real-use-of-where('^');
>
> # Now make the subset, and use it as a type. The `where` is no longer
> needed.
> subset test-set of Str where *.
> sub real-use-of-subsets ( test-set $var1 ) {
> say "This is definitely a `test-set`: $var1";
> }
> sub real-use-of-subsets ( test-set $var1 ) {
> say "Not a `test-set`: $var1";
> }
> # Test it.
> real-use-of-subsets('abc');
> real-use-of-subsets('^’);
>
> —
> Hope this helps,
> Bruce Gray (Util of PerlMonks)
>
>

-- 
__

:(){ :|:& };:


Re: Subset w/ Inline::Perl5 RE as constraint

2020-11-08 Thread Paul Procacci
Thank you Joseph,

Your response along with Bruce's response (which I'll respond to
separately) I presume works.
My hopes of fitting this into a one liner are crushed!   lol  Nah, just
playing.

Thank you for taking the time to respond.
This certainly helps with my project.

~Paul

On Sun, Nov 8, 2020 at 6:32 PM Joseph Brenner  wrote:

> I think this kind of thing does what you're after:
>
> use Inline::Perl5;
> my $p5 = Inline::Perl5.new;
>
> my $p5pat = '\w+';
> $p5.run( 'sub chk { $_[0] =~ m/' ~ $p5pat ~ '/ }' );
> subset p5_words of Str where { $p5.call( "chk", $^a ) };
>
> my p5_words $a = "alpha";
> say $a; # alpha,  perl5 word chars, so acceptable to subset
> my p5_words $b = "^";  # Type check failed in assignment to $b;
> expected str_p5 but got Str ("^")
> # Errors out because carets don't pass \w check
>
>
> It could probably be cleaned up a little more, but it works.
>
>
> On 11/5/20, Paul Procacci  wrote:
> > https://github.com/niner/Inline-Perl5
> >
> > use Inline::Perl5;
> >
> > subset test of Str where EVAL "sub {@_[0] ~= m/\w+/}", :lang;
> >
> >
> > Question:  Can you pass whatever {*} into eval for use in Inline::Perl5 a
> > la subset?
> > The above example is incomplete, I understand, however I'm looking to
> find
> > a method of constraining Str's w/ >perl5.8 RE's in subset's without it
> > getting too crazy.
> >
> > The RE's that come w/ raku proper are are much older version of RE and
> > cannot accomplish what I need.
> >
> > Thanks in Advance,
> > ~Paul
> >
> > --
> > __
> >
> > :(){ :|:& };:
> >
>


-- 
__

:(){ :|:& };:


Re: Subset w/ Inline::Perl5 RE as constraint

2020-11-08 Thread Bruce Gray
> On Fri, Nov 6, 2020 at 8:23 AM Paul Procacci  wrote:
> >
> > So two example patterns are:
> >
> > [\\u0009\\u000A\\u000D\\u0020-\\u007E\\u0085\\u00A0-\\uD7FF\\uE000-\\uFFFD\\u1-\\u10]*
> > [\\p{L}\\p{Z}\\p{N}_.:\\/=+\\-@]*
> >
> > To note, the RE's themselves cannot be changed as they are fed externally.
> > Given that I'm stuck with these RE's which I believe are PCRE, It was my 
> > hopes to lean on perl to do the evaluation.
> > Raku's perl regex engine is too old to interpret it properly, hence the 
> > shenanigans with Inline::Perl5.

—snip—

This came out of the San Francisco Raku study group, just now.

# This part is the set-up to allow interpolation of the P5 regex into a 
callable sub.
use Inline::Perl5;
use MONKEY-SEE-NO-EVAL;
my $regex_string = '\w'; # In reality, this comes from a file!

# Returns 1e0 when True and Nil when False.
my $is_valid_sub = Inline::Perl5.new.run("
sub \{
return \$_[0] =~ /$regex_string/;
\}
");
# Wrapper to allow naming the sub (instead of anonymous sub in a variable),
# and forces the return values to be the clearer Bool::True and Bool::False.
sub is-valid ( $candidate --> Bool ) {
return ? $is_valid_sub.($candidate);
}

# Test what we have so far.
say is-valid('abc').raku;
say is-valid('^').raku;

# You don't really need a subtype
multi sub real-use-of-where ( $var1 where { is-valid($^var1) } ) {
say "This is definitely valid: $var1";
}
multi sub real-use-of-where ( $var1 ) {
say "Not valid: $var1";
}
# Test it.
real-use-of-where('abc');
real-use-of-where('^');

# Now make the subset, and use it as a type. The `where` is no longer needed.
subset test-set of Str where *.
sub real-use-of-subsets ( test-set $var1 ) {
say "This is definitely a `test-set`: $var1";
}
sub real-use-of-subsets ( test-set $var1 ) {
say "Not a `test-set`: $var1";
}
# Test it.
real-use-of-subsets('abc');
real-use-of-subsets('^’);

— 
Hope this helps,
Bruce Gray (Util of PerlMonks)


Re: Subset w/ Inline::Perl5 RE as constraint

2020-11-08 Thread Joseph Brenner
I think this kind of thing does what you're after:

use Inline::Perl5;
my $p5 = Inline::Perl5.new;

my $p5pat = '\w+';
$p5.run( 'sub chk { $_[0] =~ m/' ~ $p5pat ~ '/ }' );
subset p5_words of Str where { $p5.call( "chk", $^a ) };

my p5_words $a = "alpha";
say $a; # alpha,  perl5 word chars, so acceptable to subset
my p5_words $b = "^";  # Type check failed in assignment to $b;
expected str_p5 but got Str ("^")
# Errors out because carets don't pass \w check


It could probably be cleaned up a little more, but it works.


On 11/5/20, Paul Procacci  wrote:
> https://github.com/niner/Inline-Perl5
>
> use Inline::Perl5;
>
> subset test of Str where EVAL "sub {@_[0] ~= m/\w+/}", :lang;
>
>
> Question:  Can you pass whatever {*} into eval for use in Inline::Perl5 a
> la subset?
> The above example is incomplete, I understand, however I'm looking to find
> a method of constraining Str's w/ >perl5.8 RE's in subset's without it
> getting too crazy.
>
> The RE's that come w/ raku proper are are much older version of RE and
> cannot accomplish what I need.
>
> Thanks in Advance,
> ~Paul
>
> --
> __
>
> :(){ :|:& };:
>


Re: Subset w/ Inline::Perl5 RE as constraint

2020-11-06 Thread William Michels via perl6-users
Thank you Paul!

On Fri, Nov 6, 2020 at 8:57 AM Paul Procacci  wrote:
>
> Hi Bill,
>
> Yes, that is exactly what I'm saying.
>
> https://github.com/rakudo/rakudo/issues/2624
>
> " FWIW, the :P5 supports a Perl 5 like syntax from X versions ago (probably 
> about 5.8, I would say)."
>
> The features I need are in perl 5.10 which the :P5 adverb doesn't provide.
>
> Thanks,
> Paul
>
> On Fri, Nov 6, 2020 at 11:47 AM William Michels  wrote:
>>
>> Hi Paul,
>>
>> I'm sorry, I don't understand.
>>
>> Are you saying you're using Inline::Perl5 because you can't use the
>> "Perl compatibility adverb" :Perl5 or :P5 ?
>>
>> https://docs.raku.org/language/regexes#Perl_compatibility_adverb
>>
>> Is that what you mean when you say the "perl regex engine [in Raku] is
>> too old" ?
>>
>> Thanks, Bill.
>>
>>
>>
>>
>>
>> On Fri, Nov 6, 2020 at 8:23 AM Paul Procacci  wrote:
>> >
>> > So two example patterns are:
>> >
>> > [\\u0009\\u000A\\u000D\\u0020-\\u007E\\u0085\\u00A0-\\uD7FF\\uE000-\\uFFFD\\u1-\\u10]*
>> > [\\p{L}\\p{Z}\\p{N}_.:\\/=+\\-@]*
>> >
>> > To note, the RE's themselves cannot be changed as they are fed externally.
>> > Given that I'm stuck with these RE's which I believe are PCRE, It was my 
>> > hopes to lean on perl to do the evaluation.
>> > Raku's perl regex engine is too old to interpret it properly, hence the 
>> > shenanigans with Inline::Perl5.
>> >
>> > Thanks,
>> > Paul
>> >
>> >
>> > On Fri, Nov 6, 2020 at 9:51 AM Parrot Raiser <1parr...@gmail.com> wrote:
>> >>
>> >> Can you provide some samples of what you are trying to match and
>> >> exclude? There might be alternative solutions.
>> >
>> >
>> >
>> > --
>> > __
>> >
>> > :(){ :|:& };:
>
>
>
> --
> __
>
> :(){ :|:& };:


Re: Subset w/ Inline::Perl5 RE as constraint

2020-11-06 Thread Paul Procacci
Hi Bill,

Yes, that is exactly what I'm saying.

https://github.com/rakudo/rakudo/issues/2624

" FWIW, the :P5 supports a Perl 5 like syntax from X versions ago (probably
about 5.8, I would say)."

The features I need are in perl 5.10 which the :P5 adverb doesn't provide.

Thanks,
Paul

On Fri, Nov 6, 2020 at 11:47 AM William Michels 
wrote:

> Hi Paul,
>
> I'm sorry, I don't understand.
>
> Are you saying you're using Inline::Perl5 because you can't use the
> "Perl compatibility adverb" :Perl5 or :P5 ?
>
> https://docs.raku.org/language/regexes#Perl_compatibility_adverb
>
> Is that what you mean when you say the "perl regex engine [in Raku] is
> too old" ?
>
> Thanks, Bill.
>
>
>
>
>
> On Fri, Nov 6, 2020 at 8:23 AM Paul Procacci  wrote:
> >
> > So two example patterns are:
> >
> >
> [\\u0009\\u000A\\u000D\\u0020-\\u007E\\u0085\\u00A0-\\uD7FF\\uE000-\\uFFFD\\u1-\\u10]*
> > [\\p{L}\\p{Z}\\p{N}_.:\\/=+\\-@]*
> >
> > To note, the RE's themselves cannot be changed as they are fed
> externally.
> > Given that I'm stuck with these RE's which I believe are PCRE, It was my
> hopes to lean on perl to do the evaluation.
> > Raku's perl regex engine is too old to interpret it properly, hence the
> shenanigans with Inline::Perl5.
> >
> > Thanks,
> > Paul
> >
> >
> > On Fri, Nov 6, 2020 at 9:51 AM Parrot Raiser <1parr...@gmail.com> wrote:
> >>
> >> Can you provide some samples of what you are trying to match and
> >> exclude? There might be alternative solutions.
> >
> >
> >
> > --
> > __
> >
> > :(){ :|:& };:
>


-- 
__

:(){ :|:& };:


Re: Subset w/ Inline::Perl5 RE as constraint

2020-11-06 Thread William Michels via perl6-users
Hi Paul,

I'm sorry, I don't understand.

Are you saying you're using Inline::Perl5 because you can't use the
"Perl compatibility adverb" :Perl5 or :P5 ?

https://docs.raku.org/language/regexes#Perl_compatibility_adverb

Is that what you mean when you say the "perl regex engine [in Raku] is
too old" ?

Thanks, Bill.





On Fri, Nov 6, 2020 at 8:23 AM Paul Procacci  wrote:
>
> So two example patterns are:
>
> [\\u0009\\u000A\\u000D\\u0020-\\u007E\\u0085\\u00A0-\\uD7FF\\uE000-\\uFFFD\\u1-\\u10]*
> [\\p{L}\\p{Z}\\p{N}_.:\\/=+\\-@]*
>
> To note, the RE's themselves cannot be changed as they are fed externally.
> Given that I'm stuck with these RE's which I believe are PCRE, It was my 
> hopes to lean on perl to do the evaluation.
> Raku's perl regex engine is too old to interpret it properly, hence the 
> shenanigans with Inline::Perl5.
>
> Thanks,
> Paul
>
>
> On Fri, Nov 6, 2020 at 9:51 AM Parrot Raiser <1parr...@gmail.com> wrote:
>>
>> Can you provide some samples of what you are trying to match and
>> exclude? There might be alternative solutions.
>
>
>
> --
> __
>
> :(){ :|:& };:


Re: Subset w/ Inline::Perl5 RE as constraint

2020-11-06 Thread Paul Procacci
So two example patterns are:

[\\u0009\\u000A\\u000D\\u0020-\\u007E\\u0085\\u00A0-\\uD7FF\\uE000-\\uFFFD\\u1-\\u10]*
[\\p{L}\\p{Z}\\p{N}_.:\\/=+\\-@]*

To note, the RE's themselves cannot be changed as they are fed externally.
Given that I'm stuck with these RE's which I believe are PCRE, It was my
hopes to lean on perl to do the evaluation.
Raku's perl regex engine is too old to interpret it properly, hence the
shenanigans with Inline::Perl5.

Thanks,
Paul


On Fri, Nov 6, 2020 at 9:51 AM Parrot Raiser <1parr...@gmail.com> wrote:

> Can you provide some samples of what you are trying to match and
> exclude? There might be alternative solutions.
>


-- 
__

:(){ :|:& };:


Re: Subset w/ Inline::Perl5 RE as constraint

2020-11-06 Thread Brad Gilbert
I'm pretty sure you need to use single quotes for your example, as Raku
will replace the @_[0] before Perl has a chance to do anything with it.

On Thu, Nov 5, 2020, 10:23 PM Paul Procacci  wrote:

> https://github.com/niner/Inline-Perl5
>
> use Inline::Perl5;
>
> subset test of Str where EVAL "sub {@_[0] ~= m/\w+/}", :lang;
>
>
> Question:  Can you pass whatever {*} into eval for use in Inline::Perl5 a
> la subset?
> The above example is incomplete, I understand, however I'm looking to find
> a method of constraining Str's w/ >perl5.8 RE's in subset's without it
> getting too crazy.
>
> The RE's that come w/ raku proper are are much older version of RE and
> cannot accomplish what I need.
>
> Thanks in Advance,
> ~Paul
>
> --
> __
>
> :(){ :|:& };:
>


Re: Subset w/ Inline::Perl5 RE as constraint

2020-11-06 Thread Parrot Raiser
Can you provide some samples of what you are trying to match and
exclude? There might be alternative solutions.


Subset w/ Inline::Perl5 RE as constraint

2020-11-05 Thread Paul Procacci
https://github.com/niner/Inline-Perl5

use Inline::Perl5;

subset test of Str where EVAL "sub {@_[0] ~= m/\w+/}", :lang;


Question:  Can you pass whatever {*} into eval for use in Inline::Perl5 a
la subset?
The above example is incomplete, I understand, however I'm looking to find
a method of constraining Str's w/ >perl5.8 RE's in subset's without it
getting too crazy.

The RE's that come w/ raku proper are are much older version of RE and
cannot accomplish what I need.

Thanks in Advance,
~Paul

-- 
__

:(){ :|:& };: