Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: private recursive subroutines

by ambrus (Abbot)
on May 11, 2007 at 09:34 UTC ( [id://614859]=note: print w/replies, xml ) Need Help??


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.

        ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://614859]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-03-28 21:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found