[fpc-devel] Does FreePascal support named parameters?

Sven Barth pascaldragon at googlemail.com
Tue Apr 2 07:12:04 CEST 2013


Am 01.04.2013 20:29 schrieb "Frank Church" <vfclists at gmail.com>:
>
> Does FreePascal support named parameters?
>
> Are they in the pipeline?

Yes and no. As Anthony wrote such a construct is available for Variants and
thus is supported by the parser. Normally this is disabled though. In case
of the parser you should look out for "named_args_allowed" (or similar).
What I don't know though is how the names parameters are handled after
that...

>
> 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.

As said: this syntax is already supported (though I don't know to what
extent your example would work).

> Coming to think of it will be just as easy to wrap the parameter names
> in comments i.e Func({aNumber}4, {aString} 'anystring'), much simpler
> and almost is good. Is such a style acceptable? I don't mind using it
> in my own code.

And here we can see that you haven't worked much with the internals of the
compiler yet (Note: no offence intended). Using comments for anything
besides comments (and compiler directives) is extremely hard, because they
are entirely handled by the scanner. The parser will not know that a
comment existed there.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20130402/d80346e0/attachment.html>


More information about the fpc-devel mailing list