If you could make any changes to D, what would they look like?
Patrick Schluter
Patrick.Schluter at bbox.fr
Sat Oct 30 10:17:56 UTC 2021
On Friday, 29 October 2021 at 21:56:10 UTC, Adam Ruppe wrote:
> On Friday, 29 October 2021 at 21:16:49 UTC, H. S. Teoh wrote:
>> Long story short, pureFree makes no sense
>
> What about:
>
> void foo() pure {
> int* a = malloc(5);
> scope(exit) free(a);
> }
foo is pure, but malloc and free aren't individually. If the
declaration of the purity of foo is curtailed because malloc and
free have to be marked as pure, then it is a failure of the
language. In fact there should be an equivalent of @trusted for
purity, telling the compiler "trust me, I know that that
combination of impure functions is on a whole pure". Marking
malloc/free as pure doesn't cut it as these functions cannot, by
definition, be pure individually.
But I start to understand where this abomination of purity comes
from. Transitivity. I suspect that applying transitivity
unthinkingly is not such a good idea as can be seen also with
const (immutable is transitive as it describes a property of the
data, const is not as it is a property of the means to access the
data, not the data itself).
>
>
> How is that any different than
>
> void foo() pure {
> int[5] a;
> }
>
> ?
>
> I expect that's how it is actually used. (Perhaps it would be
> better encapsulated in a function along the lines of:
>
> void foo() pure {
> workWithMemory((int* a) {
>
> }, 5);
> }
>
>
> And then the malloc/free could be wrapped up a bit better)
More information about the Digitalmars-d
mailing list