Future of string lambda functions/string predicate functions
Tyler Jameson Little
beatgammit at gmail.com
Sun Aug 11 11:30:00 PDT 2013
On Sunday, 11 August 2013 at 16:26:16 UTC, Andrei Alexandrescu
wrote:
> On 8/8/13 9:52 AM, Jonathan M Davis wrote:
>> On Thursday, August 08, 2013 07:29:56 H. S. Teoh wrote:
>>> Seems this thread has quietened down. So, what is the
>>> conclusion? Seems
>>> like almost everyone concedes that silent deprecation is the
>>> way to go.
>>> We still support string lambdas in the background, but in
>>> public docs we
>>> promote the use of the new lambda syntax. Would that be a fair
>>> assessment of this discussion?
>>
>> I find it interesting that very few Phobos devs have weighed
>> in on the matter,
>> but unfortunately, most of the posters who have weighed in do
>> seem to be
>> against keeping them.
>
> There's a related issue that I think we must solve before
> deciding whether or not we should deprecate string lambdas.
> Consider:
>
> void main() {
> import std.range;
> SortedRange!(int[], "a > b") a;
> SortedRange!(int[], "a > b") b;
> b = a;
> SortedRange!(int[], (a, b) => a > b) c;
> SortedRange!(int[], (a, b) => a > b) d;
> d = c;
> }
>
> The last line fails to compile because D does not currently
> have a good notion of comparing lambdas for equality. In
> contrast, string comparison is well defined, and although
> string lambdas have clowny issues with e.g. "a>b" being
> different from "a > b", people have a good understanding of
> what to do to get code working.
>
> So I think we should come up with a good definition of what
> comparing two function aliases means.
>
>
> Andrei
Correct me if I'm wrong, but AFAICT the old behavior was an
undocumented feature. I couldn't find string lambdas formally
documented anywhere, but lambdas are.
Comparing function aliases is an optimization, not a feature, so
I don't feel it's a blocker to deprecating string lambdas. If the
user needs the old behavior, he/she can do this today with an
actual function:
bool gt(int a, int b) {
return a > b;
}
void main() {
import std.range;
SortedRange!(int[], "a > b") a;
SortedRange!(int[], "a > b") b;
b = a;
SortedRange!(int[], gt) c;
SortedRange!(int[], gt) d;
d = c;
}
While not as concise, this is safer and does not rely on
undocumented behavior.
Another consideration, are the following equivalent?
(a,b) => a > b
(b,c) => b > c
More information about the Digitalmars-d
mailing list