On 2017-02-16 01:40, John Colvin wrote:
Slightly OT, but it is related so bear with me:
Design by introspection is great and prevent having to make new names
for every possible combo of features. Unfortunately, it doesn't work so
well for introspecting multiple types at once: normally you have to then
make a new symbol, with a new name, to pass to e.g. allSatisfy. That
annoys me, so I've been wanting this sort of thing for a while (which
would also make `every` way better to use, instead of having to make a
name for every predicate:
You know how we have named parameterised enums and aliases?
enum isInt(a) = is(a == int);
and
alias sizeof(a) = a.sizeof;
why not allow *anonymous* parameterised enums and aliases, like this:
enum areAllInt(TL ...) = allSatisfy!(enum(a) => is(a == int), TL);
void foo(TL...)(TL args)
if (allSatisfy!(enum(T) => T.sizeof <= 4, TL))
{
// ...
}
I've been thinking something similar. But this is the way I see it:
A lambda is an anonymous template function which is not yet
instantiated. But with the lambda syntax only one the different template
parameters are allowed. Why not generalize the lambda syntax to allow
different kind of template parameters. Example:
What we have today:
[1, 2, 3].map!(e => e * 2);
Is basically the same as:
T __anonymous(T)(T e)
{
return e * 2;
}
[1, 2, 3].map!(__anonymous!(int));
But today we cannot represent the following template with a lambda:
size_t sizeof(alias a)()
{
return a.sizeof;
}
So why not allow this lambda syntax:
alias sizeof = (alias a) => a.sizeof;
It would be nice if we could reuse the existing syntax for regular
template parameters as well:
alias isInt = t => is(t == int);
auto b = isInt!(int);
If the above is not possible, we could add an additional parameter list
to lambdas:
alias isInt = (t)() => is(t == int);
--
/Jacob Carlborg