Pure functions in D

Walter Bright newshound1 at digitalmars.com
Fri Sep 26 23:07:59 PDT 2008


Bruno Medeiros wrote:
> A few questions:
> 
> If a pure function can throw, is it required that it always throws given 
> the same inputs (and throwing the same Exception?).

Yes.

> Will memory allocation be considered pure?

I don't know yet. If memory allocation failure is a non-recoverable 
exception, then pure functions can allocate memory.

>  >Pure functions can be executed asynchronously.
> Do you realistically expect the compiler to be able to determine on its 
> own when it is worthwhile to perform such asynchronous call? Will it be 
> okay for the compiler to create and destroy threads under the hood, 
> without programmer intervention?

If threads/cores get cheap enough, I think this can be done. In the 
meantime, pure functions make great arguments to 'futures' calls.



More information about the Digitalmars-d mailing list