www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - C#7 features

reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
Most of them are also present in D, yay.

https://www.reddit.com/r/programming/comments/4i3h77/some_new_c7_features/

Added a comment:

https://www.reddit.com/r/programming/comments/4i3h77/some_new_c7_features/d2v5lu6


Andrei
May 06 2016
next sibling parent reply Kagamin <spam here.lot> writes:
On Friday, 6 May 2016 at 14:33:22 UTC, Andrei Alexandrescu wrote:
 Added a comment:

 https://www.reddit.com/r/programming/comments/4i3h77/some_new_c7_features/d2v5lu6
D has ref variables? Not for a long time though.
May 06 2016
parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 06.05.2016 18:58, Kagamin wrote:
 On Friday, 6 May 2016 at 14:33:22 UTC, Andrei Alexandrescu wrote:
 Added a comment:

 https://www.reddit.com/r/programming/comments/4i3h77/some_new_c7_features/d2v5lu6
D has ref variables? Not for a long time though.
D actually does not support ref local variables in most contexts (one can have ref locals declared by foreach). There is an explicit check ruling them out, but I'm pretty sure DMD supports them internally, they are useful for lowering.
May 06 2016
parent reply Steven Schveighoffer <schveiguy yahoo.com> writes:
On 5/7/16 1:29 AM, Timon Gehr wrote:
 On 06.05.2016 18:58, Kagamin wrote:
 On Friday, 6 May 2016 at 14:33:22 UTC, Andrei Alexandrescu wrote:
 Added a comment:

 https://www.reddit.com/r/programming/comments/4i3h77/some_new_c7_features/d2v5lu6
D has ref variables? Not for a long time though.
D actually does not support ref local variables in most contexts (one can have ref locals declared by foreach). There is an explicit check ruling them out, but I'm pretty sure DMD supports them internally, they are useful for lowering.
Of COURSE D supports local ref variables: struct RefVar(T) { private T * var; this(ref T v) { var = &v; } auto get() { return *var; } alias this get; } ;) -Steve
May 06 2016
parent Nick Treleaven <ntrel-pub mybtinternet.com> writes:
On Friday, 6 May 2016 at 23:51:59 UTC, Steven Schveighoffer wrote:
 Of COURSE D supports local ref variables:

 struct RefVar(T)
 {
   private T * var;
   this(ref T v) { var = &v; }
   auto get() { return *var; }
   alias this get;
 }
ref get() return {... Which is unsafe even if the ctor is marked trusted, the struct could be moved to a higher scope. But like in another thread, you can have a ref property in safe code: T v; property ref myRef(){return v;} So why are ref locals disallowed? Now we have the return attribute on functions that take myRef by ref, can it still escape? ref myRef = v;
May 07 2016
prev sibling parent reply Peter =?UTF-8?B?SMOkZ2dtYW4=?= <hagg.pet2 online.fi> writes:
On Friday, 6 May 2016 at 14:33:22 UTC, Andrei Alexandrescu wrote:
 Most of them are also present in D, yay.

 https://www.reddit.com/r/programming/comments/4i3h77/some_new_c7_features/

 Added a comment:

 https://www.reddit.com/r/programming/comments/4i3h77/some_new_c7_features/d2v5lu6


 Andrei
Their tuples seem to be a complete DIY: https://msdn.microsoft.com/en-us/library/system.tuple(v=vs.110).aspx I wouldn't be surpised to see in the implementation an array of variant or something like that, explaining why it's limited to octuples [1]. Sharp tuples look weak compared to D tuple-ish things: Tuple, TList, AliasSeq, variadics, ... [1] Also I think that the param-"variadicity" is simply emulated via a set of overloaded constructor, explaining why they stop at 8.
May 08 2016
next sibling parent Simen Kjaeraas <simen.kjaras gmail.com> writes:
On Monday, 9 May 2016 at 00:44:09 UTC, Peter Häggman wrote:

 Their tuples seem to be a complete DIY:

 https://msdn.microsoft.com/en-us/library/system.tuple(v=vs.110).aspx

 I wouldn't be surpised to see in the implementation an array of 
 variant or something like that, explaining why it's limited to 
 octuples [1]. Sharp tuples look weak compared to D tuple-ish 
 things: Tuple, TList, AliasSeq, variadics, ...

 [1] Also I think that the param-"variadicity" is simply 
 emulated via a set of overloaded constructor, explaining why 
 they stop at 8.
each arity. There's a lot of duplicated code to make that work. Wait, it's actually 9 classes - in addition to Tuple<T1> through Tuple<T1, ..., T8> there's the humble Tuple - a non-generic class that cannot be instantiated and only exists to be a namespace for the Tuple.Create function. The example code on gooroo seems to have eaten the template arguments for the constructor example - to instantiate a tuple you use one of these syntaxen: var t1 = new Tuple<int, string>(1, "foo"); var t2 = Tuple.Create(2, "bar"); templates, and have nothing on D's templates. That's not necessarily a bad thing, though - the language is different and fills a different niche. It does mean some things that are very
May 09 2016
prev sibling next sibling parent Kagamin <spam here.lot> writes:
On Monday, 9 May 2016 at 00:44:09 UTC, Peter Häggman wrote:
 I wouldn't be surpised to see in the implementation an array of 
 variant or something like that, explaining why it's limited to 
 octuples [1].
You can also use anonymous types: http://ideone.com/WBRunL they are predated by tuples.
May 09 2016
prev sibling parent reply John <johnch_atms hotmail.com> writes:
On Monday, 9 May 2016 at 00:44:09 UTC, Peter Häggman wrote:
 Their tuples seem to be a complete DIY:

 https://msdn.microsoft.com/en-us/library/system.tuple(v=vs.110).aspx
to System.Tuple. The syntax is: (int x, int y) GetPoint() { return (500, 400); } var p = GetPoint(); Console.WriteLine($"{p.x}, {p.y}");
May 09 2016
parent reply Jacob Carlborg <doob me.com> writes:
On 2016-05-09 14:46, John wrote:


 System.Tuple. The syntax is:

    (int x, int y) GetPoint() {
      return (500, 400);
    }

    var p = GetPoint();
    Console.WriteLine($"{p.x}, {p.y}");
Would be nice to have in D. Both with and without named fields. -- /Jacob Carlborg
May 09 2016
parent maik klein <maikklein googlemail.com> writes:
On Monday, 9 May 2016 at 13:09:24 UTC, Jacob Carlborg wrote:
 On 2016-05-09 14:46, John wrote:


 map to
 System.Tuple. The syntax is:

    (int x, int y) GetPoint() {
      return (500, 400);
    }

    var p = GetPoint();
    Console.WriteLine($"{p.x}, {p.y}");
Would be nice to have in D. Both with and without named fields.
I mean it is not much shorter than in D alias Point = Tuple!(int, "x", int, "y"); Point getPoint(){ return Point(500, 400); } What would be nice though if tuples would be implicitly convertible to named tuples, if the types matches. Tuple!(int, "x", int, "y") getPoint(){ return tuple(500, 400); }
May 09 2016