Re: RFC from a newbie: Method References by Jeremy Howard- December 18, 2000 Michael G Schwern wrote:> Hmmm... an object which contains a method reference which contains a> referent to itself.>Yup. I don&39;t know why some people think that circular references are complex;-)>> > Something like this would be nice in a class that creates method> > references--it would simply need to keep a list of referred objects, and> > have an explicit destructor that iterates through the references andundefs> > them. Of course, calling the...http://www.nntp.perl.org/group/perl.perl6.language.objects/2000/12/msg612.html Re: RFC from a newbie: Method References by Michael G Schwern- December 18, 2000 On Sun, Dec 17, 2000 at 11:28:49PM +1100, Jeremy Howard wrote:> There&39;s not necessarily any circular reference. The problem is that method> references are frequently used to implement event callbacks. This would> generally look something like this:<something like this sniped>Hmmm... an object which contains a method reference which contains areferent to itself.> Something like this would be nice in a class that creates method> references--it would simply need to keep a...http://www.nntp.perl.org/group/perl.perl6.language.objects/2000/12/msg611.html Re: RFC from a newbie: Method References by Jeremy Howard- December 17, 2000 Michael G Schwern wrote:> On Sun, Dec 17, 2000 at 12:11:01PM +1100, Jeremy Howard wrote:> > Something to be careful of--it&39;s easy to create a circular referencewhen> > using method pointers. As a result, neither the referrer nor refereeobjects> > are ever destroyed.> >> > When using method references it&39;s important that your class keeps trackof> > its references, and explicitly removes them when done to allow object> > destruction to occur....http://www.nntp.perl.org/group/perl.perl6.language.objects/2000/12/msg610.html Re: RFC from a newbie: Method References by Michael G Schwern- December 16, 2000 On Sun, Dec 17, 2000 at 12:11:01PM +1100, Jeremy Howard wrote:> Something to be careful of--it&39;s easy to create a circular reference when> using method pointers. As a result, neither the referrer nor referee objects> are ever destroyed.> > When using method references it&39;s important that your class keeps track of> its references, and explicitly removes them when done to allow object> destruction to occur. Perhaps this could be incorporated into>...http://www.nntp.perl.org/group/perl.perl6.language.objects/2000/12/msg609.html Re: RFC from a newbie: Method References by Jeremy Howard- December 16, 2000 Michael G Schwern wrote:> package Class::MethRef;> use strict;>> sub meth_ref > my($proto, $method, args) = _;> return sub $proto->$method(args) ;> >>> So this...>> my $meth_ref = $obj->meth_ref(&39;foo&39;, some_stuff);> $meth_ref->();>> is equivalent to this..>> $obj->foo(some_stuff);>> You could even make the meth_ref take additional (or overriding)arguments.>> Its a good idea, I&39;ll put Class::MethRef..http://www.nntp.perl.org/group/perl.perl6.language.objects/2000/12/msg608.html Re: RFC from a newbie: Method References by Michael G Schwern- December 16, 2000 On Fri, Dec 15, 2000 at 11:23:23PM -0800, Ian Hickson wrote:> Having said that: The only feature that I really miss from Perl 5 is the> lack of method pointers -- that is, references to functions in a package> with an associated object.Oh, that&39;s easy. Use a closure...my $foo = Foo->new;my $meth_ref = sub $foo->method ;&$methodref();In fact, here&39;s an example implementation...package Class::MethRef;use strict;sub meth_ref my($proto, $method, args) = _; return sub ...http://www.nntp.perl.org/group/perl.perl6.language.objects/2000/12/msg607.html Re: RFC from a newbie: Method References by Ian Hickson- December 16, 2000 On 16 Dec 2000, Randal L. Schwartz wrote:>> >>> So: What I would love to see in Perl 6 is a way of having a single>>> scalar that holds a reference to a particular instance&39;s method.>>> Is there any chance that this would be considered Or is this already>>> possible in Perl 5 but I have missed it> > my $methref = sub $foo->method(_) ;> > You missed it. :) Just be sure that $foo is not a package variable,> so that a proper...http://www.nntp.perl.org/group/perl.perl6.language.objects/2000/12/msg606.html Re: RFC from a newbie: Method References by merlyn- December 16, 2000 >>>>> "Ian" == Ian Hickson <ianhixie.ch> writes:Ian> So: What I would love to see in Perl 6 is a way of having a single scalarIan> that holds a reference to a particular instance&39;s method.Ian> Is there any chance that this would be considered Or is this alreadyIan> possible in Perl 5 but I have missed it my $methref = sub $foo->method(_) ;You missed it. :) Just be sure that $foo is not a package variable,so that a proper closure is created.--..http://www.nntp.perl.org/group/perl.perl6.language.objects/2000/12/msg605.html Re: RFC from a newbie: Method References by Ian Hickson- December 16, 2000 On Fri, 15 Dec 2000, Michael Fowler wrote:> On Fri, Dec 15, 2000 at 11:23:23PM -0800, Ian Hickson wrote:> > So: What I would love to see in Perl 6 is a way of having a single scalar> > that holds a reference to a particular instance&39;s method.> > > > Is there any chance that this would be considered Or is this already> > possible in Perl 5 but I have missed it> > How about:> my $foo = Foo->create();> my $methodref = sub ...http://www.nntp.perl.org/group/perl.perl6.language.objects/2000/12/msg604.html Re: RFC from a newbie: Method References by Michael Fowler- December 16, 2000 On Fri, Dec 15, 2000 at 11:23:23PM -0800, Ian Hickson wrote:> So: What I would love to see in Perl 6 is a way of having a single scalar> that holds a reference to a particular instance&39;s method.> > Is there any chance that this would be considered Or is this already> possible in Perl 5 but I have missed itHow about: my $foo = Foo->create(); my $methodref = sub $foo->method(_) ; &$methodref();Michael--Administrator ...http://www.nntp.perl.org/group/perl.perl6.language.objects/2000/12/msg603.html |