The Language I Wish Go Was
bearophile
bearophileHUGS at lycos.com
Thu Oct 21 14:04:10 PDT 2010
Juanjo Alvarez:
> expanding a dictionary as named
> arguments to a function is pretty useful too, but since in D's hashes
> the values must be of the same type for a declared hash it would be
> less useful, except for Variant[string] hashes maybe, which is a
> little convoluted.
In D2 there are even typesafe Variadic Functions for dynamic arrays and class objects:
http://www.digitalmars.com/d/2.0/function.html
An example:
class Foo {
int x;
string s;
this(int x_, string s_) {
this.x = x_;
this.s = s_;
}
}
void test1(int[] array ...) {}
void test2(int x, Foo f ...) {}
void main() {
test1(4, 5, 6);
test2(1, 4, "text");
}
So far typesafe variadic functions for class objects is an useless feature for me.
Once named arguments are present, typesafe variadic functions for associative arrays may look like:
void test3a(int[string] aa ...) {}
void test3b(Variant[string] aa ...) {}
You may call them like this:
test3a(x: 1, y: 2, good: 3);
test3b(x: 1, y: 2, good: "right");
Bye,
bearophile
More information about the Digitalmars-d
mailing list