On 12/21/2016 03:59 PM, John Colvin wrote:
On Wednesday, 21 December 2016 at 15:40:42 UTC, Andrei Alexandrescu wrote:
On 12/20/2016 05:49 PM, Andrei Alexandrescu wrote:
https://github.com/dlang/dlang.org/pull/1528 -- Andrei
Dropped the void functions. On to the next scandal:
A function that accepts only parameters without mutable indirections and
returns a result that has mutable indirections is called a $(I pure
factory
function). An implementation may assume that all mutable memory
returned by
the call is not referenced by any other part of the program, i.e. it is
newly allocated by the function.
Andrei
There are 3 levels:
1) no idea what's going on: e.g. the function returns a mutable
reference and also reads from global mutable memory.
That would be not pure.
2) memory must be new: e.g. returns 2 mutable references, no accessing
external mutable memory.
Yah, they could refer one another.
3) memory must be new and uniquely referenced: function returns 1
mutable reference, does not access external mutable memory.
Yah.
If I'm not mistaken only 3 enables anything useful like implicit casts
to immutable.
The formulation is careful to not specify what can be done. For now "not
referenced by any other part of the program" nicely covers 2 and 3.
Also, "returned references" should be extended to include "out"
parameters, because there's no difference as far as memory uniqueness is
concerned.
Cool idea.
Andrei