[% setvar title Add memoize into the standard library %]

This file is part of the Perl 6 Archive

Note: these documents may be out of date. Do not use as reference!

To see what is currently happening visit http://www.perl6.org/


Add memoize into the standard library


  Maintainer: Adam Turoff <ziggy@panix.com>
  Date: 14 Sep 2000
  Last Modified: 18 Sep 2000
  Mailing List: perl6-stdlib@perl.org
  Number: 228
  Version: 2
  Status: Frozen


Caching through memoization is a very useful construct. It should be a standard module.


Memoization is a very useful technique to transparently cache function return values. It can be used to quickly optimize recursive functions, or functions that take a long time to execute (such as gethostbyname).

A version of Memoize.pm should be added into the Perl6 standard library, and it should be added as a pragmatic module (i.e. memoize.pm).

Adding Memoize plugins (Memoize::Expire, etc.) into the standard library is a separate discussion.


There were no real objections to including memoize.pm in the Perl6 core.


A few people mentioned that using memoize() as a function has some action-at-a-distance qualities, although it is useful for caching builtin functions such as cos() and sin().

Bart Lateur mentioned that using a sub attribute would be logical:

	sub foo :memoize {

While this does have merit, it does raise a few issues, such as being able to turn on various Memoize extensions (such as expiry, tied caches, etc.). On the other hand, this syntax does have merit for using the default set of memoize options on a sub, without any action-at-a-distance after effects.

These problems start to deal with language issues, such as being able to use parameterized sub attributes, and internals issues, such as being able to find sub attributes defined and implemented in an extension. Neither of these are within the charter of perl6-stdlib to figure out.




Add memoize into the perl6 source tarball, as a pragmatic module.

The Perl6 language may allow some workarounds to be avoided, such as using a string value to specify the function to be memoized.


Memoize.pm search.cpan.org

MiniMemoize from TPJ: perl.plover.com

Bart Lauter's commentary on a Perl6-ish way to memoize subs: www.mail-archive.com

Leon Brocard's message on removing memoize's action-at-a-distance nature: www.mail-archive.com