DIP49 - Define qualified postblit

Timon Gehr timon.gehr at gmx.ch
Sun Nov 10 03:57:03 PST 2013


On 11/10/2013 12:35 PM, Kenji Hara wrote:
> 2013/11/10 Timon Gehr <timon.gehr at gmx.ch <mailto:timon.gehr at gmx.ch>>
> ...
>
>       = Do you think that in this case one should implement identical
>         mutable and immutable postblit?
>
>
> I think yes.
>

This still leaves the issue outlined in the other post though. How to 
copy inout to inout?

>       = "Pure function call which returns unique object"
>         -> "Strongly pure ..."
>
>
> This is valid. Because not only strongly pure function will return
> unique object.
> ...

inout(int[]) identity(inout(int[]) x)pure{ return x; }

struct S{
     int[] arr;
     this(this)inout{
         arr = identity(arr); // whoops
     }
}

But you are right, strongly pure is the wrong term. It is 'pure with 
unique arguments'.

> For example:
>    immutable(int)[] foo(int[] iarr) pure { ... }
>    int[] marr = foo([1,2,3]);
>    // foo will never return the arr argument (without unsafe cast).
>
>       = "New expression with unique arguments"
>         -> "Pure new expression ..."
>
>
> I'm not sure that "pure new expression" is widely used word in D...

"New expression using a pure-qualified constructor with unique arguments."

>
>       = (Also, the inadequacy of 'inout' becomes painfully obvious: Clearly,
>         we'd want 'inout' to mean something different for the source and
>         target struct instances. Then the definition of what is unique
>         would not be necessary in this DIP. (Anything that converts to inout
>         would be fine anyway.))
>
>
> As I already answered to deadalnix,  it is strongly related to inout.
> To describe about that, I added a section "Why use 'inout' keyword for
> 'unique' postblit?" in DIP.
>
> Kenji Hara

Sure, this makes sense to me. What I was referring to is the following 
hypothetical design, that allows multiple different inout-qualifiers, 
for example denoted by inout/n, where n is some integral constant:


inout(int[]) identity(inout(int[]) x){
     writeln("foo"); // not pure
     return x;
}

struct S{
     int[] a;
     int[] b;
     int[] c;
     int[] d;
     this(inout/1 this)inout/2{
         static assert(is(typeof(a)==inout/1(int[])));
         a = b; // error: b of type inout/1(int[]) is not
                // implicitly convertible to inout/2(int[])
         b = somePureFunction(new int[] a);  // ok
         c = identity(new inout/2(int)[] a); // ok, even though identity
                                             // _not pure_
         // error: d has not been reassigned
     }
}







More information about the Digitalmars-d mailing list