Uh... destructors?

Steven Schveighoffer schveiguy at yahoo.com
Wed Feb 23 11:48:06 PST 2011


On Wed, 23 Feb 2011 14:31:35 -0500, bearophile <bearophileHUGS at lycos.com>  
wrote:

> Steven Schveighoffer:
>
>> That is allowed, and it's expected that a pure function can return
>> different references with identical calls.
>
> A pointer and a "transparent reference" are two different things. That  
> function returns a pointer, and a pointer is a value.
> If you call a pure function with the same input you need to receive the  
> same value. Otherwise it's not pure. If you mean something else, then  
> you have redefined the meaning of "pure" so much that the word "pure" is  
> the wrong one to use.

A pointer is not a value, it's a pointer.  int is a value.  You should  
expect two calls to a pure function to return the same exact int.

Because memory allocation has side effects, you have to accept that it can  
allow pure functions to not return exactly the same bits.  That is the  
price of allowing memory allocations.

D is a language that allows pointers and comparison of pointers.  There  
are plenty of languages that don't allow this (such as Java), one of those  
might be better suited for your requirements.

I see zero value in disallowing comparing pointers in D.  What kinds of  
problems does pointer comparison cause?  I know of none.  Showing an  
assert that two pointers are not equal is not evidence of an error, it's  
evidence of incorrect expectations.

-Steve


More information about the Digitalmars-d mailing list