[fpc-devel] Pure function Wiki page

J. Gareth Moreton gareth at moreton-family.com
Sun Jul 8 17:20:17 CEST 2018


 As far as I know, keywords are often used (e.g. "constexpr" in C++).  My
reasons are explained in the Wiki topic, but it boils down to compiler
performance.  If every function is assumed to be pure, then the compiler
has to check each time if that is actually the case, and with a large
project with many hundreds of functions and thousands of calls, this will
quickly get prohibitively slow.  Generally, most functions will not be
pure, especially given the tight restrictions required (for example, object
methods can't be pure because it's impossible to determine the value of
Self at compile-time, although this may be something for future research if
the method only sets internal fields).

 Also, it won't break existing code.  For example, this will compile
without any problems (although the word 'virtual' might appear
highlighted):

 function TestClass.Test: Integer; virtual;
 var
   virtual: Integer;
 begin  virtual := x + 1;  Result := virtual * virtual;
 end;

 Due to the design of the Pascal language, procedure directives can share
names with identifiers without problems.
 Gareth

 On Sun 08/07/18 17:11 , "R0b0t1" r030t1 at gmail.com sent:
 On Sun, Jul 8, 2018 at 9:50 AM, J. Gareth Moreton 
  wrote: 
 > Hi everyone, 
 > 
 > 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. 
 > 
 > wiki.freepascal.org/Pure_functions 
 > 
 > I hope it proves useful to explain what I'm doing. How do the proposals
look 
 > so far, Florian? 
 > 
 > Gareth aka. Kit 
 > 

 This is usually done without a keyword. Why add a keyword? 

 If a keyword must be used, I'd appreciate if they weren't taken from 
 the English language. Doing so is liable to make older code that uses 
 variables of the reserved word's name incompilable. 

 Cheers, 
 R0b0t1 

 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20180708/82f35e75/attachment.html>


More information about the fpc-devel mailing list