Re: recursive closures?
From: Brian McCauley (nobull_at_mail.com)
Date: 12/16/03
- Next message: Brian McCauley: "Re: FILE parsing problems"
- Previous message: Don Stefani: "Re: Shrinkage: regexp rookie"
- In reply to: Uri Guttman: "Re: recursive closures?"
- Next in thread: Uri Guttman: "Re: recursive closures?"
- Reply: Uri Guttman: "Re: recursive closures?"
- Reply: Anno Siegel: "Re: recursive closures?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 16 Dec 2003 17:25:58 +0000
Uri Guttman <uri@stemsystems.com> writes:
> >>>>> "BM" == Brian McCauley <nobull@mail.com> writes:
>
> > Uri Guttman <uri@stemsystems.com> writes:
> >> my $sub ;
> >> $sub = sub{ blah; $sub->() }
>
> > That leaks.
>
> it isn't real code anyhow. i don't recall if damian's leaked or he
> weakened it.
>
> > use Scalar::Util qw( weaken );
> > my $weak_sub;
> > my $sub = sub{ blah; $weak_sub->() }
> > weaken($weak_sub = $sub);
>
> it would only leak if you let it fall out of scope without destroying it
> (but how?).
"You only need weak references if you don't want use some other way to
take care of tracking and breaking the circular dependancy on every
possible exit path" is true of anything that uses weak references.
Of course if you want $sub to be a variable that is forcably undefined
implicitly at the end of a scope scope then Perl has just such a thing
- the local() variable!
Now, of course, it is an annoying miss-feature that local() can't be
applied to lexical variables so if you want to use local() you are for
forced to use package variables. What one really wants to do is...
# Won't work
my $sub;
local $sub = sub{ blah; $sub->() }
...but one is forced to do...
our $sub;
local $sub = sub{ blah; $sub->() }
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
- Next message: Brian McCauley: "Re: FILE parsing problems"
- Previous message: Don Stefani: "Re: Shrinkage: regexp rookie"
- In reply to: Uri Guttman: "Re: recursive closures?"
- Next in thread: Uri Guttman: "Re: recursive closures?"
- Reply: Uri Guttman: "Re: recursive closures?"
- Reply: Anno Siegel: "Re: recursive closures?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|