Thread overview | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
December 27, 2011 A nice way to step into 2012 | ||||
---|---|---|---|---|
| ||||
https://github.com/D-Programming-Language/dmd/commit/675898721c04d0bf155a85abf986eae99c37c0dc Andrei |
December 27, 2011 Re: A nice way to step into 2012 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Tuesday, 27 December 2011 at 04:25:00 UTC, Andrei Alexandrescu wrote:
> https://github.com/D-Programming-Language/dmd/commit/675898721c04d0bf155a85abf986eae99c37c0dc
>
> Andrei
This change is cooooool!
Masahiro
|
December 27, 2011 Re: A nice way to step into 2012 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | "Andrei Alexandrescu" <SeeWebsiteForEmail@erdani.org> wrote in message news:jdbhas$2ftb$1@digitalmars.com... > https://github.com/D-Programming-Language/dmd/commit/675898721c04d0bf155a85abf986eae99c37c0dc > > Andrei Fanfuckingtastic! |
December 27, 2011 Re: A nice way to step into 2012 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Lambda very cooooool! I hope we can add shared lib support for linux & freebsd in 2012. On 27 December 2011 12:25, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote: > https://github.com/D-Programming-Language/dmd/commit/675898721c04d0bf155a85abf986eae99c37c0dc > > Andrei |
December 27, 2011 Re: A nice way to step into 2012 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Tuesday, 27 December 2011 at 04:25:00 UTC, Andrei Alexandrescu wrote:
> https://github.com/D-Programming-Language/dmd/commit/675898721c04d0bf155a85abf986eae99c37c0dc
>
> Andrei
Finally, it's here! I'll be able to use std.algorithm stuff without tons of named, nested functions now :)
|
December 27, 2011 Re: A nice way to step into 2012 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Andrei Alexandrescu:
> https://github.com/D-Programming-Language/dmd/commit/675898721c04d0bf155a85abf986eae99c37c0dc
Since some time thanks to a post in this newsgroups I am able to compile DMD, so I am able to test the changes early. It seems to work in various situations:
import std.stdio, std.range, std.algorithm;
int foo(alias callMe)(int a) {
return callMe(a);
}
int bar(alias callMe)() {
return callMe(1, 10, 100);
}
void main() {
auto r = foo!((x) => x ^^ 2)(4);
assert(r == 16);
r = foo!((x,) => x ^^ 2)(5);
assert(r == 25);
// r = foo!((x,,) => x ^^ 2)(5); // error, good
r = foo!(x=>x^^2)(6);
assert(r == 36);
r = bar!((x, y, z) => x + y + z)();
assert(r == 111);
double delegate(double)[] f;
f ~= (double x) => x ^^ 2;
assert(f[0](10) == 100);
// Syntax variety, fit for everyone:
auto pow4 = (int x) => x ^^ 4;
writeln(map!(function int(in int x) pure nothrow { return x ^^ 4; })(iota(10)));
writeln(map!(function int(int x){ return x ^^ 4; })(iota(10)));
writeln(map!(function(int x){ return x ^^ 4; })(iota(10)));
writeln(map!((int x){ return x ^^ 4; })(iota(10)));
writeln(map!((x){ return x ^^ 4; })(iota(10)));
writeln(map!((int x) => x ^^ 4)(iota(10)));
writeln(map!((x) => x ^^ 4)(iota(10)));
writeln(map!(x => x ^^ 4)(iota(10)));
writeln(map!q{ a ^^ 4 }(iota(10)));
writeln(map!"a^^4"(iota(10)));
writeln(map!pow4(iota(10)));
}
-----------------------
This program contains wrong syntax because x lacks a type:
void main() {
double delegate(double) f;
f = (x) => x + 1;
}
DMD gives the error messages:
test.d(3): Error: undefined identifier x, did you mean variable f?
test.d(3): Error: cannot implicitly convert expression (__dgliteral1) of type _error_ delegate(_error_) to double delegate(double)
Is it wise to try to improve the second error message?
Bye,
bearophile
|
December 27, 2011 Re: A nice way to step into 2012 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Le 27/12/2011 05:25, Andrei Alexandrescu a écrit :
> https://github.com/D-Programming-Language/dmd/commit/675898721c04d0bf155a85abf986eae99c37c0dc
>
>
> Andrei
Maybe I'll seem bitter, but I do not think this changement was really that important. This is nice, ok, but we have some other really serious flaw, like shared not doing what it is supposed to do.
|
December 27, 2011 Re: A nice way to step into 2012 | ||||
---|---|---|---|---|
| ||||
Posted in reply to deadalnix | On 27/12/11 10:51 AM, deadalnix wrote:
> Le 27/12/2011 05:25, Andrei Alexandrescu a écrit :
>> https://github.com/D-Programming-Language/dmd/commit/675898721c04d0bf155a85abf986eae99c37c0dc
>>
>>
>>
>> Andrei
>
> Maybe I'll seem bitter, but I do not think this changement was really
> that important. This is nice, ok, but we have some other really serious
> flaw, like shared not doing what it is supposed to do.
You seem bitter :-)
Seriously though, it's a fair point, but the syntax of lambdas is fairly important and this appears to be a simple change so the cost/benefit ratio is particularly high in this case.
|
December 27, 2011 Re: A nice way to step into 2012 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Peter Alexander | On Tuesday, 27 December 2011 at 10:57:35 UTC, Peter Alexander wrote:
> On 27/12/11 10:51 AM, deadalnix wrote:
>> Le 27/12/2011 05:25, Andrei Alexandrescu a écrit :
>>> https://github.com/D-Programming-Language/dmd/commit/675898721c04d0bf155a85abf986eae99c37c0dc
>>>
>>>
>>>
>>> Andrei
>>
>> Maybe I'll seem bitter, but I do not think this changement was really
>> that important. This is nice, ok, but we have some other really serious
>> flaw, like shared not doing what it is supposed to do.
>
> You seem bitter :-)
>
> Seriously though, it's a fair point, but the syntax of lambdas is fairly important and this appears to be a simple change so the cost/benefit ratio is particularly high in this case.
This. You can let people play around with it, test it and provide feedback with just a small patch.
And it is indeed very important. It's one of the few syntax woes we have to deal with in D, it would be a shame to let the benefits of std.algorithm and any other functional D code be overshadowed by the powerful but often excessive syntax of anonymous functions.
It's important when presenting D to initiates that high-level code looks nice.
|
December 27, 2011 Re: A nice way to step into 2012 | ||||
---|---|---|---|---|
| ||||
Posted in reply to deadalnix | On 27-12-2011 11:51, deadalnix wrote:
> Le 27/12/2011 05:25, Andrei Alexandrescu a écrit :
>> https://github.com/D-Programming-Language/dmd/commit/675898721c04d0bf155a85abf986eae99c37c0dc
>>
>>
>>
>> Andrei
>
> Maybe I'll seem bitter, but I do not think this changement was really
> that important. This is nice, ok, but we have some other really serious
> flaw, like shared not doing what it is supposed to do.
I don't quite agree. Short lambda syntax is *extremely important* for lambdas to actually be useful. If lambda syntax is not short and concise, it's not worth using over, say, a plain foreach loop.
I greatly welcome this change.
- Alex
|
Copyright © 1999-2021 by the D Language Foundation