www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Regarding Issue 9423

reply "bearophile" <bearophileHUGS lycos.com> writes:
Currently you are allowed to write a lambda literal as in line 3, 
but you can't omit "ref" as in line 4:


void foo(int delegate(ref int[1]) spam) {}
void main() {
     foo((ref x) => 0); // line3, OK
     foo(x => 0); // line4, Error
}


Do you think "ref" annotation should be required at the call site?

This is the Bugzilla thread. Hara has already implemented the 
"ref" inference, but he's not sure if it's a good idea:

http://d.puremagic.com/issues/show_bug.cgi?id=9423

Bye,
bearophile
Jan 30 2013
next sibling parent "Namespace" <rswhite4 googlemail.com> writes:
On Wednesday, 30 January 2013 at 11:10:17 UTC, bearophile wrote:
 Currently you are allowed to write a lambda literal as in line 
 3, but you can't omit "ref" as in line 4:


 void foo(int delegate(ref int[1]) spam) {}
 void main() {
     foo((ref x) => 0); // line3, OK
     foo(x => 0); // line4, Error
 }


 Do you think "ref" annotation should be required at the call 
 site?

 This is the Bugzilla thread. Hara has already implemented the 
 "ref" inference, but he's not sure if it's a good idea:

 http://d.puremagic.com/issues/show_bug.cgi?id=9423

 Bye,
 bearophile

I like it. Would be a good time to require this for normal functions and methods also. As C# it does.
Jan 30 2013
prev sibling next sibling parent "Paulo Pinto" <pjmlp progtools.org> writes:
On Wednesday, 30 January 2013 at 11:17:30 UTC, Namespace wrote:
 On Wednesday, 30 January 2013 at 11:10:17 UTC, bearophile wrote:
 Currently you are allowed to write a lambda literal as in line 
 3, but you can't omit "ref" as in line 4:


 void foo(int delegate(ref int[1]) spam) {}
 void main() {
    foo((ref x) => 0); // line3, OK
    foo(x => 0); // line4, Error
 }


 Do you think "ref" annotation should be required at the call 
 site?

 This is the Bugzilla thread. Hara has already implemented the 
 "ref" inference, but he's not sure if it's a good idea:

 http://d.puremagic.com/issues/show_bug.cgi?id=9423

 Bye,
 bearophile

I like it. Would be a good time to require this for normal functions and methods also. As C# it does.

I prefer the Pascal family way where they are implicit, but lets have what the majority prefers.
Jan 30 2013
prev sibling next sibling parent "Maxim Fomin" <maxim maxim-fomin.ru> writes:
On Wednesday, 30 January 2013 at 11:10:17 UTC, bearophile wrote:
 Currently you are allowed to write a lambda literal as in line 
 3, but you can't omit "ref" as in line 4:


 void foo(int delegate(ref int[1]) spam) {}
 void main() {
     foo((ref x) => 0); // line3, OK
     foo(x => 0); // line4, Error
 }


 Do you think "ref" annotation should be required at the call 
 site?

Ref isn't at a call site, it is a function declaration and not passing lambda by ref.
 This is the Bugzilla thread. Hara has already implemented the 
 "ref" inference, but he's not sure if it's a good idea:

 http://d.puremagic.com/issues/show_bug.cgi?id=9423

 Bye,
 bearophile

int delegate(ref int[1] spam) and int delegate(int[1] spam) are different. True, the proposal makes code writing convenient, but it can lead to troubles when foo has overload with non-ref parameter delegate. This also may probably lead to problems when passed by delegate function modifies its argument but it is unexpected by user because function was not annotated with ref. Moreover, this is a special case in a language.
Jan 30 2013
prev sibling next sibling parent "Jonathan M Davis" <jmdavisProg gmx.com> writes:
On Wednesday, January 30, 2013 12:51:22 Paulo Pinto wrote:
 I prefer the Pascal family way where they are implicit, but lets
 have what the majority prefers.

We've had this discussion at length before. It should stay implicit. There's no real point in having it at the call site unless it's required, which would break a lot of code even if you accepted that it was a valuable change. We're not going to do it. But regardless, Bearophile's example doesn't involve having ref at the call site. It's requiring ref on the parameter of a lambda declaration. That's the declaration site, not the call site. - Jonathan M Davis
Jan 30 2013
prev sibling next sibling parent "Namespace" <rswhite4 googlemail.com> writes:
On Wednesday, 30 January 2013 at 17:26:13 UTC, Jonathan M Davis 
wrote:
 On Wednesday, January 30, 2013 12:51:22 Paulo Pinto wrote:
 I prefer the Pascal family way where they are implicit, but 
 lets
 have what the majority prefers.

We've had this discussion at length before. It should stay implicit.

Ehh, where is this discussion and will this change implemented in the near future?
Jan 30 2013
prev sibling next sibling parent Timon Gehr <timon.gehr gmx.ch> writes:
On 01/30/2013 12:10 PM, bearophile wrote:
 Currently you are allowed to write a lambda literal as in line 3, but
 you can't omit "ref" as in line 4:


 void foo(int delegate(ref int[1]) spam) {}
 void main() {
      foo((ref x) => 0); // line3, OK
      foo(x => 0); // line4, Error
 }


 Do you think "ref" annotation should be required at the call site?

 This is the Bugzilla thread. Hara has already implemented the "ref"
 inference, but he's not sure if it's a good idea:

 http://d.puremagic.com/issues/show_bug.cgi?id=9423

 Bye,
 bearophile

I think the current behaviour is ok, but I do not really care. BTW, the pull does not contain a test for the case void foo(int delegate(int) dg){ ... } // 1 void foo(int delegate(ref int) dg){ ... } // 2 void main(){ foo(x=>0); } // call 1
Jan 30 2013
prev sibling next sibling parent "Jonathan M Davis" <jmdavisProg gmx.com> writes:
On Wednesday, January 30, 2013 18:35:29 Namespace wrote:
 On Wednesday, 30 January 2013 at 17:26:13 UTC, Jonathan M Davis
 
 wrote:
 On Wednesday, January 30, 2013 12:51:22 Paulo Pinto wrote:
 I prefer the Pascal family way where they are implicit, but
 lets
 have what the majority prefers.

We've had this discussion at length before. It should stay implicit.

Ehh, where is this discussion

I don't remember when it was discussed before. It's happened at least a couple of times, and I'd have to go digging through the archives. But after those discussions, I believe that it was pretty clear that we're not going to start supporting ref at the call site.
 and will this change implemented in the near future?

What change? My point was that it's _not_ changing. Function parameters can be marked with ref, but the call site doesn't use ref, and it isn't going to start using ref. - Jonathan M Davis
Jan 30 2013
prev sibling next sibling parent "Maxim Fomin" <maxim maxim-fomin.ru> writes:
On Wednesday, 30 January 2013 at 11:10:17 UTC, bearophile wrote:
 Currently you are allowed to write a lambda literal as in line 
 3, but you can't omit "ref" as in line 4:


 void foo(int delegate(ref int[1]) spam) {}
 void main() {
     foo((ref x) => 0); // line3, OK
     foo(x => 0); // line4, Error
 }


 Do you think "ref" annotation should be required at the call 
 site?

 This is the Bugzilla thread. Hara has already implemented the 
 "ref" inference, but he's not sure if it's a good idea:

 http://d.puremagic.com/issues/show_bug.cgi?id=9423

 Bye,
 bearophile

By the way, recently problem with functions taking by ref and returning passed ref was discussed and was considered to be a safity hole. If your proposal is accepted, issue with ref and safe may be needed to be taken into account in application to your proposal.
Jan 30 2013
prev sibling next sibling parent "Namespace" <rswhite4 googlemail.com> writes:
 What change? My point was that it's _not_ changing. Function 
 parameters can be
 marked with ref, but the call site doesn't use ref, and it 
 isn't going to
 start using ref.

 - Jonathan M Davis

My fault. I thought that the optional call site ref/out whatever might be implemented in the future. The C# way makes more sense, so I thought many users here would see something like this also. Even if it would be optional.
Jan 30 2013
prev sibling next sibling parent "Jonathan M Davis" <jmdavisProg gmx.com> writes:
On Wednesday, January 30, 2013 21:51:19 Namespace wrote:
 What change? My point was that it's _not_ changing. Function
 parameters can be
 marked with ref, but the call site doesn't use ref, and it
 isn't going to
 start using ref.
 
 - Jonathan M Davis

My fault. I thought that the optional call site ref/out whatever might be implemented in the future. The C# way makes more sense, so I thought many users here would see something like this also. Even if it would be optional.

No, it's been argued before, and IMHO optional ref does more harm than having none. The real benefit is when it's required, but even if it were generally agreed that that were better, it wouldn't get changed at this point, since it would break too much code. I suspect that it would cause problems with generic code though, regardless. - Jonathan M Davis
Jan 30 2013
prev sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
Maxim Fomin:

 By the way, recently problem with functions taking by ref and 
 returning passed ref was discussed and was considered to be a 
  safity hole. If your proposal is accepted, issue with ref and 
  safe may be needed to be taken into account in application to 
 your proposal.

I see. I am willing to close down that request 9423, if you want, it's not important. Bye, bearophile
Jan 30 2013