<HTML>
<div>The concept of pure functions is that it allows for their evaluation at compile time for constant arguments.  In your example, function purity wouldn't play into it because x, I assume, is a variable whose value is unknown at compile time.  However, advanced data flow analysis might be able to spot that x hasn't changed, and marking 'sin' as pure would indeed be an advantage because the first call's result can be stored for later use, and the second function call removed, knowing it won't cause side-effects.</div><div><br>
</div><div>I would say that that is currently beyond the scope of the proposal, but given that I've been working on a deep optimizer with the intention of optimising code where div and mod are used together with the same arguments (in this case, the pure 'function' is the div operator), that is definitely something I would like to come back to - thanks for the idea!<br>
<br>
Gareth</div><div><br>
</div><div><span style="font-weight: bold;">On Sun 08/07/18 19:00 , Martin fpc@mfriebe.de sent:</span></div><div><span style="font-weight: bold;"></span></div><blockquote style="BORDER-LEFT: #F5F5F5 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT:0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px"> 
  
 <defanged_meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
  
 <defanged_body text="#000000" bgcolor="#FFFFFF"> 
 <div class="moz-cite-prefix">On 08/07/2018 16:50, J. Gareth Moreton 
 wrote:<br>
 
 </div> 
 <blockquote type="cite" cite="mid:4540.1531061403@web-cluster.fastnet.co.uk"> 
 <defanged_meta http-equiv="content-type" content="text/html; charset=utf-8"> 
 Hi 
 everyone,<br>
 
 <br>
 
 <div>With some blessing from Florian on the concept, I've set up a 
 Wiki page discussing the design proposals for the support of 
 pure functions, as well as some explanation on what they 
 actually are.</div> 
 <div><br>
 
 </div> 
 <div>wiki.freepascal.org/Pure_functions</div> 
 <div><br>
 
 </div> 
 <div>I hope it proves useful to explain what I'm doing. How do the 
 proposals look so far, Florian?<br>
 
 </div> 
 </defanged_meta></blockquote> 
 <br>
 
 I seem to be missing a part of the feature (or did I misunderstand 
 (part of)  the side?<br>
 
 <br>
 
 It is all about the compiler evaluating pure functions at compile 
 time, and placing the result as a constant in the code. (Or at least 
 that's how I read it).<br>
 
 That's all fine.<br>
 
 <br>
 
 But what about re-using results at runtime.<br>
 
  <br>
 
    b := sin(x);<br>
 
 If x is unknown this can not be computed at compile time.<br>
 
 But<br>
 
   if sin(x) > y then b := sin(x);<br>
 
 <br>
 
 Knowing that sin is pure AND knowing that x did not change, means 
 only one call is needed.<br>
 
 Is that also planed?<br>
 
 <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>

</defanged_body></defanged_meta></blockquote></HTML>