memoize

Guilherme Vieira n2.nitrogen at gmail.com
Mon Jan 3 22:17:52 PST 2011


On Tue, Jan 4, 2011 at 4:05 AM, Andrew Wiley <debio264 at gmail.com> wrote:

>
>
> On Mon, Jan 3, 2011 at 10:15 PM, Andrei Alexandrescu <
> SeeWebsiteForEmail at erdani.org> wrote:
>
>> I just added a higher-order function memoize to std.functional which I
>> think is pretty cool. See the docs here:
>>
>>
>> http://d-programming-language.org/cutting-edge/phobos/std_functional.html#memoize
>>
>> I'm also thinking of adding that cutting-edge directory as a place for
>> storing documentation for commits that are in flux but not officially
>> released yet.
>
>
> Pretty sweet, but if I'm understanding this correctly, the memoized version
> of a pure function isn't pure, is it? Is there any way to get that to
> happen?
>
>
memoize uses a static variable. Are static variables considered "global" as
far as pure functions are concerned? If not, then I see no reason for it not
to be pure, or am I missing something?

Additionally, I don't understand this:

"Technically the memoized function should be pure because memoize assumes it
> will always return the same result for a given tuple of arguments. However,
> memoize does not enforce that because sometimes it is useful to memoize an
> impure function, too."


Wouldn't memoizing an impure function be a.. bug? It would return the same
cached value when in fact it should have returned something else based on
external factors. When can that be desirable?

-- 
Atenciosamente / Sincerely,
Guilherme ("n2liquid") Vieira
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20110104/a3ab07fd/attachment.html>


More information about the Digitalmars-d mailing list