www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Does D 2.110 support named parameters?

reply Brother Bill <brotherbill mail.com> writes:
Does D 2.110 support named parameters, and if so, what 
configuration is necessary,
such as -preview=all

The following code doesn't compile on Window 11.
Is there D syntax that does work?

```
void main() {
    string[string] dictionary = [
            "blue": "mavi", "red": "kırmızı", "gray": "gri"
        ];
    }

// Want to have default keySeparator by ": "
printAA("Color Dictionary", aa, commaSeparator: "\n");

void printAA(string title, string[string] aa, string keySeparator 
= ": ", string commaSeparator = ", ")
{
     // ...
}



```
Dec 05
parent reply "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
It compiles with dmd 2.109.1 if other problems are solved.

```d
void main() {
     string[string] dictionary = [
         "blue": "mavi",
         "red": "kırmızı",
         "gray": "gri"
     ];

     printAA("Color Dictionary", dictionary, commaSeparator: "\n");
}

void printAA(string title, string[string] aa,
     string keySeparator= ": ",
     string commaSeparator = ", ") {
}
```
Dec 05
next sibling parent Brother Bill <brotherbill mail.com> writes:
On Saturday, 6 December 2025 at 01:37:55 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
 It compiles with dmd 2.109.1 if other problems are solved.

 ```d
 void main() {
     string[string] dictionary = [
         "blue": "mavi",
         "red": "kırmızı",
         "gray": "gri"
     ];

     printAA("Color Dictionary", dictionary, commaSeparator: 
 "\n");
 }

 void printAA(string title, string[string] aa,
     string keySeparator= ": ",
     string commaSeparator = ", ") {
 }
 ```
The problem was using one name here and a different name there. Thanks for looking at it. Nothing special is needed for it to run.
Dec 05
prev sibling parent reply Dom Disc <dominikus scherkl.de> writes:
On Saturday, 6 December 2025 at 01:37:55 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
 It compiles with dmd 2.109.1 if other problems are solved.
Unfortunately D-Scanner put out two "problems" for each use of named parameters :-( - Expected `)` instead of `:` - Primary expression expected
Dec 06
parent reply Brother Bill <brotherbill mail.com> writes:
On Saturday, 6 December 2025 at 10:56:36 UTC, Dom Disc wrote:
 On Saturday, 6 December 2025 at 01:37:55 UTC, Richard (Rikki) 
 Andrew Cattermole wrote:
 It compiles with dmd 2.109.1 if other problems are solved.
Unfortunately D-Scanner put out two "problems" for each use of named parameters :-( - Expected `)` instead of `:` - Primary expression expected
When using VS Code, the first "problem" is displayed. But the code does compile and run. Named parameters are sometimes quite helpful. This overcomes the D-Scanner "false alarms".
Dec 06
parent Dom Disc <dominikus scherkl.de> writes:
On Saturday, 6 December 2025 at 11:37:07 UTC, Brother Bill wrote:
 When using VS Code, the first "problem" is displayed.
 But the code does compile and run.
Yes. It's only a little annoying as non-fixable "problems" degrades the value of this problem-list (e.g. have to look if problem count is non-zero is gone because it will always be non-zero).
 Named parameters are sometimes quite helpful.
 This overcomes the D-Scanner "false alarms".
Yes.
Dec 06