Re: Is returning void functions inside void functions a feature or an artifact?

2021-08-03 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 3 August 2021 at 10:28:53 UTC, Rekel wrote: On Tuesday, 3 August 2021 at 00:53:43 UTC, user1234 wrote: You got the answer in another reply but here is a bit of more fun: ```d void main() { return cast(void) 1; } ``` What does casting to void do? Does it just ignore whatever

Re: Is returning void functions inside void functions a feature or an artifact?

2021-08-03 Thread Rekel via Digitalmars-d-learn
On Tuesday, 3 August 2021 at 00:53:43 UTC, user1234 wrote: You got the answer in another reply but here is a bit of more fun: ```d void main() { return cast(void) 1; } ``` What does casting to void do? Does it just ignore whatever follows it? On Tuesday, 3 August 2021 at 07:23:34 UTC,

Re: Is returning void functions inside void functions a feature or an artifact?

2021-08-03 Thread Patrick Schluter via Digitalmars-d-learn
On Monday, 2 August 2021 at 14:46:36 UTC, jfondren wrote: On Monday, 2 August 2021 at 14:31:45 UTC, Rekel wrote: [...] I don't know where you can find this in the docs, but what doesn't seem trivial about it? The type of the expression `print()` is void. That's the type that `doSomething`

Re: Is returning void functions inside void functions a feature or an artifact?

2021-08-02 Thread user1234 via Digitalmars-d-learn
On Monday, 2 August 2021 at 14:31:45 UTC, Rekel wrote: I recently found one can return function calls to void functions, though I don't remember any documentation mentioning this even though it doesn't seem trivial. [...] If this is intended, where could I find this in the docs? I haven't

Re: Is returning void functions inside void functions a feature or an artifact?

2021-08-02 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Aug 02, 2021 at 04:42:14PM +, Rekel via Digitalmars-d-learn wrote: [...] > Also slightly off topic, but when would one use an alias instead of a > function/delegate? I haven't used aliases before. When you want a compile-time binding that could potentially elide the indirect function

Re: Is returning void functions inside void functions a feature or an artifact?

2021-08-02 Thread Ali Çehreli via Digitalmars-d-learn
On 8/2/21 9:42 AM, Rekel wrote: > when would one use an alias instead of a > function/delegate? I haven't used aliases before. alias will match both functions and delegates... and... any symbol at all. So, if you don't have a reason to constain the user, callable template parameters are most

Re: Is returning void functions inside void functions a feature or an artifact?

2021-08-02 Thread Rekel via Digitalmars-d-learn
On Monday, 2 August 2021 at 14:51:07 UTC, H. S. Teoh wrote: This is intentional, in order to make it easier to write generic code without always having to special-case functions that don't return anything. Ooh that indeed seems useful. Thanks for the hint. Also slightly off topic, but when

Re: Is returning void functions inside void functions a feature or an artifact?

2021-08-02 Thread Rekel via Digitalmars-d-learn
On Monday, 2 August 2021 at 14:46:36 UTC, jfondren wrote: C, C++, Rust, and Zig are all fine with this. Nim doesn't like it. I had no clue, never seen it used in any case. I've always assumed one couldn't return void as it's not a value. I guess intuitions aren't always universal . Good to

Re: Is returning void functions inside void functions a feature or an artifact?

2021-08-02 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Aug 02, 2021 at 02:31:45PM +, Rekel via Digitalmars-d-learn wrote: > I recently found one can return function calls to void functions, > though I don't remember any documentation mentioning this even though > it doesn't seem trivial. This is intentional, in order to make it easier to

Re: Is returning void functions inside void functions a feature or an artifact?

2021-08-02 Thread jfondren via Digitalmars-d-learn
On Monday, 2 August 2021 at 14:31:45 UTC, Rekel wrote: I recently found one can return function calls to void functions, though I don't remember any documentation mentioning this even though it doesn't seem trivial. ```d void print(){ writeln("0"); } void doSomething(int a){