Mailing List Archive

infix feature exploration with Sub::Infix (TOBYINK) ?
First, I am sorry for being *that* guy with neilb's email. I'll read
more carefully in the future.

On to the subject of the email. Since really learning about the primary
use case for sub prototypes, I've been trying to determine if one could
use it - or something - to use current perl to define an infix operator.

I decided to search CPAN (duh) and found Sub::Infix. It satisfies what I
would imagine such a native capability would provide. Even better, it's
on CPAN.

Is there a deficiency in this approach that requires time being spent on
other solutions? A person owns their time, so no judgment. I am just
wondering if this was even known or considered?

https://metacpan.org/pod/Sub::Infix

Incidentally, I recommend peering at TOBYINK's modules. His work first
caught my eye one night late as I was perusing CPAN 'recent' - something
I do often, with his "Mom" module. I mean, who wouldn't click that? The
result was me actually considering using Moo.

There are also things like Zydeco - an OOP framework I'd actually
consider using due to its lack of boiler plate. (Incidentally, a true
hidden gem of perl OOP IMO is HAUKEX's Util::H2O; recommend that if you
have not seen it).

I am pointing out many things here and highlighted TOBYINK because I was
already aware of his innovative use of exiting perl/Perl. This is the
spirit I wish to promote. He's not the only one, I do have a short list
of authors I've really come to appreciate.

Another reason I am pointing this out has to do with the idea of
sane/humane feature development. Is there a reason Sub::Infix can't be
the way that custom infix operators as-CPAN modules can't be explored? I
have not tried to implement the doh operator ... yet :)

So I submit that part of the "sane" approach would be to somehow
determine a short list of perl's most requested language extensions.
From, create a short description (but not too short) of what it should
do; then make open calls for our most creative and ambitious perlers to
create a prototype on CPAN. The purpose of this is to a) see if such a
thing would be possible in pure Pure (or babby XS); b) flesh out
questions about how to make it "perlish", and c) provide users with a
one or more implementations on CPAN to test the usefulness of such
module(s) - I suppose a "reverse dep" check on other CPAN modules is
probably a better and more implicit way to determine this - it's already
there now.

Finally, I'd like to suggest that if having an easy way to add infix
operators in Perl is indeed a potential for game changing features
exploration, we should make an official call to any interested part to;
using Sub::Infix to submit any number of trial infix operators by
publishing them on CPAN (even under some Trial:: type of name space, or
not). And we can go from there. If this is _good enough_ to test the
efficacy of different infix options, is Sub::Infix not something that we
could use to rapidly prototype them? And better still, maybe someone
will figure out Sub::Infix::Tiny (bonus points if so). And maybe we'll
discover a) Sub::Infix is perfect and should be promoted to "dual life"
or generate new ideas to test in this way (e.g., CPAN 'feature' Challenge).

Unless I am grossly judging what I foresee, LeoNerd (e.g., and not to be
insensitive or presumptuous) would be able to focus on other things if
he wishes. If not, fine also. This is is not about me, him, or anyone -
it's about working out what the process to featurehood is. Furthermore,
this could end up showing that Sub::Infix is insufficient in some way
that requires core changies; and that my general points are flawed in
some fundamental ways.

FWIW, I could see the "call" to be handled in much the same way as the
original PRCs were. This really pulled me in when neilb started doing
them years ago. And I will be forever grateful that he did.

I suppose if I *should* offer to facilitate such a "challenge". So here
it goes, if anyone is interested in participating in such a 'CPAN
feature Challenge', email me (off list preferred). Please don't wait 24
hours to let me know.

Cheers,
Brett :)
Re: infix feature exploration with Sub::Infix (TOBYINK) ? [ In reply to ]
On Fri, 16 Apr 2021 09:48:09 -0500
"B. Estrade" <brett@cpanel.net> wrote:

> First, I am sorry for being *that* guy with neilb's email. I'll read
> more carefully in the future.
>
> On to the subject of the email. Since really learning about the
> primary use case for sub prototypes, I've been trying to determine if
> one could use it - or something - to use current perl to define an
> infix operator.
>
> I decided to search CPAN (duh) and found Sub::Infix. It satisfies
> what I would imagine such a native capability would provide. Even
> better, it's on CPAN.
>
> Is there a deficiency in this approach that requires time being spent
> on other solutions? A person owns their time, so no judgment. I am
> just wondering if this was even known or considered?
>
> https://metacpan.org/pod/Sub::Infix

To quote its docs:

> Sub::Infix creates fake infix operators using overloading.

Its own synopsis has:

# Operator needs to be defined (or imported) at compile time.
BEGIN { *plus = infix { $_[0] + $_[1] } };

my $five = 2 |plus| 3;

Not wishing to turn this mail into a long critique of Sub::Infix, but
that's a) terrible, and b) about the best you can do from Pure Perl.

Basically you can only have identifier-named operators and they have to
be surrounded by |pipes|.

...
> Finally, I'd like to suggest that if having an easy way to add infix
> operators in Perl is indeed a potential for game changing features
> exploration, we should make an official call to any interested part
> to; using Sub::Infix to submit any number of trial infix operators by
> publishing them on CPAN (even under some Trial:: type of name space,
> or not). And we can go from there. If this is _good enough_ to test
> the efficacy of different infix options, is Sub::Infix not something
> that we could use to rapidly prototype them? And better still, maybe
> someone will figure out Sub::Infix::Tiny (bonus points if so). And
> maybe we'll discover a) Sub::Infix is perfect and should be promoted
> to "dual life" or generate new ideas to test in this way (e.g., CPAN
> 'feature' Challenge).

I already have a much better way to do these; my upcoming
XS::Parse::Infix. That allows this - taken from the unit tests of
Syntax::Operator::Equ:

ok( "abc" equ "abc", 'identical strings');
ok(!("abc" equ "def"), 'different strings');

ok( 123 === 123, 'identical strings');
ok(!(123 === 456), 'different strings');

Notice a) the lack of |pipes| and b) the use of non-identifier
operators; ie. the ===.

This technique is more powerful still; it can create hyperoperators as
well (i.e. operators that work on other syntax, such as other
operators). This from Syntax::Operator::In:

ok( "c" in<eq> ("a".."e") , 'c is in a..e');
ok(not("f" in<eq> ("a".."e")), 'f is not in a..e');

--
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/
Re: infix feature exploration with Sub::Infix (TOBYINK) ? [ In reply to ]
On 4/16/21 10:52 AM, Paul "LeoNerd" Evans wrote:
> On Fri, 16 Apr 2021 09:48:09 -0500
> "B. Estrade" <brett@cpanel.net> wrote:
>
>> First, I am sorry for being *that* guy with neilb's email. I'll read
>> more carefully in the future.
>>
>> On to the subject of the email. Since really learning about the
>> primary use case for sub prototypes, I've been trying to determine if
>> one could use it - or something - to use current perl to define an
>> infix operator.
>>
>> I decided to search CPAN (duh) and found Sub::Infix. It satisfies
>> what I would imagine such a native capability would provide. Even
>> better, it's on CPAN.
>>
>> Is there a deficiency in this approach that requires time being spent
>> on other solutions? A person owns their time, so no judgment. I am
>> just wondering if this was even known or considered?
>>
>> https://metacpan.org/pod/Sub::Infix
>
> To quote its docs:
>
> > Sub::Infix creates fake infix operators using overloading.
>
> Its own synopsis has:
>
> # Operator needs to be defined (or imported) at compile time.
> BEGIN { *plus = infix { $_[0] + $_[1] } };
>
> my $five = 2 |plus| 3;
>
> Not wishing to turn this mail into a long critique of Sub::Infix, but
> that's a) terrible, and b) about the best you can do from Pure Perl.
>

Sub::Infix is a straw man. A relevant straw man, but one none the less.
I am not presenting it to be burned for effigy, but something needs to
service this role.

This is great feedback. #a notwithstanding, #b is an extremely helpful
statement.

My next question towards my interest is, can we leverage this "best you
can do" to explore the evaluation of language features.

Necessarily, starting with "best one can do" in pure Perl is the precise
place we need to exert the greatest pressure.

a) is this actually sufficient to deliver the actual value of custom infix?

b) do we really want custom postfix/circumfix/etc (this would a nice
follow up "challenge")

c) did we learn that what people *really* want are "hyperops" (not sure
I understand that concept yet)?

Given a, b, c above; what fundamental core capabilities, if they do not
exist or require "terrible" things, need to be provided so that these
kind of language extensions *can* be satisfactorily facilitated using
merely pure Perl or babby XS?

In other words, what *actually* needs to be added to perl such that it
maximizes the number of CPAN contributions either provide or leverage
these capabilities?

In other other words, what core work provides the most value? And this
ultimately is the "search space" over which we're operating for language
extensions and allocating time, effort, and personal investment to achieve.

This kind of exercise is not like search optimization algorithms, like
simulated annealing. We may be "stuck" in a local maximum/minimum with
regards to Perl. And we need to "shake it up" to continue along the
search for what Perl looks like optimally. I don't know if you
understand that analogy, but it's one I have quickly at hand.

>
> Basically you can only have identifier-named operators and they have to
> be surrounded by |pipes|.
>
> ...
>> Finally, I'd like to suggest that if having an easy way to add infix
>> operators in Perl is indeed a potential for game changing features
>> exploration, we should make an official call to any interested part
>> to; using Sub::Infix to submit any number of trial infix operators by
>> publishing them on CPAN (even under some Trial:: type of name space,
>> or not). And we can go from there. If this is _good enough_ to test
>> the efficacy of different infix options, is Sub::Infix not something
>> that we could use to rapidly prototype them? And better still, maybe
>> someone will figure out Sub::Infix::Tiny (bonus points if so). And
>> maybe we'll discover a) Sub::Infix is perfect and should be promoted
>> to "dual life" or generate new ideas to test in this way (e.g., CPAN
>> 'feature' Challenge).
>
> I already have a much better way to do these; my upcoming
> XS::Parse::Infix. That allows this - taken from the unit tests of
> Syntax::Operator::Equ:
>
> ok( "abc" equ "abc", 'identical strings');
> ok(!("abc" equ "def"), 'different strings');
>
> ok( 123 === 123, 'identical strings');
> ok(!(123 === 456), 'different strings');
>
> Notice a) the lack of |pipes| and b) the use of non-identifier
> operators; ie. the ===.
>
> This technique is more powerful still; it can create hyperoperators as
> well (i.e. operators that work on other syntax, such as other
> operators). This from Syntax::Operator::In:
>
> ok( "c" in<eq> ("a".."e") , 'c is in a..e');
> ok(not("f" in<eq> ("a".."e")), 'f is not in a..e');
>

Thank you. I can't argue about how compelling an ability to do something
is. I am attempting to figure out for myself, how determine where to
allocate effort and personal investment as cheaply as possible.

The obvious answer for me is, we have a huge warehouse of options. Let's
see what we can do to justify the human capital involved in "going deep"
into Perl.

I have already, sufficiently I think, proven that 'trim' and 'say'
should never have been implemented in core. One ship has sailed, another
hopefully has sparked a greater journey of discovery. 'isa', I can't
speak of, but it's striking how much less code it took to implement than
'trim'. Now I believe I have provided a compelling pathway to:

* "cheaply" determine what infix ops would be unexpectedly useful
* provide an opportunity to explore *what* can't be done in pure Perl or
baby XS, and therefore warrants deeper core support
* continue to develop this "model" for new feature exploration and
cleanly determining exactly what core support is needed

I will concede that the set of valid reasons for paying the cost of core
development include, but are probably not limited to:

* the alternative is inelegant
* the alternative is orders of magnitude slower than lower level core
support
* pure Perl + baby XS can't support this feature with out a gratuitous
amount of "adult" XS

Hopefully you can see that I am not discounting the value of an infix
infrastructure. My goal is not even to determine the value of the
ability of supporting infix (in this case). My goal is to provide a
logical, sane, and humane feature pathway that we "mere moral" Perl
programmers can participate in.

Thank you, again, LeoNerd for all your work. I hope you can see that I
value your time. I don't mean to patronize here; but frankly if we can
determine that this infix support is not needed, I think your talents
(and the talents of the others) could be more appropriate applied in
areas identified by the process I am suggesting (or some variation of it).

Let's keep this conversation going with the higher order goals in mind,
while lovingly burning our straw men. Even if we must add "infix"
support as yet another straw man.

Cheers,
Brett
Re: infix feature exploration with Sub::Infix (TOBYINK) ? [ In reply to ]
On Fri, 16 Apr 2021 11:52:58 -0500
"B. Estrade" <brett@cpanel.net> wrote:

> c) did we learn that what people *really* want are "hyperops" (not
> sure I understand that concept yet)?

I am somewhat dubious of this fact, but it seems at least some people
-really- do want it.

People continually ask for an "in" operator, so they can test if a
value is an element of a list. I'm forever pointing out that that's
already possible since basically forever using List::Util::any:

if(any { $str eq $_ } @values) { ... }

but for some reason some people dislike that. Maybe that extra set of
braces is offputting - I don't know.. They'd prefer to write

if($str in<eq> @values) { ... }
if($str in:eq @values) { ... }

(I'm still undecided about <cheverons> vs colon notation here)

I'm not sure I _quite_ feel the value proposition is really worth it;
but perhaps I would have felt the same way about say() before it was
added.

> Given a, b, c above; what fundamental core capabilities, if they do
> not exist or require "terrible" things, need to be provided so that
> these kind of language extensions *can* be satisfactorily facilitated
> using merely pure Perl or babby XS?
>
> In other words, what *actually* needs to be added to perl such that
> it maximizes the number of CPAN contributions either provide or
> leverage these capabilities?

PL_infix_plugin. See my branch

https://github.com/Perl/perl5/tree/leonerd/infix-plugin

> This kind of exercise is not like search optimization algorithms,
> like simulated annealing. We may be "stuck" in a local
> maximum/minimum with regards to Perl. And we need to "shake it up" to
> continue along the search for what Perl looks like optimally. I don't
> know if you understand that analogy, but it's one I have quickly at
> hand.

Indeed. My "shaking it up" is based around creating a couple of new
CPAN modules that I would suggest be used as the way to create syntax
plugins, rather than people using the core API directly:

https://metacpan.org/pod/XS::Parse::Keyword

https://metacpan.org/pod/XS::Parse::Sublike

plus I plan to have the new XS::Parse::Infix up as well once core can
support it.

> I have already, sufficiently I think, proven that 'trim' and 'say'
> should never have been implemented in core. One ship has sailed,
> another hopefully has sparked a greater journey of discovery. 'isa',
> I can't speak of, but it's striking how much less code it took to
> implement than 'trim'. Now I believe I have provided a compelling
> pathway to:
>
> * "cheaply" determine what infix ops would be unexpectedly useful
> * provide an opportunity to explore *what* can't be done in pure Perl
> or baby XS, and therefore warrants deeper core support
> * continue to develop this "model" for new feature exploration and
> cleanly determining exactly what core support is needed

Indeed - use my CPAN modules above.

> I will concede that the set of valid reasons for paying the cost of
> core development include, but are probably not limited to:
>
> * the alternative is inelegant
> * the alternative is orders of magnitude slower than lower level core
> support
> * pure Perl + baby XS can't support this feature with out a
> gratuitous amount of "adult" XS

Take a look at how little XS code is actually involved in using those
modules. E.g. I've already put up Syntax::Keyword::Match:

https://metacpan.org/source/PEVANS/Syntax-Keyword-Match-0.01/lib%2FSyntax%2FKeyword%2FMatch.xs

that's tiny. That's actually much much less code than it takes to
implement in core. Much easier to write, much faster to build and
unit-test and run through the CPAN cycle every few days, rather than
the yearly perl releases. It's verymuch the way I think we should do
things going forward.

> Thank you, again, LeoNerd for all your work. I hope you can see that
> I value your time. I don't mean to patronize here; but frankly if we
> can determine that this infix support is not needed, I think your
> talents (and the talents of the others) could be more appropriate
> applied in areas identified by the process I am suggesting (or some
> variation of it).

I've already built it. It took a few days. That's all. ;)

--
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/
Re: infix feature exploration with Sub::Infix (TOBYINK) ? [ In reply to ]
Thank you, all of your content inline below is helpful and insightful
(of the +5 variety). I will definitely be keeping an eye out for your
work and explore your branches and CPAN modules you mention below.

I can't speak on the syntax or others preferences. Seems like you're
providing the kind of paths I am envisioning. This is good.

My next wonder is beyond infix and looking at what other interesting
features have been desired. Does such a "short list" of feature requests
exist?

If I can find a reasonably canonical list, my plan is to initiate the
set of "feature challenges" I spoke of previously. My thought goes to
generic semantics for expressing partial ordering among executable
blocks - a generalization of expressing concurrent programming models in
a way that is both semantically consistent with Perl and able to be
handled in a correct way.

But I am not ready for that challenge myself. Maybe soonish. What's
really starting to gather in my mind is a set of "grand challenges" for
the Perl community to target. I promise not to post again for 24 hours
from now :)

Cheers,
Brett

On 4/16/21 12:30 PM, Paul "LeoNerd" Evans wrote:
> On Fri, 16 Apr 2021 11:52:58 -0500
> "B. Estrade" <brett@cpanel.net> wrote:
>
>> c) did we learn that what people *really* want are "hyperops" (not
>> sure I understand that concept yet)?
>
> I am somewhat dubious of this fact, but it seems at least some people
> -really- do want it.
>
> People continually ask for an "in" operator, so they can test if a
> value is an element of a list. I'm forever pointing out that that's
> already possible since basically forever using List::Util::any:
>
> if(any { $str eq $_ } @values) { ... }
>
> but for some reason some people dislike that. Maybe that extra set of
> braces is offputting - I don't know.. They'd prefer to write
>
> if($str in<eq> @values) { ... }
> if($str in:eq @values) { ... }
>
> (I'm still undecided about <cheverons> vs colon notation here)
>
> I'm not sure I _quite_ feel the value proposition is really worth it;
> but perhaps I would have felt the same way about say() before it was
> added.
>
>> Given a, b, c above; what fundamental core capabilities, if they do
>> not exist or require "terrible" things, need to be provided so that
>> these kind of language extensions *can* be satisfactorily facilitated
>> using merely pure Perl or babby XS?
>>
>> In other words, what *actually* needs to be added to perl such that
>> it maximizes the number of CPAN contributions either provide or
>> leverage these capabilities?
>
> PL_infix_plugin. See my branch
>
> https://github.com/Perl/perl5/tree/leonerd/infix-plugin
>
>> This kind of exercise is not like search optimization algorithms,
>> like simulated annealing. We may be "stuck" in a local
>> maximum/minimum with regards to Perl. And we need to "shake it up" to
>> continue along the search for what Perl looks like optimally. I don't
>> know if you understand that analogy, but it's one I have quickly at
>> hand.
>
> Indeed. My "shaking it up" is based around creating a couple of new
> CPAN modules that I would suggest be used as the way to create syntax
> plugins, rather than people using the core API directly:
>
> https://metacpan.org/pod/XS::Parse::Keyword
>
> https://metacpan.org/pod/XS::Parse::Sublike
>
> plus I plan to have the new XS::Parse::Infix up as well once core can
> support it.
>
>> I have already, sufficiently I think, proven that 'trim' and 'say'
>> should never have been implemented in core. One ship has sailed,
>> another hopefully has sparked a greater journey of discovery. 'isa',
>> I can't speak of, but it's striking how much less code it took to
>> implement than 'trim'. Now I believe I have provided a compelling
>> pathway to:
>>
>> * "cheaply" determine what infix ops would be unexpectedly useful
>> * provide an opportunity to explore *what* can't be done in pure Perl
>> or baby XS, and therefore warrants deeper core support
>> * continue to develop this "model" for new feature exploration and
>> cleanly determining exactly what core support is needed
>
> Indeed - use my CPAN modules above.
>
>> I will concede that the set of valid reasons for paying the cost of
>> core development include, but are probably not limited to:
>>
>> * the alternative is inelegant
>> * the alternative is orders of magnitude slower than lower level core
>> support
>> * pure Perl + baby XS can't support this feature with out a
>> gratuitous amount of "adult" XS
>
> Take a look at how little XS code is actually involved in using those
> modules. E.g. I've already put up Syntax::Keyword::Match:
>
> https://metacpan.org/source/PEVANS/Syntax-Keyword-Match-0.01/lib%2FSyntax%2FKeyword%2FMatch.xs
>
> that's tiny. That's actually much much less code than it takes to
> implement in core. Much easier to write, much faster to build and
> unit-test and run through the CPAN cycle every few days, rather than
> the yearly perl releases. It's verymuch the way I think we should do
> things going forward.
>
>> Thank you, again, LeoNerd for all your work. I hope you can see that
>> I value your time. I don't mean to patronize here; but frankly if we
>> can determine that this infix support is not needed, I think your
>> talents (and the talents of the others) could be more appropriate
>> applied in areas identified by the process I am suggesting (or some
>> variation of it).
>
> I've already built it. It took a few days. That's all. ;)
>