On Tue, 16 Dec 2008 01:48:21 +0300, mastrost <[email protected]> wrote:
Hi,
first of all, thank you Walter and all the D community for making the
great "pure"
feature become reality.
I have 2 questions concerning the behaviour of this feature.
The first one concerns the existence -or not- of "pure delegates".
It makes sense to use a delegate if its closure is not empty -otherwise
it is no
more than a function-. This is the reason why we can think delegates
cannot be
pure. Let's take an example:
void foo(){
int x=0;
//bar is not pure at all in this context
int bar(){
return x;
}
writefln(bar()); // prints '0'
++x;
writefln(bar()); // prints '1'
}
But the fact is that when returning a delegate, its closure freezes
forever and so
behaves like a local variable and not like a global variable by respect
to the
delegate :
int delegate() getPureFunction(int x){
int bar(){
return x;
}
return &bar;
}
void main(){
int delegate() myPureFunction;
myPureFunction = getPureFunction(5);
}
In this example, myPureFunction looks like a pure function, does it?
So how does dmd 2.022 behave for such kind of "pure delegates" ? Do you
think
there is a futur for pure delegates in the D language ? If not this
would mean
that we cannot use the power of delegates (to do real functionnal
programming) and
the power of purity in the same time, which will be very disapointing for
programmers, don't you think ?
Yes, it was previously discussed many times (not only delegates but any
function in general (locally impure)).
Current plan it to make pure function restrictive and then lift unnecessary
restrictions where possible.
This was my first question. The second one concerns purity and parallel
programming. Is dmd 2.022 implementing some kind of parallelism thanks
to pure
function? In fact I have been argued that "pure" keyword is not enough
for the
compiler to make an efficient parallel program. The problem would be
that the
compiler has no mean to know the granularity of the tasks. What are your
feelings
about that?
This is not implemented yet. Pure function are just being added into language.
Thanks a lot