Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

We all can disagree what constitutes overkill. But someone has gone a step further, and generalised persistant programs' ability to remember previously requested results. Check out Memoize ("trade space for time"). It inserts itself into the call-stream somewhat magically, and detects function calls that are identical, and returns the previously-computed value for the same input.

Of course, this only makes sense when the same input always results in the same output, as it would here. This can really speed up recursive results to the point where, for some functions, the recursively-computed value is faster than the iterative. And, of course, Memoize can help simplify non-recursive functions as well. It does require a bit of caution to ensure that there are no side effects possible on a function, though.

[time elapses...] Oddly, Memoize has a bunch of add-ons that I just saw when I checked it out on CPAN (to ensure I got the link correct above) which allows this to work even for non-persistant programs. That merits some more thought. Man, do I love perl. This would be incredibly programmer-intensive in basically any other language. But in perl, someone did it already, and I can just use it. That's too cool.


In reply to Re^2: Tail-recursion in perl?! by Tanktalus
in thread Tail-recursion in perl?! by neniro

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-24 06:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found