Re: Unexpectedly nice case of auto return type

2019-12-06 Thread mipri via Digitalmars-d-learn
On Friday, 6 December 2019 at 23:25:30 UTC, Johannes Loher wrote: On Tuesday, 3 December 2019 at 10:06:22 UTC, Mike Parker wrote: On Tuesday, 3 December 2019 at 10:03:22 UTC, Basile B. wrote: That's interesting details of D developement. Since you reply to the first message I think you have

Re: Unexpectedly nice case of auto return type

2019-12-06 Thread Johannes Loher via Digitalmars-d-learn
On Tuesday, 3 December 2019 at 10:06:22 UTC, Mike Parker wrote: On Tuesday, 3 December 2019 at 10:03:22 UTC, Basile B. wrote: That's interesting details of D developement. Since you reply to the first message I think you have not followed but in the last reply I told that maybe we should be

Re: Unexpectedly nice case of auto return type

2019-12-06 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 4 December 2019 at 12:54:34 UTC, Basile B. wrote: On Wednesday, 4 December 2019 at 03:17:27 UTC, Adam D. Ruppe wrote: On Wednesday, 4 December 2019 at 01:28:00 UTC, H. S. Teoh wrote: typeof(return) is one of the lesser known cool things about D that make it so cool. Somebody

Re: Unexpectedly nice case of auto return type

2019-12-04 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 4 December 2019 at 03:17:27 UTC, Adam D. Ruppe wrote: On Wednesday, 4 December 2019 at 01:28:00 UTC, H. S. Teoh wrote: typeof(return) is one of the lesser known cool things about D that make it so cool. Somebody should write an article about it to raise awareness of it. :-D

Re: Unexpectedly nice case of auto return type

2019-12-04 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 3 December 2019 at 10:19:02 UTC, Jonathan M Davis wrote: On Tuesday, December 3, 2019 3:03:22 AM MST Basile B. via Digitalmars-d- learn wrote: On Tuesday, 3 December 2019 at 09:58:36 UTC, Jonathan M Davis wrote: > On Tuesday, December 3, 2019 12:12:18 AM MST Basile B. via > >

Re: Unexpectedly nice case of auto return type

2019-12-04 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 3 December 2019 at 23:44:59 UTC, mipri wrote: On Tuesday, 3 December 2019 at 10:13:30 UTC, mipri wrote: Speaking of nice stuff and aliases, suppose you want to return a nice tuple with named elements? Option 1: auto auto option1() { return tuple!(int, "apples", int,

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 4 December 2019 at 01:28:00 UTC, H. S. Teoh wrote: typeof(return) is one of the lesser known cool things about D that make it so cool. Somebody should write an article about it to raise awareness of it. :-D you know i probably will write about that next week. so be sure to

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Dec 04, 2019 at 01:01:04AM +, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Tuesday, 3 December 2019 at 23:44:59 UTC, mipri wrote: > > Option 4: typeof(return) > > typeof(return) is super cool for like option type things too! typeof(return) is one of the lesser known cool things

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 3 December 2019 at 23:44:59 UTC, mipri wrote: Option 4: typeof(return) typeof(return) is super cool for like option type things too!

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread mipri via Digitalmars-d-learn
On Tuesday, 3 December 2019 at 10:13:30 UTC, mipri wrote: Speaking of nice stuff and aliases, suppose you want to return a nice tuple with named elements? Option 1: auto auto option1() { return tuple!(int, "apples", int, "oranges")(1, 2); } Option 2: redundancy Tuple!(int,

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread Meta via Digitalmars-d-learn
On Tuesday, 3 December 2019 at 22:11:39 UTC, Meta wrote: On Tuesday, 3 December 2019 at 17:45:27 UTC, H. S. Teoh wrote: The thing is, `void` means "no return type" (or "no type" in some contexts), i.e., void == TBottom in that case. Not *quite* correct. void is not a bottom type; it's a unit

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread Meta via Digitalmars-d-learn
On Tuesday, 3 December 2019 at 17:45:27 UTC, H. S. Teoh wrote: The thing is, `void` means "no return type" (or "no type" in some contexts), i.e., void == TBottom in that case. Not *quite* correct. void is not a bottom type; it's a unit type, meaning that it's a type with only 1 value (as is

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 03, 2019 at 09:08:55PM +, Paul Backus via Digitalmars-d-learn wrote: > On Tuesday, 3 December 2019 at 17:45:27 UTC, H. S. Teoh wrote: > > The thing is, `void` means "no return type" (or "no type" in some > > contexts), i.e., void == TBottom in that case. > > This is incorrect.

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 3 December 2019 at 17:45:27 UTC, H. S. Teoh wrote: The thing is, `void` means "no return type" (or "no type" in some contexts), i.e., void == TBottom in that case. This is incorrect. `void` as a return type is a unit type; that is, a type with exactly one value. A function with a

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 03, 2019 at 03:19:02AM -0700, Jonathan M Davis via Digitalmars-d-learn wrote: > On Tuesday, December 3, 2019 3:03:22 AM MST Basile B. via Digitalmars-d- > learn wrote: [...] > > [...] maybe we should be able to name the type of null. I think this > > relates to TBottom too a bit. > >

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, December 3, 2019 3:23:20 AM MST Basile B. via Digitalmars-d- learn wrote: > On Tuesday, 3 December 2019 at 10:19:02 UTC, Jonathan M Davis > > wrote: > > On Tuesday, December 3, 2019 3:03:22 AM MST Basile B. via > > > > Digitalmars-d- learn wrote: > >> [...] > > > > There isn't much

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 3 December 2019 at 10:19:02 UTC, Jonathan M Davis wrote: On Tuesday, December 3, 2019 3:03:22 AM MST Basile B. via Digitalmars-d- learn wrote: [...] There isn't much point in giving the type of null an explicit name given that it doesn't come up very often, and typeof(null) is

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, December 3, 2019 3:03:22 AM MST Basile B. via Digitalmars-d- learn wrote: > On Tuesday, 3 December 2019 at 09:58:36 UTC, Jonathan M Davis > > wrote: > > On Tuesday, December 3, 2019 12:12:18 AM MST Basile B. via > > > > Digitalmars-d- learn wrote: > >> I wish something like this was

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread mipri via Digitalmars-d-learn
On Tuesday, 3 December 2019 at 10:02:47 UTC, Andrea Fontana wrote: On Tuesday, 3 December 2019 at 09:48:39 UTC, Basile B. wrote: You see what surprises me here is that we cannot express the special type that is `TypeNull` and that can only have one value (`null`) so instead we have to use

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 3 December 2019 at 10:06:22 UTC, Mike Parker wrote: On Tuesday, 3 December 2019 at 10:03:22 UTC, Basile B. wrote: That's interesting details of D developement. Since you reply to the first message I think you have not followed but in the last reply I told that maybe we should be

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 3 December 2019 at 10:03:22 UTC, Basile B. wrote: That's interesting details of D developement. Since you reply to the first message I think you have not followed but in the last reply I told that maybe we should be able to name the type of null. I think this relates to TBottom

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 3 December 2019 at 09:48:39 UTC, Basile B. wrote: You see what surprises me here is that we cannot express the special type that is `TypeNull` and that can only have one value (`null`) so instead we have to use `auto` or `typeof(null)`. You can still create an alias anyway :)

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 3 December 2019 at 09:58:36 UTC, Jonathan M Davis wrote: On Tuesday, December 3, 2019 12:12:18 AM MST Basile B. via Digitalmars-d- learn wrote: I wish something like this was possible, until I change the return type of `alwaysReturnNull` from `void*` to `auto`. --- class A {}

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, December 3, 2019 12:12:18 AM MST Basile B. via Digitalmars-d- learn wrote: > I wish something like this was possible, until I change the > return type of `alwaysReturnNull` from `void*` to `auto`. > > > --- > class A {} > class B {} > > auto alwaysReturnNull() // void*, don't compile >

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 3 December 2019 at 09:44:20 UTC, Basile B. wrote: On Tuesday, 3 December 2019 at 08:47:45 UTC, Andrea Fontana wrote: On Tuesday, 3 December 2019 at 07:24:31 UTC, Basile B. wrote: A testA() { return alwaysReturnNull(); // Tnull can be implictly converted to A

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 3 December 2019 at 08:47:45 UTC, Andrea Fontana wrote: On Tuesday, 3 December 2019 at 07:24:31 UTC, Basile B. wrote: A testA() { return alwaysReturnNull(); // Tnull can be implictly converted to A } still nice tho. Why not [1]? [1] typeof(null)

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 3 December 2019 at 07:24:31 UTC, Basile B. wrote: A testA() { return alwaysReturnNull(); // Tnull can be implictly converted to A } still nice tho. Why not [1]? [1] typeof(null) alwaysReturnNull() { ... } Andrea

Re: Unexpectedly nice case of auto return type

2019-12-02 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 3 December 2019 at 07:12:18 UTC, Basile B. wrote: I wish something like this was possible, until I change the return type of `alwaysReturnNull` from `void*` to `auto`. --- class A {} class B {} auto alwaysReturnNull() // void*, don't compile { writeln(); return null; } A

Unexpectedly nice case of auto return type

2019-12-02 Thread Basile B. via Digitalmars-d-learn
I wish something like this was possible, until I change the return type of `alwaysReturnNull` from `void*` to `auto`. --- class A {} class B {} auto alwaysReturnNull() // void*, don't compile { writeln(); return null; } A testA() { return alwaysReturnNull(); } B testB() {