November 25
On Tuesday, 24 November 2020 at 17:12:38 UTC, Paul Backus wrote:
> On Tuesday, 24 November 2020 at 09:47:33 UTC, FeepingCreature wrote:
>>
>> Could DIP1033 offer something like ...
>>
>> inout(T) get(DG : inout(T) delegate())(DG fallback) pure { ... }
>>
>> Where DG would carry callsite inference about nothrow and @safe ness of the converted expression?
>
> As I understand it, with DIP 1033, a call to your example `get` function like `myNullable.get(123)` will deduce `DG` to be `int` (as it currently would), but it will instantiate successfully instead of failing, because `int` will now have an implicit conversion to `inout(int) delegate`. At runtime, the argument will be evaluated eagerly unless you explicitly wrap it in a delegate (e.g., with `() =>`).

Ah crud, yeah.

Damn. It would be *really valuable* to have a way to actually combine lazy with @safe, pure, nothrow etc.
November 25
On Friday, 20 November 2020 at 07:29:21 UTC, Mike Parker wrote:
> This is the discussion thread for the Final Review of DIP 1033, "Implicit Conversion of Expressions to Delegates":
>
> https://github.com/dlang/DIPs/blob/8e56fc593ece5c74f18b8eb68c3f9dcedf2396a7/DIPs/DIP1033.md
>

I don't quite understand this paragraph on "null":

"null implicitly converts directly to any delegate, but is not of type T, so it will not be turned into a lambda. Again, this is what is expected and is consistent with existing code."

What if T is another nullable type?

class C {
}

void foo(C delegate() c) {
    C c2 = c(); // According to the DIP, segfaults immediately instead of initializing c2 to null
}

void main() {
    foo(null);
}

"null" implicitly converts to C and, therefore, should be converted to "delegate() typeof(null){ return null; }" if we want proper lazy semantics.

Next ›   Last »
1 2 3