|
Archives
D Programming
digitalmars.Ddigitalmars.D.bugs digitalmars.D.dtl digitalmars.D.ide digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger D.gnu D C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
digitalmars.D - How to use pure in D 2.0 question on Stack Overflow?
Does anyone know the answer to this D related question on SO? http://stackoverflow.com/questions/1008803/how-to-use-pure-in-d-2-0/ Jun 17 2009
Reply to Jeroen,Does anyone know the answer to this D related question on SO? http://stackoverflow.com/questions/1008803/how-to-use-pure-in-d-2-0/ Jun 17 2009
BCS wrote:Reply to Jeroen,Does anyone know the answer to this D related question on SO? http://stackoverflow.com/questions/1008803/how-to-use-pure-in-d-2-0/ Jun 17 2009
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Walter Bright wrote:BCS wrote:Reply to Jeroen,Does anyone know the answer to this D related question on SO? http://stackoverflow.com/questions/1008803/how-to-use-pure-in-d-2-0/ Jun 18 2009
Jeroen Dirks:Does anyone know the answer to this D related question on SO? http://stackoverflow.com/questions/1008803/how-to-use-pure-in-d-2-0/ Jun 17 2009
Jeroen Dirks Wrote:Does anyone know the answer to this D related question on SO? http://stackoverflow.com/questions/1008803/how-to-use-pure-in-d-2-0/ Jun 17 2009
Jason House:Many functions in Phobos are not marked as pure even though they could be. That limits pure's use for me)< Jun 17 2009
bearophile Wrote:Jason House:Many functions in Phobos are not marked as pure even though they could be. That limits pure's use for me)< Jun 18 2009
Jason House wrote:bearophile Wrote:Jason House:Many functions in Phobos are not marked as pure even though they could be. That limits pure's use for me)< Jun 30 2009
On Thu, 18 Jun 2009 00:32:20 +0400, Jeroen Dirks <jeroen.dirks sympatico.ca> wrote:Does anyone know the answer to this D related question on SO? http://stackoverflow.com/questions/1008803/how-to-use-pure-in-d-2-0/ Jun 18 2009
Denis Koroskin:There needs to be a way to tell that addMsg doesn't access global variables.< Another solution is... remove global variables entirely! No globals - no problems :)< Jun 18 2009
It seems that we are back to making copied all over the place because
the compiler can not tell if we would modify something shared.
If the compiler would be smarter and maybe with the help of some
annotations on the functions called can figure out what data is owned
by a pure operation then you might have a real killer feature here.
1 Compiler guarantees related to locality of changes (without need for
locks everywhere)
2 Still write imperative style code.
3 Not having to do copy on write all the time so that old object is
not changed.
Maybe something like this could be added:
class TestObj
{
init( int v )
{
value = v;
}
int value;
}
class Log
{
internal string[] msg;
internal TestObj[] values;
local addMsg( string s ) // marked local since it only changes
internal data
{
msg ~= s;
}
local addValue( int v )
{
values != new TestObj( v )
}
local incValues()
{
for ( v; values ) {
v.value += 1;
}
}
pure string[] getMsgs() {
return msg.dup(); // have to make a copy since it is internal
}
// following would be compiler errors:
string[] getMsg2()
{
return msg; // error: references to internal can not be
returned or exported somehow
}
local addValue2( TestObj t )
{
values ~= tl // error: can not assign external object to
internal data
}
};
pure Log WorkWithObj()
{
Log l = new Log();
l.addMsg("Hello");
l.addMsg("World");
l.addValue( 41 );
l.addValue( 9 );
l.incValues();
return l;
}
Jun 18 2009
On Thu, 18 Jun 2009 23:21:29 +0100, div0 wrote:Surely the heap itself is global state? So creating a new object should be forbidden. Jun 18 2009
|