[fpc-devel] Pure function Wiki page

Dmitry Boyarintsev skalogryz.lists at gmail.com
Sun Jul 8 18:53:47 CEST 2018


On Sun, Jul 8, 2018 at 11:20 AM, J. Gareth Moreton <
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.

thanks,
Dmitry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20180708/90c35d16/attachment.html>


More information about the fpc-devel mailing list