<HTML>
<div><style> BODY { font-family:Arial, Helvetica, sans-serif;font-size:12px; }</style>The problem with determining if a function is pure or not is not just limited to looking for references to external memory and the like, but also has to take into account that the function might contain an infinite loop, for example, and this is difficult because there is no general-purpose algorithm for finding out if a given program (or a group of functions) will finish or continue running forever. See "Turing's halting problem": https://en.wikipedia.org/wiki/Halting_problem</div><div><br>
</div><div>As mentioned before, the other reason is semantics. It might potentially confuse the programmer if "const x = FunctionCall(42);" is seemingly allowed for some arbitrary functions, but not others. By clearly defining valid functions as pure, it makes it clear to the programmer what can be specified, and also aids in debugging because the compiler will throw a warning if the function is question is actually impure, for example (and then the actual error for trying to assign a function result to a constant).<br>
</div><div><br>
</div><div>Gareth<br>
</div> <br>
<br>
<span style="font-weight: bold;">On Mon 09/07/18 00:00 , Dmitry Boyarintsev skalogryz.lists@gmail.com sent:<br>
</span><blockquote style="BORDER-LEFT: #F5F5F5 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT:0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Jul 8, 2018 at 6:47 PM, Thorsten Engler <span dir="ltr"><<a href="mailto:thorsten.engler@gmx.net">thorsten.engler@gmx.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div link="blue" vlink="purple" lang="EN-AU"><div class="m_3484498959208481130WordSection1"><p class="MsoNormal"><span style="font-size:11.0pt;font-family:" calibri",sans-serif"="">
You are thinking about something like:<span style="text-decoration: underline;"></span><span style="text-decoration: underline;"></span></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:" calibri",sans-serif"=""><span style="text-decoration: underline;"></span> <span style="text-decoration: underline;"></span></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:" calibri",sans-serif"="">const<span style="text-decoration: underline;"></span><span style="text-decoration: underline;"></span></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:" calibri",sans-serif"=""> x = FunctionCall(42);<span style="text-decoration: underline;"></span><span style="text-decoration: underline;"></span></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:" calibri",sans-serif"="">
<span style="text-decoration: underline;"></span> <span style="text-decoration: underline;"></span></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:" calibri",sans-serif"="">In which case, yes, the compiler could possibly see that as in implicit “check if that function is pure”.<span style="text-decoration: underline;"></span><span style="text-decoration: underline;"></span></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:" calibri",sans-serif"=""><span style="text-decoration: underline;"></span> <span style="text-decoration: underline;"></span></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:" calibri",sans-serif"="">But “constant expressions” can also be something like:<span style="text-decoration: underline;">
</span><span style="text-decoration: underline;"></span></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:" calibri",sans-serif"=""><span style="text-decoration: underline;"></span> <span style="text-decoration: underline;"></span></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:" calibri",sans-serif"="">If FunctionCall(42) > 0 then <span style="text-decoration: underline;"></span><span style="text-decoration: underline;"></span></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:" calibri",sans-serif"=""><span style="text-decoration: underline;"></span> <span style="text-decoration: underline;"></span></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:" calibri",sans-serif"="">
In which case you don’t want the compiler to have to test every single expression in your program to see if it is composed (all the way down) of pure functions.</span></p></div></div></blockquote><div><br>
</div><div>Maybe a different approach should be taken?</div><div>Determine how much performance impact is made to determine the purity of a function. and then consider adding a new directive and a keyword.</div><div><br>
</div><div>thanks,<br>
</div><div>Dmitry</div></div></div></div>
_______________________________________________<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>
</blockquote></HTML>