[fpc-devel] Pure function Wiki page
Florian Klämpfl
florian at freepascal.org
Sun Jul 8 19:01:05 CEST 2018
Am 08.07.2018 um 18:53 schrieb Dmitry Boyarintsev:
> On Sun, Jul 8, 2018 at 11:20 AM, J. Gareth Moreton <gareth at moreton-family.com <mailto:gareth at moreton-family.com>> wrote:
>
> As far as I know, keywords are often used (e.g. "constexpr" in C++). My reasons are explained in the Wiki topic,
> but it boils down to compiler performance.
>
> How about adding a new modeswitch instead PUREFUNCTIONS?
> The mode switch would treat any "function" as pure function (and should check the code for "purity").
>
> While at the same time would allow "procedures" to return values:
> procedure Random(l: LongInt):LongInt;
>
> However, not having an extra modeswitch or new keywords would be beneficial:
>
> From the compiler performance perspective, the purity of a function needs to be checked only when evaluating constant
> expressions (according to the wiki article)
> Thus the actual use of a function in a constant expression should act as the proposed "pure" keyword.
>
No. Because pure is part of the function header and tells users "you can use this function with constant arguments in
constant expressions and this won't change without notification". If the compiler determines by itself if a function is
pure or not, it might even depend on the compiler version if a function is detected as pure or not.
More information about the fpc-devel
mailing list