[fpc-devel] Does FreePascal support named parameters?

Mark Morgan Lloyd markMLl.fpc-devel at telemetry.co.uk
Tue Apr 2 09:56:03 CEST 2013


Frank Church wrote:
> Does FreePascal support named parameters?
> 
> Are they in the pipeline?
> 
> I am not interested in the whole nine yards in case it will be
> difficult to implement. I am thinking of something that will make it
> easier to read, but not change the code generation, ie the order of
> the parameters should remain the same, so that the compiler can
> generate the same code.
> 
> consider a function such as.
> 
> Func(aNumber: integer; aString: string);
> 
> I want to be able to write Func(aNumber := 4, aString := 'anystring');
> If I type Func(aString := 'anystring',4) the compiler should generate
> an error as the order of parameters has been changed.

The obvious thing would be some variant of the snippet below, but it 
doesn't work (at least on the version of the compiler I tested).

program Test;

Type
   Point = record
     X,Y : Real
     end;
Var
   Origin : Point = (X:0.0; Y:0.0);


procedure draw(p: point);

begin
end;


begin
   draw(origin);
   draw((X:0.0; Y:0.0))
end.

-- 
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]



More information about the fpc-devel mailing list