String lambdas
Bauss via Digitalmars-d
digitalmars-d at puremagic.com
Sat Apr 30 09:02:02 PDT 2016
On Tuesday, 26 April 2016 at 17:58:22 UTC, Andrei Alexandrescu
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.
>
> 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.
>
>
> Andrei
An alternative to string lambads could be something like a
shortened version of lambdas like consider
"a > b" could be something like {%0 > %1} and then the body of
the expression is evaluated to see whether it's a valid D
expression where %1 and %2 would equal first and second arguments
in the expression and when used you could simply use do something
like
Compare(T,expression)(T x, T y) {
return expression(x,y); // the compiler has to figure out
that this should be evaluated as return x < y with the example
above.
This will ensure that the expression is a valid D expression and
cannot really hacked to do other stuff what it's meant to.
Of course this is just an idea on top of my head on how string
lambdas could be resolved.
More information about the Digitalmars-d
mailing list