Jump to page: 1 2
Thread overview
Regarding Issue 9423
Jan 30, 2013
bearophile
Jan 30, 2013
Namespace
Jan 30, 2013
Paulo Pinto
Jan 30, 2013
Jonathan M Davis
Jan 30, 2013
Namespace
Jan 30, 2013
Jonathan M Davis
Jan 30, 2013
Namespace
Jan 30, 2013
Jonathan M Davis
Jan 30, 2013
Maxim Fomin
Jan 30, 2013
Timon Gehr
Jan 30, 2013
Maxim Fomin
Jan 30, 2013
bearophile
January 30, 2013
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
January 30, 2013
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.
January 30, 2013
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.
January 30, 2013
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.
January 30, 2013
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
January 30, 2013
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?

January 30, 2013
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
January 30, 2013
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
January 30, 2013
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.
January 30, 2013
> 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.
« First   ‹ Prev
1 2