Re: scope(exit) with expected library

2021-08-25 Thread WebFreak001 via Digitalmars-d-learn
On Wednesday, 25 August 2021 at 15:30:57 UTC, Steven Schveighoffer wrote: [...] Another approach is to let the compiler deal with the error handling and not muddy your return type. Swift does something similar, where it rewrites the throw/catch into a standard return and doesn't do actual thr

Re: scope(exit) with expected library

2021-08-25 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/25/21 10:58 AM, WebFreak001 wrote: Hm I'm not quite seeing how the error handler is related to an "Expected type interface" that the compiler could expect. This would be without compiler changes. Currently with exceptions the scope things are implemented using try-catch-finally, this

Re: scope(exit) with expected library

2021-08-25 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 25 August 2021 at 14:42:07 UTC, Steven Schveighoffer wrote: I think it's possible to work with some mechanics that aren't necessarily desirable. Something like: ```d ErrorHandler error = registerErrorHandler; error.onFailure({writeln("division failed");}); error.onSuccess({write

Re: scope(exit) with expected library

2021-08-25 Thread WebFreak001 via Digitalmars-d-learn
On Wednesday, 25 August 2021 at 14:52:34 UTC, Steven Schveighoffer wrote: On 8/25/21 10:42 AM, Steven Schveighoffer wrote: I think it's possible to work with some mechanics that aren't necessarily desirable. Something like: One has to weigh how much this is preferred to actual exception

Re: scope(exit) with expected library

2021-08-25 Thread WebFreak001 via Digitalmars-d-learn
On Wednesday, 25 August 2021 at 14:42:07 UTC, Steven Schveighoffer wrote: On 8/25/21 10:22 AM, Paul Backus wrote: On Wednesday, 25 August 2021 at 14:04:54 UTC, WebFreak001 wrote: [...] Probably the only principled way to make this work would be to define some kind of "concept"/structural int

Re: scope(exit) with expected library

2021-08-25 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/25/21 10:42 AM, Steven Schveighoffer wrote: I think it's possible to work with some mechanics that aren't necessarily desirable. Something like: One has to weigh how much this is preferred to actual exception handling... If something like DIP1008 could become usable, it might allevia

Re: scope(exit) with expected library

2021-08-25 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/25/21 10:22 AM, Paul Backus wrote: On Wednesday, 25 August 2021 at 14:04:54 UTC, WebFreak001 wrote: Would it be possible to extend `scope(exit)` and `scope(success)` to trigger properly for functions returning `Expected!T` as defined in the [expectations](https://code.dlang.org/packages/ex

Re: scope(exit) with expected library

2021-08-25 Thread WebFreak001 via Digitalmars-d-learn
On Wednesday, 25 August 2021 at 14:22:26 UTC, Paul Backus wrote: On Wednesday, 25 August 2021 at 14:04:54 UTC, WebFreak001 wrote: [...] Probably the only principled way to make this work would be to define some kind of "concept"/structural interface that's recognized by the compiler to mean

Re: scope(exit) with expected library

2021-08-25 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 25 August 2021 at 14:04:54 UTC, WebFreak001 wrote: Would it be possible to extend `scope(exit)` and `scope(success)` to trigger properly for functions returning `Expected!T` as defined in the [expectations](https://code.dlang.org/packages/expectations) and [expected](https://code

scope(exit) with expected library

2021-08-25 Thread WebFreak001 via Digitalmars-d-learn
Would it be possible to extend `scope(exit)` and `scope(success)` to trigger properly for functions returning `Expected!T` as defined in the [expectations](https://code.dlang.org/packages/expectations) and [expected](https://code.dlang.org/packages/expected) DUB libraries? For example is it