in reply to Re: private recursive subroutines
in thread private recursive subroutines

In fact, it was diotalevi who taught me that my $f; $f = sub { ... &$f(...) ...}; leaks memory but the Y-combinator version my $g = sub { my $s = shift; ... &$s($s, ...) ... }; my $f = sub { &$g($g, @_) }; does not.

That was when I showed him the Y-combinatored version of a function for pureness (no side-effects). I didn't really need that because the function was global so I could have used side-effects (the memory leak wasn't an issue because it's a garbage-collected language). At that time, I didn't know that it has a practical application in perl because of the reference counting. You can find that implementation here: t2n.olv (source), t2n.pl (compiled to prolog), t2n.sml (compiled to sml), olvashato/ (link to all files).

Btw, diotalevi also claimed that this memory leak issue is described somewhere in Higher Order Perl, but I couldn't find it in that book. I'd be greatful if anyone can point me to the exact place.

Replies are listed 'Best First'.
Re^3: private recursive subroutines
by diotalevi (Canon) on May 13, 2007 at 04:05 UTC
    Btw, diotalevi also claimed that this memory leak issue is described somewhere in Higher Order Perl, but I couldn't find it in that book. I'd be greatful if anyone can point me to the exact place.

    No. MJD ignored the problem and hoped p5p would solve it. That's not entirely unreasonable since this usage is common but it doesn't seem like its fix is immanent.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

      That's wierd, because I thought there was no way to fix this bug without a different garbage collector.

      On the other hand, I hope that the my $x; sub { sub { $x } } bug will be fixed by p5p, though I know nothing of its technical details.

        I think the hope was that my $x; $x = sub { $x } would be special-cased.

        ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊