November 15, 2017 Re: Should aliasing a lambda expression be allowed? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrea Fontana | On 11/15/17 11:59 AM, Andrea Fontana wrote:
> On Wednesday, 15 November 2017 at 15:25:06 UTC, Steven Schveighoffer wrote:
>> alias foo = lambda1;
>> alias foo = lambda2;
>
> What?
Yep. Would never have tried that in a million years before seeing this thread :) But it does work. Tested with dmd 2.076.1 and 2.066. So it's been there a while.
-Steve
|
November 15, 2017 Re: Deprecate implicit `int` to `bool` conversion for integer literals | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Tuesday, 14 November 2017 at 13:17:22 UTC, Steven Schveighoffer wrote:
> The array handling is probably the only part that would be painful. but we could handle that the same way we deprecated octal numbers:
>
> bools!"01001101"; => [false, true, false, false, true, true, false, true];
Thanks for chiming in. `bool[] boolValues = cast(bool[])[0,1,0,1]` will still work fine under option 1. It's only *implicit* casting that's being proposed for deprecation.
Mike
|
November 16, 2017 Re: Deprecate implicit `int` to `bool` conversion for integer literals | ||||
---|---|---|---|---|
| ||||
Posted in reply to Michael V. Franklin | On 11/14/17 11:33 PM, Michael V. Franklin wrote:
> On Wednesday, 15 November 2017 at 04:24:58 UTC, Walter Bright wrote:
>> On 11/14/2017 5:20 AM, Nick Treleaven wrote:
>>> An very similar problem exists for int and char overloads:
>>>
>>> alias foo = (char c) => 1;
>>> alias foo = (int i) => 4;
>>>
>>> enum int e = 7;
>>> static assert(foo(e) == 4); // fails
>>
>> I cannot reproduce this error.
>
> Try it here: https://run.dlang.io/is/nfMGfG
> DMD-nightly
Cool, thanks. That seems to be an unrelated bug. Have you added it to bugzilla? Thanks! -- Andrei
|
November 16, 2017 Re: Deprecate implicit `int` to `bool` conversion for integer literals | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Thursday, 16 November 2017 at 07:24:44 UTC, Andrei Alexandrescu wrote: >> Try it here: https://run.dlang.io/is/nfMGfG >> DMD-nightly > > Cool, thanks. That seems to be an unrelated bug. Have you added it to bugzilla? Thanks! -- Andrei Bugzilla Issue is here: https://issues.dlang.org/show_bug.cgi?id=17983 Mike |
November 16, 2017 Re: Should aliasing a lambda expression be allowed? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Wednesday, 15 November 2017 at 19:29:29 UTC, Steven Schveighoffer wrote: > On 11/15/17 11:59 AM, Andrea Fontana wrote: >> On Wednesday, 15 November 2017 at 15:25:06 UTC, Steven Schveighoffer wrote: >>> alias foo = lambda1; >>> alias foo = lambda2; >> >> What? > > Yep. Would never have tried that in a million years before seeing this thread :) But it does work. Tested with dmd 2.076.1 and 2.066. So it's been there a while. > > -Steve I guess you guys haven't been keeping up with language changes :P https://dlang.org/changelog/2.070.0.html#alias-funclit And yes, you can use 'alias' to capture overload sets. See also: https://github.com/dlang/dmd/pull/1660/files https://github.com/dlang/dmd/pull/2125/files#diff-51d0a1ca6214e6a916212fcbf93d7e40 https://github.com/dlang/dmd/pull/2417/files https://github.com/dlang/dmd/pull/4826/files https://github.com/dlang/dmd/pull/5162/files https://github.com/dlang/dmd/pull/5202 https://github.com/dlang/phobos/pull/5818/files |
November 16, 2017 Re: Should aliasing a lambda expression be allowed? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Petar Kirov [ZombineDev] | On Thursday, 16 November 2017 at 13:05:51 UTC, Petar Kirov [ZombineDev] wrote:
> On Wednesday, 15 November 2017 at 19:29:29 UTC, Steven Schveighoffer wrote:
>> On 11/15/17 11:59 AM, Andrea Fontana wrote:
>>> On Wednesday, 15 November 2017 at 15:25:06 UTC, Steven Schveighoffer wrote:
>>>> alias foo = lambda1;
>>>> alias foo = lambda2;
>>>
>>> What?
>>
>> Yep. Would never have tried that in a million years before seeing this thread :) But it does work. Tested with dmd 2.076.1 and 2.066. So it's been there a while.
>>
>> -Steve
>
> I guess you guys haven't been keeping up with language changes :P
>
> https://dlang.org/changelog/2.070.0.html#alias-funclit
>
> And yes, you can use 'alias' to capture overload sets.
> See also:
>
> https://github.com/dlang/dmd/pull/1660/files
> https://github.com/dlang/dmd/pull/2125/files#diff-51d0a1ca6214e6a916212fcbf93d7e40
> https://github.com/dlang/dmd/pull/2417/files
> https://github.com/dlang/dmd/pull/4826/files
> https://github.com/dlang/dmd/pull/5162/files
> https://github.com/dlang/dmd/pull/5202
>
> https://github.com/dlang/phobos/pull/5818/files
Yes, as far as I understand this is just the normal way that you add a symbol to an existing overload set, except now it also interacts with the functionality of using an alias to create a named function literal. Kind of interesting because I don't think it was possible to do this before, e.g.:
int function(int) f1 = (int n) => n;
int function(int) f2 = (char c) => c;
Would obviously be rejected by the compiler. However, using the alias syntax we can create an overload set from function literals in addition to regular functions.
|
November 16, 2017 Re: Deprecate implicit `int` to `bool` conversion for integer literals | ||||
---|---|---|---|---|
| ||||
Posted in reply to Michael V. Franklin | On 11/16/2017 02:29 AM, Michael V. Franklin wrote:
> On Thursday, 16 November 2017 at 07:24:44 UTC, Andrei Alexandrescu wrote:
>
>>> Try it here: https://run.dlang.io/is/nfMGfG
>>> DMD-nightly
>>
>> Cool, thanks. That seems to be an unrelated bug. Have you added it to bugzilla? Thanks! -- Andrei
>
> Bugzilla Issue is here: https://issues.dlang.org/show_bug.cgi?id=17983
>
> Mike
Gracias! -- Andrei
|
November 16, 2017 Re: Should aliasing a lambda expression be allowed? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Meta | On Thursday, 16 November 2017 at 16:10:50 UTC, Meta wrote:
> int function(int) f1 = (int n) => n;
> int function(int) f2 = (char c) => c;
Should be int function(char)
|
November 18, 2017 Re: Deprecate implicit `int` to `bool` conversion for integer literals | ||||
---|---|---|---|---|
| ||||
Posted in reply to Michael V. Franklin | On 15.11.2017 00:14, Michael V. Franklin wrote: > On Tuesday, 14 November 2017 at 13:20:22 UTC, Nick Treleaven wrote: > >> An very similar problem exists for int and char overloads: >> >> alias foo = (char c) => 1; >> alias foo = (int i) => 4; >> >> enum int e = 7; >> static assert(foo(e) == 4); // fails > > Wait a minute! This doesn't appear to be a casting or overload problem. Can you really overload aliases in D? > ... Yes. auto foo(int x){ return x; } auto bar(double x){ return x+1; } alias qux=foo; alias qux=bar; void main(){ import std.stdio; writeln(qux(1)," ",qux(1.0)); // 1 2 } This is by design. The fact that the following does not work is just a (known) compiler bug: alias qux=(int x)=>x; alias qux=(double x)=>x+1; void main(){ import std.stdio; writeln(qux(1)," ",qux(1.0)); // error } https://issues.dlang.org/show_bug.cgi?id=16099 |
November 18, 2017 Re: Should aliasing a lambda expression be allowed? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On 15.11.2017 13:28, Steven Schveighoffer wrote:
>
> However, it would be good to prevent the second alias which effectively does nothing.
No. It should just overload properly.
|
Copyright © 1999-2021 by the D Language Foundation