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

>
>
> On Mon, Jan 3, 2011 at 10:15 PM, Andrei Alexandrescu <
> seewebsiteforem...@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

Reply via email to