develooper Front page | perl.perl5.porters | Postings from December 2017

Re: Request For Context - about the 5.22->5.24 context stack rework

Thread Previous | Thread Next
David Nicol
December 13, 2017 17:27
Re: Request For Context - about the 5.22->5.24 context stack rework
Message ID:
On Wed, Dec 13, 2017 at 9:30 AM, Paul "LeoNerd" Evans <> wrote:

> most notably, the two functions with signatures
>   static void MY_suspendedstate_suspend(pTHX_ SuspendedState *state, CV
> *cv);
>   static void MY_suspendedstate_resume(pTHX_ SuspendedState *state, CV
> *cv);
> Were core perl to provide something of that shape (and I'm not at this
> stage requesting that it does - simply illustrating the point here),
> then my entire CPAN module becomes just another syntax hook using only
> documented APIs and features, and adds the entire concept of
> async/await coroutine-style future handling to Perl.

it's easy to imagine how, given these tools, a "yield" (instead of return)
keyword could turn any sub into a coro, with no additional complications to
the programmer, as long as only one instance of a coroutine is allowed at a
time. Some additional keyword would need to be required for multiple
instances of a coroutine to coexist in the same runtime, at least with
package names for them.

perhaps like so:

    sub one_two_three { yield 1; yield 2; 3 }

    cosub another_one_two_three \&one_two_three;

Alternately, this could work, instead of a special copier keyword:

    sub OTTfactory { sub { yield 1; yield 2; 3 } }
    *one_two_three = OTTfactory;
    *another_one_two_three = OTTfactory;

And of course the BCP for this kind of feature AIUI is objects with
methods, instead of hiding state details in the language:

     { package OTT; sub new { my $s=1; bless \$s} sub ott { my $sr=shift;
$$sr > 3 and $$sr=1; $$sr++ }}
     my $ott = OTT->new();
     print $ott->ott(), "\n" for 1 .. 10;
ha! tested, works :)

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About