On 8/4/21 7:17 PM, Steven Schveighoffer wrote:
>> The compiler has to evaluate the default argument as constant
>> expression in order to use it as default value..
>
> This is not true, you can use runtime calls as default values.
Whaaaaat??? I just checked and it works! :)
string bar() {
import std.process;
return ("BAR" in environment) ? environment["BAR"] : null;
}
string foo(string s = bar()) {
return s;
}
void main() {
import std.stdio;
writeln(foo("hello world"));
writeln(foo());
}
Run e.g. with
$ BAR=whaaat ./deneme
I wonder whether this feature is thanks to 'lazy' parameters, which are
actually delegates.
Ali