DIP19: Remove comma operator from D and provision better syntactic support for tuples
Michael
pr at m1xa.com
Sat Oct 6 08:47:36 PDT 2012
On Sunday, 23 September 2012 at 20:39:38 UTC, Andrei Alexandrescu
wrote:
> I discussed this with Walter, and we concluded that we could
> deprecate the comma operator if it helps tuples. So I started
> with this:
>
> http://www.prowiki.org/wiki4d/wiki.cgi?LanguageDevel/DIPs/DIP19
>
> Unfortunately, I started much cockier than I ended. The
> analysis in there fails to construct a case even half strong
> that deprecating the comma operator could significantly help
> tuples. Well it essentially concludes that tuples are mostly
> fine as they are, and attempts to embellish them syntactically
> are marred with unexpected problems. Nevertheless, I sure have
> missed aspects all over, so contributions are appreciated.
>
>
> Thanks,
>
> Andrei
With removed comma operator from D next code will work?
module maybe;
import std.stdio;
import std.algorithm;
R With(I, R)(I o, R function (I) fun)
{
return o is null ? null : fun(o);
}
R Return(I, R)(I o, R function (I) fun, R failureResult)
{
return o is null ? failureResult : fun(o);
}
I If(I)(I o, bool function (I) fun)
{
return o is null ? null : fun(o) ? o : null;
}
I Unless(I)(I o, bool function (I) fun)
{
return o is null ? null : fun(o) ? null : o;
}
I Do(I)(I o, void function (I) fun)
{
return o is null ? null : fun(o), o;
}
void doit(string value)
{
writeln("Loading... \n");
}
void main()
{
string name = "D";
name = name.With((string x) => "Hello, " ~ x ~ "!").
If((string x) => canFind(x, "D")).
Do((string x) => x.doit).
Return((string x) => x ~ " I love You!", "Oh, my!");
writeln(name);
}
especially template function
I Do(I)(I o, void function (I) fun)
{
return o is null ? null : fun(o), o;
}
More information about the Digitalmars-d
mailing list