John-Carmack quotes the D programming language
bearophile
bearophileHUGS at lycos.com
Fri Apr 27 07:51:00 PDT 2012
Guillaume Chatelet:
> A very good article by John-Carmack about purity
>
> http://www.altdevblogaday.com/2012/04/26/functional-programming-in-c/
>Returning everything by value is the natural functional
>programming style, but relying on compilers to always perform
>return value optimization can be hazardous to performance, so
>passing reference parameter for output of complex data
>structures is often justifiable, but it has the unfortunate
>effect of preventing you from declaring the returned value as
>const to enforce single assignment.<
Is this what he is talking about?
class Foo {
int x;
}
const(Foo) bar() pure {
auto f = new Foo;
f.x = 1;
return f;
}
void main() pure {}
----------------------
Regarding D purity I have asked for another little improvements:
http://d.puremagic.com/issues/show_bug.cgi?id=7994
It's related to this other example:
import std.string: text;
string foo() {
return text(1);
}
void main() pure {
enum s = foo(); // currently an error
}
Bye,
bearophile
More information about the Digitalmars-d
mailing list