Thread overview
[Issue 809] Should be possible to convert lazy argument to delegate
May 16
RazvanN
May 16
RazvanN
Aug 02
Dlang Bot
Aug 02
Dlang Bot
Aug 26
Dlang Bot
May 16
https://issues.dlang.org/show_bug.cgi?id=809

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
                 CC|                            |razvan.nitu1305@gmail.com
         Resolution|---                         |WONTFIX

--- Comment #4 from RazvanN <razvan.nitu1305@gmail.com> ---
I don't think that dg should be viewed as a delegate even though the compiler actually creates one for the int. Logically you still have an int value which you are trying to assign to a delegate. Closing as WONTFIX.

--
May 16
https://issues.dlang.org/show_bug.cgi?id=809

Stewart Gordon <smjg@iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|WONTFIX                     |---

--- Comment #5 from Stewart Gordon <smjg@iname.com> ---
(In reply to RazvanN from comment #4)

I disagree.  If you have a lazy parameter, when you reference it in the function you are saying "evaluate it at this point".  Essentially, a lazy parameter is just syntactic sugar for a delegate, so it makes perfect sense to be able to access said delegate.  I certainly can't see any reason not to allow the programmer to do this.

(I realise you could effectively achieve this with a delegate literal:
int delegate() dg_ = { return dg; };
But can D compilers be relied on to optimise this to be the original delegate
rather than a wrapper?)

Furthermore, individuals shouldn't be marking bugs as WONTFIX just because they personally disagree with them.  Let's see what Walter says.

--
May 16
https://issues.dlang.org/show_bug.cgi?id=809

--- Comment #6 from RazvanN <razvan.nitu1305@gmail.com> ---
(In reply to Stewart Gordon from comment #5)
> (In reply to RazvanN from comment #4)
> 
> I disagree.  If you have a lazy parameter, when you reference it in the function you are saying "evaluate it at this point".  Essentially, a lazy parameter is just syntactic sugar for a delegate, so it makes perfect sense to be able to access said delegate.  I certainly can't see any reason not to allow the programmer to do this.
> 
> (I realise you could effectively achieve this with a delegate literal:
> int delegate() dg_ = { return dg; };
> But can D compilers be relied on to optimise this to be the original
> delegate rather than a wrapper?)
> 
You can do pragma(inline) int delegate() dg_ = { return dg; };

> Furthermore, individuals shouldn't be marking bugs as WONTFIX just because they personally disagree with them.  Let's see what Walter says.

I interpreted Walter's comment and replied as an extension to his first comment.

--
May 19
https://issues.dlang.org/show_bug.cgi?id=809

--- Comment #7 from Stewart Gordon <smjg@iname.com> ---
(In reply to RazvanN from comment #6)
> I interpreted Walter's comment and replied as an extension to his first comment.

As I interpret Walter's comment, it's talking about Li's original idea, that one should be able to use the bare name of the lazy parameter to mean the delegate.  Then I suggested defining &dg to mean the delegate.  Really, the essence of this issue is that it's suggesting definining a syntax to extract the delegate from a lazy function parameter - which could be a language-defined overload of the & (address-of) operator per comment 2, or it could be something else entirely.

--
June 04
https://issues.dlang.org/show_bug.cgi?id=809

Andrei Alexandrescu <andrei@erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei@erdani.com

--- Comment #8 from Andrei Alexandrescu <andrei@erdani.com> ---
On the face of it, a lazy parameter is a delegate so the request makes sense. On the other hand lazy T is meant to be "pretty much the same as T". This works today:

void test(lazy int dg){
    int delegate() dg_ = { return dg; };
}

I'm not sure how it interacts with attributes and qualifiers.

This could be made to work:

void test(lazy int dg){
    int delegate() dg_ = &dg;
}

Currently, oddly enough (and definitely a bug), this issues an unfit error
message:

void test(lazy int dg){
    auto x = &dg;
}

"Error: lazy variable dg cannot be modified" :o)

So it seems like taking the address of a lazy is "available" and could return the underlying delegate.

--
August 02
https://issues.dlang.org/show_bug.cgi?id=809

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #9 from Dlang Bot <dlang-bot@dlang.rocks> ---
@RazvanN7 created dlang/dmd pull request #10264 "Fix Issue 809 - Should be possible to convert lazy argument to delegate" fixing this issue:

- Fix Issue 809 - Should be possible to convert lazy argument to delegate

https://github.com/dlang/dmd/pull/10264

--
August 02
https://issues.dlang.org/show_bug.cgi?id=809

--- Comment #10 from Dlang Bot <dlang-bot@dlang.rocks> ---
@RazvanN7 created dlang/dlang.org pull request #2686 "Spec change for Issue 809" mentioning this issue:

- Spec change for Issue 809

  Merge after dmd PR: https://github.com/dlang/dmd/pull/10264

https://github.com/dlang/dlang.org/pull/2686

--
August 26
https://issues.dlang.org/show_bug.cgi?id=809

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #11 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #10264 "Fix Issue 809 - Should be possible to convert lazy argument to delegate" was merged into master:

- d105c1c648f7944e84422276d19c21a39917afb3 by RazvanN7:
  Fix Issue 809 - Should be possible to convert lazy argument to delegate

https://github.com/dlang/dmd/pull/10264

--