<HTML>
<style> BODY { font-family:Arial, Helvetica, sans-serif;font-size:12px; }</style>Hi everyone. The development of pure function support is going well, along with catching error cases. Thanks to some discussion from Sven, the compiler will now detect if you reference a function before defining it as "pure", so cases where it's defined as "forward" are trapped as errors so as to not cause problematic behaviour. I'm still a little unsure of it in places, but so far, I have been running the attached file through the compiler.<br>
<br>
PureTestUnit.pas(5,10) Hint: Function "PureMin" is eligible for the "pure" directive<br>
PureTestUnit.pas(33,15) Warning: Procedure is not eligible to be pure (impure function call)<br>
PureTestUnit.pas(37,1) Error: Function declared pure after it has already been referenced<br>
PureTestUnit.pas(44,4) Fatal: There were 1 errors compiling module, stopping<br>
<br>
In this situation, the parsing of the "Binomial" function, which has been declared to be pure, raises a warning because it calls the Factorial function, which hasn't been declared as such in the interface, but later on in the implementation, and then the error is because the implementation of Factorial appears after it's already been used. If you rearrange the code so Factorial appears before Binomial, the error and warning vanish. Currently that feels a bit clumsy to me.<br>
<br>
One question I've yet to find an answer for is when you have something like the following:<br>
<br>
interface<br>
<br>
function ln(x: Double): Double; pure;<br>
<br>
const<br>
LN2 = ln(2);<br>
<br>
implementation<br>
<br>
function HalfLife(decay: Double): Double;<br>
begin<br>
Result := LN2 / decay;<br>
end;<br>
<br>
function ln(x: Double): Double;<br>
<div>begin</div><div> { Code to calculate natural lograithm }<br>
</div>end;<br>
<br>
<br>
How and when is the constant defined? Should such constructs be disallowed and constants only allowed to be declared in other units that use the unit that contains the pure functions in its interface section? What would be the ideal and cleanest behaviour?<br>
<br>
Gareth aka. Kit<br>
</HTML>