Better syntax for varargs / variadic functions?

Bill Baxter dnewsgroup at billbaxter.com
Tue Oct 17 01:38:54 PDT 2006


Chris Miller wrote:
> On Thu, 05 Oct 2006 04:41:38 -0400, Bill Baxter 
> <dnewsgroup at billbaxter.com> wrote:
> 
>> Much better!
>>
>> It seems very odd, though, that the opApply doesn't do the advancing 
>> of arg (the iw++ that next() does).   If opApply took care of that, 
>> then get() or value() would probably be a better name than next().
> 
> Because a lot of times some arguments mean "look at next argument too" 
> so you'd only need to call next() again and it wouldn't goof up the 
> iteration; you could also even foreach() over the same args for a sub 
> range: foreach(arg; args){ foreach(arg; args){ if(foo)break; } }.

Seems like there's no reason you can't have the best of both worlds.
If you only call get(), then the pointer advances for you by one.  Or if 
you use next(), then it doesn't.  It seems skip() might be handy too.

Attached is a version that has next(), get(), and skip().  I'm not sure 
what it will do with your foreach(){ foreach() } thing, though.

Maybe it's a D thing, but to me if I see a "foreach(foo, bar) { }" my 
brain *really* wants to believe that foo will be magically set to refer 
to each item in bar, one by one.

--bb
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: variadic.d
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20061017/a26a3a63/attachment.ksh>


More information about the Digitalmars-d mailing list