Is this function pure?
BCS
ao at pathlink.com
Tue Sep 18 11:20:30 PDT 2007
Reply to Benjamin,
> Reply to Nathan,
>
>> Nathan Reed wrote:
>>
>>> It would be interesting to see if it's possible to write a function
>>> that acheives nondeterminism *without* either memory allocation or
>>> reading global state (e.g. rand()). I believe it's not.
>>>
>> I just realized that (as someone else pointed out) taking the address
>> of a local variable would also be nondeterministic. Pointer
>> shenanigans in general can lead to nondeterminism, so maybe pointers
>> should be forbidden entirely in pure functions. Given that pointers
>> are rarely used in D except for interfacing with C functions and
>> suchlike, this seems like it would be not entirely unreasonable.
>>
>> Thanks,
>> Nathan Reed
> It would be a better approach (IMHO) for pure function to just be
> prevented from accessing "other things". This could be done with some
> sort of VM. It is interesting to note that given such a VM, pure
> function can call some non pure function. The requirement would be
> that a pure function must not call anything that accesses something
> that the pure function can't. In a VM this is easy to enforce, just
> don't put anything into it that the function shouldn't access.
>
(BTW: all that is with regards to pure running at compile time)
More information about the Digitalmars-d
mailing list