@live questions

thedeemon dlang at thedeemon.com
Mon Nov 23 00:21:34 UTC 2020


On Sunday, 22 November 2020 at 07:44:51 UTC, Walter Bright wrote:

> Please understand that the current @live implementation is a 
> prototype. I expect we'll be learning a lot about how to use it 
> properly. Rust went through considerable evolution, too. I 
> don't expect @live to wind up in the same place as Rust any 
> more than D's functional programming capabilities turn it into 
> Haskell.


Are there any meaningful code examples using @live to look at and 
learn?

So far I'm struggling to see how one would write any @live code 
at all, e.g. how would I create an array of objects and sort it.

Even simpler case I'm struggling with: create a pair of objects, 
choose one of them dynamically and show it to the user, then 
release the objects. Something like

struct S { string name; }

@live void show(scope const S* p) { // this works
     writeln(p.name);
}

void release(S *p) { } // consumes the ownership

// how do I make this work?
@live auto longer(scope const S* a, scope const S* b) {
     if (a.name.length > b.name.length)
         return a;
     else
         return b;
}

@live void foo()
{
     auto a = new S("aaa");
     auto b = new S("bb");

     auto c = longer(a,b); // I need a reference to one of them
     show(c);

     release(a);
     release(b);
}

This doesn't compile and I wonder how to fix this.


More information about the Digitalmars-d mailing list