Walter:

> You can write memoized functions in D, you just can't label them as const.
> You'll be relying on convention. Memoized (logically const) functions are not
> verifiable in C++, either, so you are not technically worse off.

I agree with what you say about C++ here. But in theory it's possible to define 
a built-in @memoize that's usable on strongly pure functions (and const member 
functions that are strongly pure), that keeps them strongly pure. In some 
functional languages this memoization is automatic, but in D it's probably 
better to keep it on request, as CTFE.

A pure memoized function is useful because you may call it from another pure 
function, and because pure functions work well with immutability (so you are 
able to assign to an immutable variable even the result of a memoized strongly 
pure function).

Bye,
bearophile

Reply via email to