xsharp.eu • Named parameter support
Page 1 of 1

Named parameter support

Posted: Wed Jan 31, 2024 11:14 am
by baramuse
Hi,

I tried the named parameter syntax

Code: Select all

logConfiguration:WriteTo:File("serilog.txt", rollingInterval := Serilog.RollingInterval.Day ):CreateLogger()
like in the inline constructor of the Tuple example

Code: Select all

 oCustomer := TUPLE{Name := "Nikos", Age := 47, IsActive := TRUE}
but it does not seem to be supported.

Am I doing it wrong ?

Regards.

Re: Named parameter support

Posted: Wed Jan 31, 2024 11:43 am
by robert
Basile,
You have to enable the support for this on the language page of the project properties:
https://www.xsharp.eu/help/proppage-language.html

We cannot enable this by default, because the ':=' operator could also be an assignment a rollingInterval local (in your example).
In the Core dialect this is enabled by default. In the other dialects not.

See also https://www.xsharp.eu/help/opt-namedargs.html for an example of where namedarguments could cause a problem.


Rober

Re: Named parameter support

Posted: Wed Jan 31, 2024 11:49 am
by baramuse
Thank you Robert for the doc.

I did not know you could assign a variable within a method call, so it does make sense.
And you can't use the column either (as in .net) I guess.

Now I have enabled the named parameters, I have hundreds of errors :/
So I'll use the full constructor for that one, but that's good to know !

Re: Named parameter support

Posted: Wed Jan 31, 2024 1:18 pm
by robert
Basile,
baramuse wrote: Wed Jan 31, 2024 11:49 am Thank you Robert for the doc.

I did not know you could assign a variable within a method call, so it does make sense.
And you can't use the column either (as in .net) I guess.

Now I have enabled the named parameters, I have hundreds of errors :/
So I'll use the full constructor for that one, but that's good to know !
The 100s of errors are the reason that we have disabled this for the non core dialects!

Robert