<HTML>
<div><style> BODY { font-family:Arial, Helvetica, sans-serif;font-size:12px; }</style>It also feels safer and more intuitive for the programmer. If you're writing code such as "const Partitions = log2(Length(StaticList));" (assuming Length(StaticList) evaluates to a constant value), then defining log2 as a pure function shows you know what you're doing, because otherwise it might seem random and arbitrary in that you can assign some functions to constants, but not others. And if the pure function in question is actually impure, then you get both a warning and an error... first the warning that the function is impure, and then an error because you're assigning a function result to a constant, and the two appearing side-by-side will quickly inform the programmer what's going on.</div><div><br>
</div><div>It's also the reason behind my choice of the <span style="font-weight: bold;">pure</span> keyword... ease-of-use and intuitiveness.<br>
</div><div><br>
</div><div>Gareth<br>
</div><br>
<span style="font-weight: bold;">On Sun 08/07/18 18:01 , Florian Klämpfl florian@freepascal.org sent:<br>
</span><blockquote style="BORDER-LEFT: #F5F5F5 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">Am 08.07.2018 um 18:53 schrieb Dmitry Boyarintsev:
<br>
<span style="color: rgb(102, 102, 102);">> On Sun, Jul 8, 2018 at 11:20 AM, J. Gareth Moreton <gareth@moreton-family.com <<a="" href="mailto:gareth@moreton-family.com">gareth@moreton-family.com>> wrote:
</gareth@moreton-family.com></span><br>
<span style="color: rgb(102, 102, 102);">>
</span><br>
<span style="color: rgb(102, 102, 102);">> As far as I know, keywords are often used (e.g. "constexpr" in C++). My reasons are explained in the Wiki topic,
</span><br>
<span style="color: rgb(102, 102, 102);">> but it boils down to compiler performance.
</span><br>
<span style="color: rgb(102, 102, 102);">>
</span><br>
<span style="color: rgb(102, 102, 102);">> How about adding a new modeswitch instead PUREFUNCTIONS?
</span><br>
<span style="color: rgb(102, 102, 102);">> The mode switch would treat any "function" as pure function (and should check the code for "purity").
</span><br>
<span style="color: rgb(102, 102, 102);">>
</span><br>
<span style="color: rgb(102, 102, 102);">> While at the same time would allow "procedures" to return values:
</span><br>
<span style="color: rgb(102, 102, 102);">> procedure Random(l: LongInt):LongInt;
</span><br>
<span style="color: rgb(102, 102, 102);">>
</span><br>
<span style="color: rgb(102, 102, 102);">> However, not having an extra modeswitch or new keywords would be beneficial:
</span><br>
<span style="color: rgb(102, 102, 102);">>
</span><br>
<span style="color: rgb(102, 102, 102);">> From the compiler performance perspective, the purity of a function needs to be checked only when evaluating constant
</span><br>
<span style="color: rgb(102, 102, 102);">> expressions (according to the wiki article)
</span><br>
<span style="color: rgb(102, 102, 102);">> Thus the actual use of a function in a constant expression should act as the proposed "pure" keyword.
</span><br>
<span style="color: rgb(102, 102, 102);">>
</span><br>
<br>
No. Because pure is part of the function header and tells users "you can use this function with constant arguments in
<br>
constant expressions and this won't change without notification". If the compiler determines by itself if a function is
<br>
pure or not, it might even depend on the compiler version if a function is detected as pure or not.
<br>
_______________________________________________
<br>
fpc-devel maillist - <a href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a>
<br>
<a target="_blank" href="<a href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</a>"><span style="color: red;">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</span></a>
<br>
<br>
<br>
</blockquote></HTML>