Purity (D2 standard libraries / object.d)

Stewart Gordon smjg_1998 at yahoo.com
Sun Jan 11 07:41:40 PST 2009


Jason House wrote:
> Andrei Alexandrescu wrote:
> 
>>> That's way beyond the ability of a compiler to do automatically.  
>>> The compiler would have to understand that the pure function 
>>> produces continuous results.
>> You're replying to the wrong guy. I'm saying: the compiler 
>> shouldn't have to do so, but it should allow functions to do it.

So effectiely, the compiler could just trust pure functions to be 
actually pure, with UB for any that isn't?

> Here's the simplest memoization example I could come up with.

You mean the simplest example beyond just remembering a single property 
value?

> Maybe we should try to figure out how to get this to work and then
> expand to other cases?
<snip>
> Note the thread-local static variable.  That's guaranteed to be
> thread safe and is easy to prove that it has no side effects outside
> of the fibonocci function.
> 
> Inevitably, I've embarrassed myself by not actually passing what I
> thought was simple code through a compiler...
<snip>

Indeed.

Stewart.



More information about the Digitalmars-d mailing list