D's treatment of values versus side-effect free nullary functions

Don nospam at nospam.com
Sat Jul 24 12:41:56 PDT 2010


Jim Balter wrote:
> 
> "Jonathan M Davis" <jmdavisprog at gmail.com> wrote in message 
> news:mailman.435.1279700666.24349.digitalmars-d at puremagic.com...
>> On Wednesday 21 July 2010 00:09:05 Don wrote:
>>> While running the semantic on each function body, the compiler could
>>> fairly easily check to see if the function is CTFEable. (The main
>>> complication is that it has to guess about how many iterations are
>>> performed in loops). Then, when a CTFEable function is called with
>>> compile-time constants as arguments, it could run CTFE on it, even if it
>>> is not mandatory.
>>>
>>> Incidentally, having the function being marked as 'pure' doesn't really
>>> help at all for determining if it is CTFEable.
>>
>> Hmm. As I understood it, it did.
> 
> You understood right.
> 
>> But I guess that if it did, the compiler could
>> technically determine whether a function was actually pure anyway by 
>> looking at
>> its body. All the pure attribute would do is save it the trouble. So, 
>> the pure
>> attribute wouldn't do much in that sense except save the compiler some
>> computation.
> 
> pure functions must halt, so the attribute let's you tell the compiler 
> something that it could only figure out with difficulty, if at all.

Being marked as 'pure' is no guarantee that the function will terminate.


More information about the Digitalmars-d mailing list