View mode: basic / threaded / horizontal-split · Log in · Help
January 05, 2010
Named variadic arguments
Coming from this question, named variadic arguments:
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=18586

It's a possible way to implement something like this Python code:
def foo(x, y, **kwds):
 # here kwds is a dict of str:value

With another kind of typesafe variadic function:
void foo(int x, int y, Box[string] kwds ...) {}

foo(1, 2, z:10, w:30);
==>
In foo kwds == ["z":box(10), "w":box(30)];
(Variant or something else can be used instead of Box.)

Bye,
bearophile
January 07, 2010
Re: Named variadic arguments [to remove for class objects?]
> With another kind of typesafe variadic function:
> void foo(int x, int y, Box[string] kwds ...) {}

While that can be useful, so far I've never find an use of "typesafe variadic functions for class objects" (See D docs about typesafe variadic functions). If no one uses this feature then it can be removed from D2.

Bye,
bearophile
Top | Discussion index | About this forum | D home