Are named variadic arguments possible?

bearophile bearophileHUGS at lycos.com
Tue Jan 5 03:33:07 PST 2010


> Do you need high performance for this code?
> If not, what about using an associative array of Variant[string] as third argument? It's not a nice solution.

It's not a nice solution, but that's essentially what Python does in such situation:
def foo(x, y, **kwds):
  # here kwds is a dict of str:value

In D there are Typesafe Variadic Functions, you can use:
int sum(int[] ar ...) {
To define a function that takes an arbitrary number of ints or a dynamic array of ints (and maybe fixed sized array of int too).
Another (weird! never used) alternative usage of the Typesafe Variadic Functions is to build an object on the fly.

So that syntax may be extended to support:
void foo(Variant[string] kwds ...) {
}

I may show this silly idea in the main D newsgroup later today.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list