Improvement in pure functions specification

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Wed Dec 21 14:08:58 PST 2016


On 12/21/2016 04:42 PM, Johan Engelen wrote:
> On Wednesday, 21 December 2016 at 21:34:04 UTC, Andrei Alexandrescu wrote:
>> On 12/21/2016 03:04 PM, Johan Engelen wrote:
>>
>>> Super contrived, but I hope you get my drift:
>>> ```
>>> int *awesome() pure {
>>>   static if (ohSoAwesome) {
>>>      return new int;
>>>   } else {
>>>      return null;
>>>   }
>>> }
>>> ```
>>
>> Where does ohSoAwesome come from?
>
> A random bool.
> Perhaps something like this:
> ```
> version(LDC)
>   ohSoAwesome = true;
> else
>   ohSoAwesome = false
> ```

Well randomness is not available in pure functions. Anyhow I've 
reformulated the wording and added an example. The sheer fact it works 
is pretty awesome.

https://github.com/dlang/dlang.org/pull/1528

For now I didn't want to give thrown values any special treatment, i.e. 
maximum freedom for the implementation.


Andrei



More information about the Digitalmars-d mailing list