On Friday, 4 April 2014 at 15:15:55 UTC, bearophile wrote:
Bienlein:
What I was actually looking for was how to get this to work:
immutable int b = if(1 == 1) { return 123; } else { return
456; };
immutable b = (1 == 1) ? 123 : 456;
Bye,
bearophile
You said you did not like ternary expre
On Friday, 4 April 2014 at 19:56:14 UTC, Jesse Phillips wrote:
On Friday, 4 April 2014 at 15:13:25 UTC, Bienlein wrote:
What I was actually looking for was how to get this to work:
immutable int b = if(1 == 1) { return 123; } else { return
456; };
But I'm happy enough with the solution throu
On Friday, 4 April 2014 at 15:13:25 UTC, Bienlein wrote:
What I was actually looking for was how to get this to work:
immutable int b = if(1 == 1) { return 123; } else { return 456;
};
But I'm happy enough with the solution through a delegate.
What bearophile said, or:
immutable int b = {i
Bienlein:
What I was actually looking for was how to get this to work:
immutable int b = if(1 == 1) { return 123; } else { return 456;
};
immutable b = (1 == 1) ? 123 : 456;
Bye,
bearophile
On Friday, 4 April 2014 at 13:53:33 UTC, bearophile wrote:
If your D function has one argument, you have to give it one
argument, even if it doesn't have a visible name and it's
unused.
Ah! Admittedly, I though it's the return type .. So this works
now:
immutable int b = () {
if(1 ==
Bienlein:
Whereas this does not compile:
immutable int b = (int) {
if(1 == 1) {
return 123;
} else {
return 456;
}
}(); // line x
However, this does compile and displays correctly 123:
immutable int b = (int) {
if(1 == 1) {
Thanks so far. I have another one, though. Not trying to tease
people, I really don't know ;-).
This compiles and runs:
immutable int a = (int val) {
if(1 == 1) {
return val;
} else {
return 456;
}
}(123);
writeln(a);
Whereas th
Hello!
You just missed the syntax a little.
Instead of:
> int delegate(int) dg = { value => return value + a + 3; };
You can write
auto dg = (int value) { return value + a + 3; }; // Omitted return
type, but had to specify type of value.
or
auto dg = (int value) => value + a + 3; //
On Monday, 24 March 2014 at 16:40:55 UTC, Bienlein wrote:
Now I want the closure (aka delegate) to have a closure
variable:
int a = 7;
int delegate(int) dg = { value => return value + a + 3; };
auto result = dg(123);
Unhappily, the code above doesn't compile. Tried various
things, looked for
Hello,
I have some piece of code that compiles and runs fine:
void main(string[] args)
{
int a = 7;
int delegate() dg = { return a + 3; };
auto result = dg();
writeln(result);
}
Now I want the closure (aka delegate) to have a closure variable:
int a = 7;
10 matches
Mail list logo