<HTML>
<style> BODY { font-family:Arial, Helvetica, sans-serif;font-size:12px; }</style>If I had to give a realistic example of a pure function in such a conditional expression, how about?<br>
<br>
"if (decay_constant * time_elapsed) >= ln(2) then ..."<br>
<br>
This is a formula related to radioactive decay - if the condition is true, then over half of the original sample has decayed (i.e. time_elapsed is greater than the sample's half-life).<br>
<br>
Yes, if any parameters are variables, then the function is not evaluated. My intention is that the purity of a function is only determined when it comes to evaluating it in an expression, but because of how complex functions can become, the "pure" directive hints to the compiler that the given function is pure and it should attempt the laborous task of evaluating it, rather than the opposite approach of attempting to evaluate all functions with constant actual parameters and potentially increasing the compilation time by several orders of magnitude (don't forget it might be attempting to do the same thing with system functions if the project is undergoing a full build).<br>
<div><br>
</div><div>Gareth<br>
</div> <br>
<br>
<span style="font-weight: bold;">On Mon 09/07/18 01:21 , 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 7:18 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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="EN-AU"><div class="gmail-m_-7190478354832580930WordSection1"><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif">
Maybe you don’t understand what “determine the purity of a function” means?<span style="text-decoration: underline;"></span><span style="text-decoration: underline;"></span></span></p><p class="MsoNormal"><span style="font-size:11pt;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:11pt;font-family:Calibri,sans-serif">It means that every time any function is called, the compiler has to try to execute the function at compile time (by working through the nodes like an interpreter) until it hits a point that is non-deterministic. This can potentially take forever (the halting problem is real!), so the only thing limiting it is basically some form of timeout (defined as either time spend or nodes traverse).<span style="text-decoration: underline;">
</span><span style="text-decoration: underline;"></span></span></p><p class="MsoNormal"><span style="font-size:11pt;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:11pt;font-family:Calibri,sans-serif">If you are talking about always considering every function as pure until proven otherwise, you are talking about slowing down the compiler by orders of magnitude.</span></p></div></div></blockquote><div><br>
</div><div>I'm taking about considering every function that's **used to calculate a constant expression** as a pure function (not just every function). </div>
<div>(how many of:</div><div>If FunctionCall(42) > 0 then<br>
</div><div>vs</div><div>If FunctionCall(x) > 0 then<br>
</div><div>is out there?)</div><div><br>
</div><div>Naturally, if a parameters of pure function are variable of any kind, the evaluation cannot be done in compile time anyway.</div><div><br>
</div><div>So, if a function (even if it's a pure function) is not used for constant expression valuation, there's no point in the actual "determination of purity" (in it's full meaning).</div>
<div><br>
</div><div>The compiler knows if a function potentially impure w/o the actual evaluation or interpretation, solely based on what data it's using. </div><div><br>
</div><div>Even if you deal with functions marked by a developer as "pure", the problem of full determination of purity remains. </div><div><br>
</div><div>thanks,</div><div>Dmitry</div><div><br>
</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>