String lambdas

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Tue Apr 26 12:15:16 PDT 2016


On Tuesday, April 26, 2016 13:58:22 Andrei Alexandrescu via Digitalmars-d 
wrote:
> https://github.com/dlang/phobos/pull/3882
>
> I just closed with some regret a nice piece of engineering. Please
> comment if you think string lambdas have a lot of unexploited potential.

Well, they're nicer than the "new" lambda syntax for really short stuff like
"a == b" or "a != b", but beyond that, the newer syntax mostly does what the
string lambdas were trying to do. And if your lambda gets very long, it
really should be replaced with something like a nested function anyway.
Pretty much anything complicated shouldn't be a lambda, or it risks being
unmaintainable. So, while that PR was indeed a nice piece of engineering, it
seems to be solving a problem that really shouldn't be solved with lambdas
anyway.

> One thing we really need in order to 100% replace string lambdas with
> lambdas is function equivalence. Right now we're in the odd situation
> that SomeTemplate!((a, b) => a < b) has distinct types, one per
> instantiation.

Once that's solved, we can consider deprecating string lambdas, but
equivalence is indeed the one killer feature that non-string lambdas lack.
However, from what I recall of discussions on that, it sounded like it was
going to be pretty nasty to implement. :(

- Jonathan M Davis



More information about the Digitalmars-d mailing list