[Phoenix-pm] More: Re: Coro(utine) support from the perl core

Scott Walters scott at illogics.org
Thu Mar 9 11:23:53 PST 2006


----- Forwarded message from demerphq <demerphq at gmail.com> -----

Return-Path: perl5-porters-return-110528-scott=slowass.net at perl.org
X-Original-To: scott at slowass.net
Delivered-To: scott at slowass.net
Received: from lists.develooper.com (x6.develooper.com [63.251.223.186])
	by slowass.net (Postfix) with SMTP id 8506D553AA
	for <scott at slowass.net>; Thu,  9 Mar 2006 19:13:34 +0000 (GMT)
Received: (qmail 2065 invoked by uid 514); 9 Mar 2006 19:06:35 -0000
Mailing-List: contact perl5-porters-help at perl.org; run by ezmlm
Precedence: bulk
list-help: <mailto:perl5-porters-help at perl.org>
list-unsubscribe: <mailto:perl5-porters-unsubscribe at perl.org>
list-post: <mailto:perl5-porters at perl.org>
X-List-Archive: <http://nntp.perl.org/group/perl.perl5.porters/110528>
List-Id: <perl5-porters.perl.org>
Delivered-To: mailing list perl5-porters at perl.org
Received: (qmail 2053 invoked from network); 9 Mar 2006 19:06:35 -0000
Delivered-To: perl5-porters at perl.org
X-Spam-Status: No, hits=-2.6 required=8.0
	tests=BAYES_00,SPF_PASS
X-Spam-Check-By: la.mx.develooper.com
Received-SPF: pass (x1.develooper.com: domain of demerphq at gmail.com designates 64.233.184.197 as permitted sender)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws;
        s=beta; d=gmail.com;
        h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
        b=mSf0l1CU8yuZtI3Iguyg6qDlwNAa+z+BJDjLlRnm43/mDY98KHJCIf0PeG/9rNAbPFgRBCHxEVHFsG2cQdcn2lniBQLIpnjmvhqFwDGbZlmCRjLrB1ZJ7niZ8SBr6XgXrIBMLsYw/udMJrEtkRUjsFyyW7nLFc1rcPILaEsDmtI=
Message-ID: <9b18b3110603091106p4f50b364sa1b567269e6b1480 at mail.gmail.com>
Date: Thu, 9 Mar 2006 20:06:24 +0100
From: demerphq <demerphq at gmail.com>
To: Marc Lehmann <schmorp at schmorp.de>
Subject: Re: Coro(utine) support from the perl core
Cc: perl5-porters at perl.org
In-Reply-To: <20060309174422.GE22421 at schmorp.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
References: <20060309010716.GA13267 at schmorp.de>
	 <20060309083910.GI6272 at woobling.org>
	 <20060309144512.GA22421 at schmorp.de>
	 <9b18b3110603090648i69c6b880o7a4fb30e4433cb9c at mail.gmail.com>
	 <20060309174422.GE22421 at schmorp.de>

On 3/9/06, Marc Lehmann <schmorp at schmorp.de> wrote:
> On Thu, Mar 09, 2006 at 03:48:09PM +0100, demerphq <demerphq at gmail.com> wrote:
> > > The simple case can already be done using e.g. Storable.
> >
> > You can use Data::Dump::Streamer to serialize closures... Although im
> > not certain its relevent to this conversation.
>
> No, you can't, here is an example:
>
>    ...
>    my $var;
>    my $closure = sub { $var++ };
>    dumpevalandcall $closure;
>    print $var;
>
>    sub dumpevalandcall {
>       my $source = Data::Dumper::Dumper $_[0];
>       (eval $source)->();
>    }
>
> There is no way to serialise the closure so that the deserialised version
> still refers to $var.

Well, I think it depends on what you mean. Terms are slippery in this
part of the world.

Consider the following code:

use Data::Dump::Streamer;
sub make_subs {
    my $var=shift;
    my $inc = sub { $var++ };
    my $dec = sub { $var-- };
    my $get = sub { \$var };
    return ($inc,$dec,$get)
}

my ($i,$d,$g)=make_subs(123);
Dump(${$g->()},$i,$d,$g)->Out();

__END__
$var = 123;
$CODE1 = sub {
           $var++;
         };
$CODE2 = sub {
           $var--;
         };
$CODE3 = sub {
           \$var;
         };


As you can see, the output the subs bound to the same var. So in one
sense your statement is wrong. Using DDS you can serialize a set of
closures and other data elements such that when eval'ed the result has
shared data as is appropriate.

However, you are correct in that DDS wont help you reattach to the
same $var as was used  in the first place, but thats a little
different a problem I think, and with a bit of work I suspect its not
a showstopper.

> Now consider killing the process and restarting it between dumping and
> eval'ing: which $var does it refer to?

Well, actually, I think if done carefully the recreated closures would
reference the correct var. I think the attached example suggests ways
this could be accomplished.

Im still not saying that coroutines are any easier with this stuff,
just trying to make it clear that with Data::Dump::Streamer you _can_
serialize closures properly for at least one IMO reasonable definition
of properly.

yves
ps: Im not sure why you used an example that used Data::Dumper to say
that Data::Dump::Streamer can't do something....



--
perl -Mre=debug -e "/just|another|perl|hacker/"
----- End forwarded message -----


More information about the Phoenix-pm mailing list