pure or not pure?

Georg Wrede georg at nospam.org
Wed Apr 9 14:54:26 PDT 2008


guslay wrote:
> Steven Schveighoffer Wrote:
> 
>>1. Can pure functions use mutable heap data?  If so, what are the 
>>restrictions for this?
>>
>>i.e.:
>>pure char[] f(int x, int y)
>>{
>>   char[] c = new char[y];
>>   c[] = (char)x;
>>}
> 
> Isn't the dynamic allocator a global state?

IMHO, especially in D, we'll have to make an exception of /new/.

If we didn't, then a function can't return anything that can't be stored 
on the stack.

So, if we pretend that a string is returned via the stack, and that any 
local strings a pure function needs temporarily, are in its own stack, 
then we're okay.

I don't really see any alternative here. Also, I don't see the 
language/compiler enforcing this as all that hard.



More information about the Digitalmars-d mailing list