[fpc-devel] pure function feedback
    J. Gareth Moreton 
    gareth at moreton-family.com
       
    Fri Jun 28 14:24:24 CEST 2024
    
    
  
Hi Marģers,
Thanks for the feedback!
Assigning the results of pure functions to constants has not yet been 
developed.  I had planned to add it once the bulk of pure functions 
(i.e. the current merge request) had been approved since it requires 
some additional work (specifically what happens if the function is not 
actually pure or otherwise can't return a straightforward result).
2 and 3 are definite bugs though.  The second case should at the very 
least make the function impure, while the third case should indeed not 
disqualify the function.  I'll see what I can do. Thanks again.
Kit
On 28/06/2024 09:35, Marģers . via fpc-devel wrote:
> 1. pure function value to constants
>
> function foo(i:longword):longword; pure;
> begin
>   foo:=9;
> end;
>
> const bar = foo( 8 );  //-- not allowed.. but i expect this to work!
>          jar : longword = foo( 7 ); //-- and this as well
>
>
> 2. this does not end grasefully
>
> function foo (i:longword):shortstring; pure;
> var s : shortstring;
>       n : longword;
> begin
>   s:=''';
>   for n:=1 to i do s:=s +'a';
>   //-- not assing return value
> end;
> begin writeln(foo(9)); end.
>
> 3.
> function foo (i:longword):ansistring; pure;
> var s : shortstring;
>       n : longword;
> begin
>   s:=''';
>   for n:=1 to i do s:=s +'a';
>   foo:=s; //-- this makes function not pure, but why whould it!
> end;
> begin writeln(foo(9)); end.
>
>
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
-- 
This email has been checked for viruses by Avast antivirus software.
www.avast.com
    
    
More information about the fpc-devel
mailing list