Logical const

bearophile bearophileHUGS at lycos.com
Sun Nov 28 11:52:50 PST 2010


Andrei Alexandrescu:

> Of course memoization is more or less obscure 
> depending on whom you ask, but objective speaking it's simply not that 
> frequent, and definitely not something you can't achieve in a variety of 
> ways.

In the air there is the idea of allowing implicit cast of the result of strongly pure functions to immutable values. If you add to this some way to perform catching in a pure way you are good.

In another answer I have suggested a built-in @memoize that doesn't change the purity of the function it is applied to (so a strongly immutable function too may be memoized and keeps being strongly pure).

If that built-in @memoize is not good or efficient enough, then you may think about implementing it with library code. Currently it is not possible, because it can't be pure. Adding a kind of @trusted_pure" to solve that is possible, but not tidy & safe.

So is it possible to invent a way to define a safe pure memoize in library code? I don't know, it seems interesting :-)

Bye,
bearophile


More information about the Digitalmars-d mailing list