www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - D Lang'99 & Its future

reply Salih Dincer <salihdb hotmail.com> writes:
Hope, D will go on to the next version,
the compiler will release up to v10!

Many happy returns of the (D)ay...🥳

```d
   enum Dlang99 = 4026728633831507;

   union Magic
   {
     long data;
     char[8] bits;

     string toString()
     {
       return bits;
     }
   }
   auto magic = Magic(Dlang99<<10|'D');
        magic.writefln!"..::%s::..";
```
Feb 08 2022
next sibling parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Tue, Feb 08, 2022 at 06:19:55PM +0000, Salih Dincer via Digitalmars-d wrote:
 Hope, D will go on to the next version,
 the compiler will release up to v10!
 
 Many happy returns of the (D)ay...🥳
 
 ```d
   enum Dlang99 = 4026728633831507;
 
   union Magic
   {
     long data;
     char[8] bits;
 
     string toString()
In latest dmd git HEAD, you need to annotate this function with `return`, because it escapes a reference to `this`. :-)
     {
       return bits;
     }
   }
   auto magic = Magic(Dlang99<<10|'D');
        magic.writefln!"..::%s::..";
 ```
T -- WINDOWS = Will Install Needless Data On Whole System -- CompuMan
Feb 08 2022
next sibling parent user1234 <user1234 12.de> writes:
On Tuesday, 8 February 2022 at 18:28:21 UTC, H. S. Teoh wrote:
 On Tue, Feb 08, 2022 at 06:19:55PM +0000, Salih Dincer via 
 Digitalmars-d wrote:
 Hope, D will go on to the next version,
 the compiler will release up to v10!
 
 Many happy returns of the (D)ay...🥳
 
 ```d
   enum Dlang99 = 4026728633831507;
 
   union Magic
   {
     long data;
     char[8] bits;
 
     string toString()
In latest dmd git HEAD, you need to annotate this function with `return`, because it escapes a reference to `this`. :-)
     {
       return bits;
     }
   }
   auto magic = Magic(Dlang99<<10|'D');
        magic.writefln!"..::%s::..";
 ```
T
destroyer 2000
Feb 08 2022
prev sibling next sibling parent reply Martin Tschierschke <mt smartdolphin.de> writes:
On Tuesday, 8 February 2022 at 18:28:21 UTC, H. S. Teoh wrote:

 In latest dmd git HEAD, you need to annotate this function with 
 `return`, because it escapes a reference to `this`. :-)
Sorry, I am to stupid, where do you have to "annotate return"?
Feb 09 2022
parent reply bauss <jj_1337 live.dk> writes:
On Wednesday, 9 February 2022 at 08:38:00 UTC, Martin 
Tschierschke wrote:
 On Tuesday, 8 February 2022 at 18:28:21 UTC, H. S. Teoh wrote:

 In latest dmd git HEAD, you need to annotate this function 
 with `return`, because it escapes a reference to `this`. :-)
Sorry, I am to stupid, where do you have to "annotate return"?
I believe it would be like this: ```d ref string toString() return { return bits; } ``` Someone can correct me if I'm wrong, but I believe this is what he's referring to in the spec: https://dlang.org/spec/function.html#return-ref-parameters
Feb 09 2022
parent reply Martin Tschierschke <mt smartdolphin.de> writes:
On Wednesday, 9 February 2022 at 10:21:33 UTC, bauss wrote:
 On Wednesday, 9 February 2022 at 08:38:00 UTC, Martin 
 Tschierschke wrote:
 On Tuesday, 8 February 2022 at 18:28:21 UTC, H. S. Teoh wrote:

 In latest dmd git HEAD, you need to annotate this function 
 with `return`, because it escapes a reference to `this`. :-)
Sorry, I am to stupid, where do you have to "annotate return"?
I believe it would be like this: ```d ref string toString() return { return bits; } ```
Thank you I tried it, at the https://tour.dlang.org/ rdmd Playground and got a casting error, so I changed ```string``` to ```char[8]``` and it worked: no return needed: (?) ``` import std.stdio; void main() { enum Dlang99 = 4026728633831507; union Magic { long data; char[8] bits; char[8] toString() { return bits; } } auto magic = Magic(Dlang99<<10|'D'); magic.writefln!"..::%s::.."; } ```
Feb 09 2022
next sibling parent reply bauss <jj_1337 live.dk> writes:
On Wednesday, 9 February 2022 at 12:24:32 UTC, Martin 
Tschierschke wrote:
 On Wednesday, 9 February 2022 at 10:21:33 UTC, bauss wrote:
 On Wednesday, 9 February 2022 at 08:38:00 UTC, Martin 
 Tschierschke wrote:
 On Tuesday, 8 February 2022 at 18:28:21 UTC, H. S. Teoh wrote:

 In latest dmd git HEAD, you need to annotate this function 
 with `return`, because it escapes a reference to `this`. :-)
Sorry, I am to stupid, where do you have to "annotate return"?
I believe it would be like this: ```d ref string toString() return { return bits; } ```
Thank you I tried it, at the https://tour.dlang.org/ rdmd Playground and got a casting error, so I changed ```string``` to ```char[8]``` and it worked: no return needed: (?) ``` import std.stdio; void main() { enum Dlang99 = 4026728633831507; union Magic { long data; char[8] bits; char[8] toString() { return bits; } } auto magic = Magic(Dlang99<<10|'D'); magic.writefln!"..::%s::.."; } ```
toString() should return a string, so what should happen is that the value of bits must actually be converted to string. The error is evident if you ex. try to cast bits to string like this: ``` string toString() { return cast(string)bits; } ``` Which will give this error: ``` onlineapp.d(12): Deprecation: returning `cast(string)this.bits` escapes a reference to parameter `this` onlineapp.d(12): perhaps annotate the parameter with `return` ``` So when we do: ``` string toString() return { return cast(string)bits; } ``` There's no error. Probably a terrible example and I'm not sure if casting like that is even considered safe or should even be done like that, but yeah...
Feb 09 2022
parent Martin Tschierschke <mt smartdolphin.de> writes:
On Wednesday, 9 February 2022 at 12:47:34 UTC, bauss wrote:
[...]
 ```

 So when we do:

 ```
     string toString() return
     {
       return cast(string)bits;
     }
 ```

 There's no error.

 Probably a terrible example and I'm not sure if casting like 
 that is even considered safe or should even be done like that, 
 but yeah...
👍👍👍, and thanks.
Feb 09 2022
prev sibling parent user1234 <user1234 12.de> writes:
On Wednesday, 9 February 2022 at 12:24:32 UTC, Martin 
Tschierschke wrote:
 Thank you I tried it, at the https://tour.dlang.org/ rdmd 
 Playground and
 got a casting error, so I changed ```string``` to ```char[8]``` 
 and it worked:
 no return needed: (?)
it's still dead stack data
Feb 09 2022
prev sibling parent Salih Dincer <salihdb hotmail.com> writes:
On Tuesday, 8 February 2022 at 18:28:21 UTC, H. S. Teoh wrote:
 On Tue, Feb 08, 2022 at 06:19:55PM +0000, Salih Dincer via 
 Digitalmars-d wrote:
 Hope, D will go on to the next version,
 the compiler will release up to v10!
 
 Many happy returns of the (D)ay...🥳
 
 ```d
   enum Dlang99 = 4026728633831507;
 
   union Magic
   {
     long data;
     char[8] bits;
 
     string toString()
In latest dmd git HEAD, you need to annotate this function with `return`, because it escapes a reference to `this`. :-)
     {
       return bits;
     }
   }
   auto magic = Magic(Dlang99<<10|'D');
        magic.writefln!"..::%s::..";
 ```
T
Okay, you're right. Now worked it: https://run.dlang.io/is/ja1n6C ```d auto toString() { return cast(string)bits; } ```
Feb 09 2022
prev sibling parent reply matheus <matheus gmail.com> writes:
On Tuesday, 8 February 2022 at 18:19:55 UTC, Salih Dincer wrote:
 Hope, D will go on to the next version,
It will end-up as a full circle, D started as better replacement for chaotic C++, it was even written in the latter and going neck to neck or even surpassing over the years, until it reached the point of "dog-fooding" and the compiler was rewritten in D, and now its direction is to be like D as a better C, it's incorporating stuffs like importC, and will eventually get rid of the GC, classes, templates... just to become a C's Doppelgänger. :) Matheus.
Feb 08 2022
parent reply forkit <forkit gmail.com> writes:
On Tuesday, 8 February 2022 at 23:30:44 UTC, matheus wrote:
 On Tuesday, 8 February 2022 at 18:19:55 UTC, Salih Dincer wrote:
 Hope, D will go on to the next version,
It will end-up as a full circle, D started as better replacement for chaotic C++, it was even written in the latter and going neck to neck or even surpassing over the years, until it reached the point of "dog-fooding" and the compiler was rewritten in D, and now its direction is to be like D as a better C, it's incorporating stuffs like importC, and will eventually get rid of the GC, classes, templates... just to become a C's Doppelgänger. :) Matheus.
There appears to be a fundamental law of physics, whereby the natural tendency of things is to approach a chaotic state. C++ already seems well on its way... With D, the real question is, just how long can we delay this decay ;-)
Feb 08 2022
parent forkit <forkit gmail.com> writes:
On Wednesday, 9 February 2022 at 00:03:23 UTC, forkit wrote:

do the maths:

-(entropy) = k log (1/D)
Feb 08 2022