digitalmars.D - Optional arguments/parameters
- Wanderer (6/6) May 28 2014 Java misses this feature badly, forcing programmers to copy-paste
- Namespace (2/9) May 28 2014 Default parameters? Of course. Every good language does that. :)
- Rene Zwanenburg (4/15) May 28 2014 No named parameters though:
- bearophile (5/6) May 28 2014 You can answer by yourself similar questions online here:
- Wanderer (2/8) May 28 2014 Thanks! :-)
- Ary Borenszweig (20/26) May 28 2014 Regarding this, is this supposed to work?
- Dicebot (4/7) May 28 2014 I can't find exact place in spec but AFAIK default arguments in D
Java misses this feature badly, forcing programmers to copy-paste
bloated code (constructor A calls constructor B with fewer
arguments, constructor B calls constructor C etc, same thing with
methods). Please tell me, does D support this feature?
int myNiceFunc(double a, double b=0, int c=0) {...}
auto n = myNiceFunc(100);
May 28 2014
On Wednesday, 28 May 2014 at 11:54:30 UTC, Wanderer wrote:
Java misses this feature badly, forcing programmers to
copy-paste bloated code (constructor A calls constructor B with
fewer arguments, constructor B calls constructor C etc, same
thing with methods). Please tell me, does D support this
feature?
int myNiceFunc(double a, double b=0, int c=0) {...}
auto n = myNiceFunc(100);
Default parameters? Of course. Every good language does that. :)
May 28 2014
On Wednesday, 28 May 2014 at 11:57:51 UTC, Namespace wrote:On Wednesday, 28 May 2014 at 11:54:30 UTC, Wanderer wrote:No named parameters though: int myNiceFunc(double a, double b=0, int c=0) {...} auto n = myNiceFunc(100, c: 5); // Doesn't workJava misses this feature badly, forcing programmers to copy-paste bloated code (constructor A calls constructor B with fewer arguments, constructor B calls constructor C etc, same thing with methods). Please tell me, does D support this feature? int myNiceFunc(double a, double b=0, int c=0) {...} auto n = myNiceFunc(100);Default parameters? Of course. Every good language does that. :)
May 28 2014
Wanderer:Please tell me, does D support this feature?You can answer by yourself similar questions online here: http://dpaste.dzfl.pl/ Bye, bearophile
May 28 2014
On Wednesday, 28 May 2014 at 13:01:52 UTC, bearophile wrote:Wanderer:Thanks! :-)Please tell me, does D support this feature?You can answer by yourself similar questions online here: http://dpaste.dzfl.pl/ Bye, bearophile
May 28 2014
On 5/28/14, 8:54 AM, Wanderer wrote:
Java misses this feature badly, forcing programmers to copy-paste
bloated code (constructor A calls constructor B with fewer arguments,
constructor B calls constructor C etc, same thing with methods). Please
tell me, does D support this feature?
int myNiceFunc(double a, double b=0, int c=0) {...}
auto n = myNiceFunc(100);
Regarding this, is this supposed to work?
---
import std.stdio;
class Foo {
int bar() {
return 1;
}
int foo(int x = bar()) {
return x;
}
}
void main() {
new Foo().foo();
}
---
I get:
coco.d(8): Error: need 'this' to access member bar
But there is a 'this' in that place (it's not a static function).
Should I file this as a bug?
May 28 2014
On Wednesday, 28 May 2014 at 17:11:09 UTC, Ary Borenszweig wrote:But there is a 'this' in that place (it's not a static function). Should I file this as a bug?I can't find exact place in spec but AFAIK default arguments in D are evaluated in context of call scope, same as in C. Could have detected the problem earlier with better error message though.
May 28 2014









"Rene Zwanenburg" <renezwanenburg gmail.com> 