Purity (D2 standard libraries / object.d)
Walter Bright
newshound1 at digitalmars.com
Sat Jan 10 12:36:51 PST 2009
Andrei Alexandrescu wrote:
> Walter Bright wrote:
>> Michel Fortin wrote:
>>> Hum, could the compiler be trusted to add the memoization code to
>>> pure functions so they can stay pure?
>>
>> If the compiler does general memoization on pure functions, all it has
>> to do is use the bits of the arguments passed on the stack to the
>> function as an index into an associative array of the return values.
>
> Not the bits, the full objects if they have indirection. (Pure functions
> should accept const parameters!)
You're right, the "just the bits on the stack" is if the arguments are
immutable. Const arguments would have to include whatever was indirectly
referenced, which I argue is impractical for the runtime to handle
automatically.
More information about the Digitalmars-d
mailing list